From 099239ca646aaa1bc180409e5d598bea8797f57c Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 21 Dec 2018 08:49:31 +0100 Subject: [PATCH] More granular transient states --- .../eu/faircode/email/AdapterMessage.java | 40 ++++++++++++------- .../java/eu/faircode/email/SimpleTask.java | 17 ++++++++ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 4c9efed4cd..d9894087c6 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -309,20 +309,6 @@ public class AdapterMessage extends RecyclerView.Adapter>() { + @Override + protected void onInit(Bundle args) { + bnvActions.setHasTransientState(true); + } + + @Override + protected void onCleanup(Bundle args) { + bnvActions.setHasTransientState(false); + } + @Override protected List onLoad(Context context, Bundle args) { long account = args.getLong("account"); @@ -745,6 +741,22 @@ public class AdapterMessage extends RecyclerView.Adapter bodyTask = new SimpleTask() { private String body = null; + @Override + protected void onInit(Bundle args) { + btnHtml.setHasTransientState(true); + btnImages.setHasTransientState(true); + tvBody.setHasTransientState(true); + pbBody.setHasTransientState(true); + } + + @Override + protected void onCleanup(Bundle args) { + btnHtml.setHasTransientState(false); + btnImages.setHasTransientState(false); + tvBody.setHasTransientState(false); + pbBody.setHasTransientState(false); + } + @Override protected Spanned onLoad(final Context context, final Bundle args) { TupleMessageEx message = (TupleMessageEx) args.getSerializable("message"); diff --git a/app/src/main/java/eu/faircode/email/SimpleTask.java b/app/src/main/java/eu/faircode/email/SimpleTask.java index 9c599861d8..4af3fa985e 100644 --- a/app/src/main/java/eu/faircode/email/SimpleTask.java +++ b/app/src/main/java/eu/faircode/email/SimpleTask.java @@ -117,6 +117,12 @@ public abstract class SimpleTask 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 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 implements LifecycleObserver { protected abstract void onException(Bundle args, Throwable ex); + protected void onCleanup(Bundle args) { + } + private static class Result { Throwable ex; Object data;