From 9878853d209a4493bf5d0e5987ec1f40147b3593 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 25 Jul 2020 21:28:26 +0200 Subject: [PATCH] Dismiss undo on opening thread --- .../java/eu/faircode/email/ActivityView.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index a063a7bfaa..c3737e5c1a 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -115,6 +115,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB private boolean exit = false; private boolean searching = false; + private Snackbar lastSnackbar = null; static final int REQUEST_UNIFIED = 1; static final int REQUEST_WHY = 2; @@ -735,12 +736,14 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB final Snackbar snackbar = Snackbar.make(content, title, Snackbar.LENGTH_INDEFINITE) .setGestureInsetBottomIgnored(true); + lastSnackbar = snackbar; + snackbar.setAction(R.string.title_undo, new View.OnClickListener() { @Override public void onClick(View v) { - snackbar.dismiss(); + Log.i("Undo cancel"); snackbar.getView().setTag(true); - show.execute(ActivityView.this, args, "undo:show"); + snackbar.dismiss(); } }); @@ -757,6 +760,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB @Override public void onDismissed(Snackbar transientBottomBar, int event) { + if (snackbar.getView().getTag() == null) + move.execute(ActivityView.this, args, "undo:move"); + else + show.execute(ActivityView.this, args, "undo:show"); + ViewGroup.MarginLayoutParams lparam = (ViewGroup.MarginLayoutParams) content.getLayoutParams(); lparam.bottomMargin = margin; content.setLayoutParams(lparam); @@ -768,16 +776,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB new Handler().postDelayed(new Runnable() { @Override public void run() { - Log.i("Move timeout"); - - if (snackbar.getView().getTag() != null) - return; - - // Remove snackbar + Log.i("Undo timeout"); if (snackbar.isShown()) snackbar.dismiss(); - - move.execute(ActivityView.this, args, "undo:move"); } }, undo_timeout); } @@ -1298,6 +1299,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB private void onViewThread(Intent intent) { boolean found = intent.getBooleanExtra("found", false); + if (lastSnackbar != null && lastSnackbar.isShown()) + lastSnackbar.dismiss(); + if (!found && getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) getSupportFragmentManager().popBackStack("thread", FragmentManager.POP_BACK_STACK_INCLUSIVE);