Added option to restore app state on start

This commit is contained in:
M66B
2022-06-24 12:15:41 +02:00
parent 758d9aa47a
commit 6381c85fdd
6 changed files with 58 additions and 5 deletions

View File

@@ -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) {