mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-09 18:43:23 +02:00
Added option to restore app state on start
This commit is contained in:
@@ -282,6 +282,8 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
||||
super.onPause();
|
||||
|
||||
visible = false;
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
prefs.edit().putString("last_activity", this.getClass().getName()).apply();
|
||||
|
||||
checkAuthentication(false);
|
||||
}
|
||||
|
||||
@@ -42,8 +42,9 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
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 RESTORE_STATE_INTERVAL = 3 * 60 * 1000L; // milliseconds
|
||||
private static final long SERVICE_START_DELAY = 5 * 1000L; // milliseconds
|
||||
|
||||
@Override
|
||||
@@ -205,9 +206,18 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
|
||||
// https://developer.android.com/docs/quality-guidelines/core-app-quality
|
||||
long now = new Date().getTime();
|
||||
long last = prefs.getLong("last_launched", 0L);
|
||||
if (!BuildConfig.PLAY_STORE_RELEASE &&
|
||||
now - last > RESTORE_STATE_INTERVAL)
|
||||
boolean restore_on_launch = prefs.getBoolean("restore_on_launch", true);
|
||||
if (!restore_on_launch || now - last > RESTORE_STATE_INTERVAL * 60 * 1000L)
|
||||
view.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
else {
|
||||
String last_activity = prefs.getString("last_activity", null);
|
||||
long composing = prefs.getLong("last_composing", -1L);
|
||||
if (ActivityCompose.class.getName().equals(last_activity) && composing >= 0)
|
||||
view = new Intent(ActivityMain.this, ActivityCompose.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra("action", "edit")
|
||||
.putExtra("id", composing);
|
||||
}
|
||||
|
||||
Intent saved = args.getParcelable("intent");
|
||||
if (saved == null) {
|
||||
|
||||
@@ -1664,6 +1664,9 @@ public class FragmentCompose extends FragmentBase {
|
||||
onAction(R.id.action_save, extras, "pause");
|
||||
}
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefs.edit().putLong("last_composing", working).apply();
|
||||
|
||||
ConnectivityManager cm = Helper.getSystemService(context, ConnectivityManager.class);
|
||||
cm.unregisterNetworkCallback(networkCallback);
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ import java.util.List;
|
||||
|
||||
public class FragmentOptionsBehavior extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private ImageButton ibHelp;
|
||||
private SwitchCompat swRestoreOnLaunch;
|
||||
private TextView tvRestoreOnLaunchHint;
|
||||
private SwitchCompat swSyncOnlaunch;
|
||||
private SwitchCompat swDoubleBack;
|
||||
private SwitchCompat swConversationActions;
|
||||
@@ -100,7 +102,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
||||
final static int DEFAULT_SWIPE_SENSITIVITY = 7;
|
||||
|
||||
private final static String[] RESET_OPTIONS = new String[]{
|
||||
"sync_on_launch", "double_back", "conversation_actions", "conversation_actions_replies", "language_detection",
|
||||
"restore_on_launch", "sync_on_launch", "double_back", "conversation_actions", "conversation_actions_replies", "language_detection",
|
||||
"default_snooze",
|
||||
"pull", "autoscroll", "quick_filter", "quick_scroll", "swipe_sensitivity", "foldernav",
|
||||
"doubletap", "swipenav", "volumenav", "reversed", "swipe_close", "swipe_move",
|
||||
@@ -122,6 +124,8 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
||||
// Get controls
|
||||
|
||||
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);
|
||||
@@ -180,6 +184,14 @@ 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) {
|
||||
prefs.edit().putBoolean("restore_on_launch", checked).apply();
|
||||
}
|
||||
});
|
||||
|
||||
swSyncOnlaunch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
@@ -523,6 +535,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
|
||||
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()));
|
||||
|
||||
Reference in New Issue
Block a user