mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-30 21:58:52 +02:00
Added SimpleTask.isAlive
This commit is contained in:
@@ -49,10 +49,10 @@ import java.util.concurrent.Future;
|
||||
public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||
private boolean log = true;
|
||||
private boolean count = true;
|
||||
private boolean optional = false;
|
||||
|
||||
private String name;
|
||||
private long started;
|
||||
private boolean destroyed;
|
||||
private boolean reported;
|
||||
private Lifecycle.State state;
|
||||
private Future<?> future;
|
||||
@@ -79,11 +79,6 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleTask<T> setOptional(boolean optional) {
|
||||
this.optional = optional;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleTask<T> setExecutor(ExecutorService executor) {
|
||||
this.localExecutor = executor;
|
||||
return this;
|
||||
@@ -153,8 +148,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||
LifecycleObserver watcher = new LifecycleObserver() {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
public void onDestroy() {
|
||||
EntityLog.log(context, EntityLog.Type.Debug, "Cancelling task=" + name);
|
||||
cancel(context);
|
||||
destroyed = true;
|
||||
owner.getLifecycle().removeObserver(this);
|
||||
}
|
||||
};
|
||||
@@ -197,8 +191,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||
// No delivery
|
||||
cleanup(context);
|
||||
} else {
|
||||
if (optional)
|
||||
owner.getLifecycle().removeObserver(watcher);
|
||||
owner.getLifecycle().removeObserver(watcher);
|
||||
|
||||
if (state.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
// Inline delivery
|
||||
@@ -269,12 +262,15 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||
}
|
||||
});
|
||||
|
||||
if (optional)
|
||||
owner.getLifecycle().addObserver(watcher);
|
||||
owner.getLifecycle().addObserver(watcher);
|
||||
|
||||
updateTaskCount(context);
|
||||
}
|
||||
|
||||
public boolean isAlive() {
|
||||
return !this.destroyed;
|
||||
}
|
||||
|
||||
void cancel(Context context) {
|
||||
if (future != null && future.cancel(false)) {
|
||||
Log.i("Cancelled task=" + name);
|
||||
|
||||
Reference in New Issue
Block a user