From afa83fb6b406caeacc3b78987dc4d30f11c01c71 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 15 Jul 2021 17:37:40 +0200 Subject: [PATCH] Android 12: remind doze mode --- .../eu/faircode/email/FragmentMessages.java | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 247ada1b75..ce7cc54586 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -4026,10 +4026,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. grpOutbox.setVisibility(count == 0 ? View.GONE : View.VISIBLE); } }); - - if (!checkReporting()) - if (!checkReview()) - checkFingerprint(); } @Override @@ -4060,6 +4056,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. // Restart spinner swipeRefresh.resetRefreshing(); + if (!checkDoze()) + if (!checkReporting()) + if (!checkReview()) + checkFingerprint(); + prefs.registerOnSharedPreferenceChangeListener(this); onSharedPreferenceChanged(prefs, "pro"); @@ -4143,6 +4144,31 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } }; + private boolean checkDoze() { + if (viewType != AdapterMessage.ViewType.UNIFIED) + return false; + + if (!Helper.isDozeRequired()) + return false; + + final Context context = getContext(); + Boolean isIgnoring = Helper.isIgnoringOptimizations(context); + if (isIgnoring == null || isIgnoring) + return false; + + final Snackbar snackbar = Snackbar.make(view, R.string.title_setup_doze, Snackbar.LENGTH_INDEFINITE) + .setGestureInsetBottomIgnored(true); + snackbar.setAction(R.string.title_fix, new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(new Intent(context, ActivitySetup.class)); + } + }); + snackbar.show(); + + return true; + } + private boolean checkReporting() { if (viewType != AdapterMessage.ViewType.UNIFIED) return false;