mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-28 08:32:16 +01:00
More granular transient states
This commit is contained in:
@@ -117,6 +117,12 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||
this.args = null;
|
||||
this.stored = null;
|
||||
|
||||
try {
|
||||
onInit(args);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
||||
}
|
||||
|
||||
owner.getLifecycle().addObserver(this);
|
||||
|
||||
final Handler handler = new Handler();
|
||||
@@ -160,11 +166,19 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||
} catch (Throwable ex) {
|
||||
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
||||
} finally {
|
||||
try {
|
||||
onCleanup(args);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
||||
}
|
||||
onDestroyed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void onInit(Bundle args) {
|
||||
}
|
||||
|
||||
protected abstract T onLoad(Context context, Bundle args) throws Throwable;
|
||||
|
||||
protected void onLoaded(Bundle args, T data) {
|
||||
@@ -172,6 +186,9 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||
|
||||
protected abstract void onException(Bundle args, Throwable ex);
|
||||
|
||||
protected void onCleanup(Bundle args) {
|
||||
}
|
||||
|
||||
private static class Result {
|
||||
Throwable ex;
|
||||
Object data;
|
||||
|
||||
Reference in New Issue
Block a user