mirror of https://github.com/M66B/FairEmail.git
You're being watched
This commit is contained in:
parent
12e577fc9a
commit
d303a859a8
|
@ -144,6 +144,14 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LifecycleObserver watcher = new LifecycleObserver() {
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||||
|
public void onDestroy() {
|
||||||
|
cancel(context);
|
||||||
|
owner.getLifecycle().removeObserver(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
future = getExecutor(context).submit(new Runnable() {
|
future = getExecutor(context).submit(new Runnable() {
|
||||||
private Object data;
|
private Object data;
|
||||||
private long elapsed;
|
private long elapsed;
|
||||||
|
@ -181,30 +189,34 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
if (state.equals(Lifecycle.State.DESTROYED)) {
|
if (state.equals(Lifecycle.State.DESTROYED)) {
|
||||||
// No delivery
|
// No delivery
|
||||||
cleanup(context);
|
cleanup(context);
|
||||||
} else if (state.isAtLeast(Lifecycle.State.RESUMED)) {
|
|
||||||
// Inline delivery
|
|
||||||
Log.i("Deliver task " + name + " state=" + state + " elapse=" + elapsed + " ms");
|
|
||||||
deliver();
|
|
||||||
cleanup(context);
|
|
||||||
} else {
|
} else {
|
||||||
Log.i("Deferring task " + name + " state=" + state);
|
owner.getLifecycle().removeObserver(watcher);
|
||||||
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
|
if (state.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||||
public void onAny() {
|
// Inline delivery
|
||||||
state = owner.getLifecycle().getCurrentState();
|
Log.i("Deliver task " + name + " state=" + state + " elapse=" + elapsed + " ms");
|
||||||
if (state.equals(Lifecycle.State.DESTROYED)) {
|
deliver();
|
||||||
Log.i("Destroyed task " + name);
|
cleanup(context);
|
||||||
owner.getLifecycle().removeObserver(this);
|
} else {
|
||||||
cleanup(context);
|
Log.i("Deferring task " + name + " state=" + state);
|
||||||
} else if (state.isAtLeast(Lifecycle.State.RESUMED)) {
|
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
||||||
Log.i("Deferred delivery task " + name);
|
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
|
||||||
owner.getLifecycle().removeObserver(this);
|
public void onAny() {
|
||||||
deliver();
|
state = owner.getLifecycle().getCurrentState();
|
||||||
cleanup(context);
|
if (state.equals(Lifecycle.State.DESTROYED)) {
|
||||||
} else
|
Log.i("Destroyed task " + name);
|
||||||
Log.i("Deferring task " + name + " state=" + state);
|
owner.getLifecycle().removeObserver(this);
|
||||||
}
|
cleanup(context);
|
||||||
});
|
} else if (state.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||||
|
Log.i("Deferred delivery task " + name);
|
||||||
|
owner.getLifecycle().removeObserver(this);
|
||||||
|
deliver();
|
||||||
|
cleanup(context);
|
||||||
|
} else
|
||||||
|
Log.i("Deferring task " + name + " state=" + state);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,6 +261,8 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
owner.getLifecycle().addObserver(watcher);
|
||||||
|
|
||||||
updateTaskCount(context);
|
updateTaskCount(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue