Restore on launch by default

master
M66B 4 months ago
parent 71362110c2
commit 1c9b4df261

@ -43,8 +43,6 @@ import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
public class ActivityMain extends ActivityBase implements FragmentManager.OnBackStackChangedListener, SharedPreferences.OnSharedPreferenceChangeListener { 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 SPLASH_DELAY = 1500L; // milliseconds
private static final long SERVICE_START_DELAY = 5 * 1000L; // milliseconds private static final long SERVICE_START_DELAY = 5 * 1000L; // milliseconds
private static final long IGNORE_STORAGE_SPACE = 24 * 60 * 60 * 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 // VX-N3
// https://developer.android.com/docs/quality-guidelines/core-app-quality // https://developer.android.com/docs/quality-guidelines/core-app-quality
long now = new Date().getTime(); boolean restore_on_launch = prefs.getBoolean("restore_on_launch", true);
long last = prefs.getLong("last_launched", 0L); if (!restore_on_launch)
boolean restore_on_launch = prefs.getBoolean("restore_on_launch", false);
if (!restore_on_launch || now - last > RESTORE_STATE_INTERVAL * 60 * 1000L)
view.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); view.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
else { else {
String last_activity = prefs.getString("last_activity", null); 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"); Intent saved = args.getParcelable("intent");
if (saved == null) { if (saved == null) {
prefs.edit().putLong("last_launched", now).apply();
startActivity(view, options); startActivity(view, options);
if (sync_on_launch) if (sync_on_launch)
ServiceUI.sync(ActivityMain.this, null); ServiceUI.sync(ActivityMain.this, null);

@ -1102,6 +1102,11 @@ public class ApplicationEx extends Application
editor.remove("color_stripe_wide"); 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) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !BuildConfig.DEBUG)
editor.remove("background_service"); editor.remove("background_service");

@ -59,7 +59,6 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
private View view; private View view;
private ImageButton ibHelp; private ImageButton ibHelp;
private SwitchCompat swRestoreOnLaunch; private SwitchCompat swRestoreOnLaunch;
private TextView tvRestoreOnLaunchHint;
private SwitchCompat swSyncOnlaunch; private SwitchCompat swSyncOnlaunch;
private SwitchCompat swDoubleBack; private SwitchCompat swDoubleBack;
private SwitchCompat swConversationActions; private SwitchCompat swConversationActions;
@ -147,7 +146,6 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
ibHelp = view.findViewById(R.id.ibHelp); ibHelp = view.findViewById(R.id.ibHelp);
swRestoreOnLaunch = view.findViewById(R.id.swRestoreOnLaunch); swRestoreOnLaunch = view.findViewById(R.id.swRestoreOnLaunch);
tvRestoreOnLaunchHint = view.findViewById(R.id.tvRestoreOnLaunchHint);
swSyncOnlaunch = view.findViewById(R.id.swSyncOnlaunch); swSyncOnlaunch = view.findViewById(R.id.swSyncOnlaunch);
swDoubleBack = view.findViewById(R.id.swDoubleBack); swDoubleBack = view.findViewById(R.id.swDoubleBack);
swConversationActions = view.findViewById(R.id.swConversationActions); 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() { swRestoreOnLaunch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -729,7 +726,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); 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)); swSyncOnlaunch.setChecked(prefs.getBoolean("sync_on_launch", false));
swDoubleBack.setChecked(prefs.getBoolean("double_back", false)); swDoubleBack.setChecked(prefs.getBoolean("double_back", false));
swConversationActions.setChecked(prefs.getBoolean("conversation_actions", Helper.isGoogle())); swConversationActions.setChecked(prefs.getBoolean("conversation_actions", Helper.isGoogle()));

@ -1149,7 +1149,7 @@
Android may ask for permission to access the selected folder, even though the app doesn\'t need it. 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). You can cancel the selection dialog to restore the default folder (usually the \'Download\' folder).
</string> </string>
<string name="title_advanced_restore_on_launch_hint">Restore last app state when restarted via the launcher icon within %1$d minutes</string> <string name="title_advanced_restore_on_launch_hint">Restore last app state if possible when restarted via the launcher icon</string>
<string name="title_advanced_autoexpand_hint">Automatically open message when there is just one message or just one unread message in a conversation</string> <string name="title_advanced_autoexpand_hint">Automatically open message when there is just one message or just one unread message in a conversation</string>
<string name="title_advanced_expandall_hint">The answer button will not be shown when multiple messages are expanded because it is unclear which message the button applies to</string> <string name="title_advanced_expandall_hint">The answer button will not be shown when multiple messages are expanded because it is unclear which message the button applies to</string>
<string name="title_advanced_autoseen_hint">Automatically marking messages as read on expanding can be disabled in the advanced account settings of each account</string> <string name="title_advanced_autoseen_hint">Automatically marking messages as read on expanding can be disabled in the advanced account settings of each account</string>

Loading…
Cancel
Save