From 1c9b4df2610230b939438d4eaffba230c114a6ef Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 19 May 2025 22:02:46 +0200 Subject: [PATCH] Restore on launch by default --- app/src/main/java/eu/faircode/email/ActivityMain.java | 9 ++------- app/src/main/java/eu/faircode/email/ApplicationEx.java | 5 +++++ .../java/eu/faircode/email/FragmentOptionsBehavior.java | 5 +---- app/src/main/res/values/strings.xml | 2 +- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityMain.java b/app/src/main/java/eu/faircode/email/ActivityMain.java index d36bb9e56c..ae295cad08 100644 --- a/app/src/main/java/eu/faircode/email/ActivityMain.java +++ b/app/src/main/java/eu/faircode/email/ActivityMain.java @@ -43,8 +43,6 @@ import java.util.List; import java.util.concurrent.ExecutorService; public class ActivityMain extends ActivityBase implements FragmentManager.OnBackStackChangedListener, SharedPreferences.OnSharedPreferenceChangeListener { - static final int RESTORE_STATE_INTERVAL = 3; // minutes - private static final long SPLASH_DELAY = 1500L; // milliseconds private static final long SERVICE_START_DELAY = 5 * 1000L; // milliseconds private static final long IGNORE_STORAGE_SPACE = 24 * 60 * 60 * 1000L; // milliseconds @@ -271,10 +269,8 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack // VX-N3 // https://developer.android.com/docs/quality-guidelines/core-app-quality - long now = new Date().getTime(); - long last = prefs.getLong("last_launched", 0L); - boolean restore_on_launch = prefs.getBoolean("restore_on_launch", false); - if (!restore_on_launch || now - last > RESTORE_STATE_INTERVAL * 60 * 1000L) + boolean restore_on_launch = prefs.getBoolean("restore_on_launch", true); + if (!restore_on_launch) view.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); else { String last_activity = prefs.getString("last_activity", null); @@ -288,7 +284,6 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack Intent saved = args.getParcelable("intent"); if (saved == null) { - prefs.edit().putLong("last_launched", now).apply(); startActivity(view, options); if (sync_on_launch) ServiceUI.sync(ActivityMain.this, null); diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java index 4bb00e4f12..52e8db5ba4 100644 --- a/app/src/main/java/eu/faircode/email/ApplicationEx.java +++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java @@ -1102,6 +1102,11 @@ public class ApplicationEx extends Application editor.remove("color_stripe_wide"); } + if (version < 2277) { + if (!prefs.contains("restore_on_launch")) + editor.putBoolean("restore_on_launch", false); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !BuildConfig.DEBUG) editor.remove("background_service"); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java index e3e919fa75..24a215e2fc 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java @@ -59,7 +59,6 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe private View view; private ImageButton ibHelp; private SwitchCompat swRestoreOnLaunch; - private TextView tvRestoreOnLaunchHint; private SwitchCompat swSyncOnlaunch; private SwitchCompat swDoubleBack; private SwitchCompat swConversationActions; @@ -147,7 +146,6 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe ibHelp = view.findViewById(R.id.ibHelp); swRestoreOnLaunch = view.findViewById(R.id.swRestoreOnLaunch); - tvRestoreOnLaunchHint = view.findViewById(R.id.tvRestoreOnLaunchHint); swSyncOnlaunch = view.findViewById(R.id.swSyncOnlaunch); swDoubleBack = view.findViewById(R.id.swDoubleBack); swConversationActions = view.findViewById(R.id.swConversationActions); @@ -224,7 +222,6 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe } }); - tvRestoreOnLaunchHint.setText(getString(R.string.title_advanced_restore_on_launch_hint, ActivityMain.RESTORE_STATE_INTERVAL)); swRestoreOnLaunch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -729,7 +726,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - swRestoreOnLaunch.setChecked(prefs.getBoolean("restore_on_launch", false)); + swRestoreOnLaunch.setChecked(prefs.getBoolean("restore_on_launch", true)); swSyncOnlaunch.setChecked(prefs.getBoolean("sync_on_launch", false)); swDoubleBack.setChecked(prefs.getBoolean("double_back", false)); swConversationActions.setChecked(prefs.getBoolean("conversation_actions", Helper.isGoogle())); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e14f262d91..a60d1c8b2b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1149,7 +1149,7 @@ Android may ask for permission to access the selected folder, even though the app doesn\'t need it. You can cancel the selection dialog to restore the default folder (usually the \'Download\' folder). - Restore last app state when restarted via the launcher icon within %1$d minutes + Restore last app state if possible when restarted via the launcher icon Automatically open message when there is just one message or just one unread message in a conversation The answer button will not be shown when multiple messages are expanded because it is unclear which message the button applies to Automatically marking messages as read on expanding can be disabled in the advanced account settings of each account