diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java
index df18d06ab8..9c0a3a9b5e 100644
--- a/app/src/main/java/eu/faircode/email/ActivityBase.java
+++ b/app/src/main/java/eu/faircode/email/ActivityBase.java
@@ -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);
}
diff --git a/app/src/main/java/eu/faircode/email/ActivityMain.java b/app/src/main/java/eu/faircode/email/ActivityMain.java
index 5eccf24546..c88382c1a8 100644
--- a/app/src/main/java/eu/faircode/email/ActivityMain.java
+++ b/app/src/main/java/eu/faircode/email/ActivityMain.java
@@ -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) {
diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java
index d095cd0522..d0eba3a625 100644
--- a/app/src/main/java/eu/faircode/email/FragmentCompose.java
+++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java
@@ -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);
diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java
index 7f3c920cfd..84f4a7e8ca 100644
--- a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java
+++ b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java
@@ -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()));
diff --git a/app/src/main/res/layout/fragment_options_behavior.xml b/app/src/main/res/layout/fragment_options_behavior.xml
index adef964349..c3de8612f1 100644
--- a/app/src/main/res/layout/fragment_options_behavior.xml
+++ b/app/src/main/res/layout/fragment_options_behavior.xml
@@ -75,6 +75,29 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
+
+
+
+
Partial authentication
Complete authentication
+ Restore app state on start
Synchronize on start
Double \'back\' to exit
Suggest actions (Android 10+)
@@ -860,6 +861,7 @@
The contents of compressed files (%1$s) with more than %2$s files or with files larger than %3$s will not be shown
This will more accurately display messages, but possibly with a delay
+ Restore last app state when restarted via the launcher icon within %1$d minutes
Language detection support depends on the device manufacturer
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