mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-24 15:11:03 +00:00
Added option to restore app state on start
This commit is contained in:
parent
758d9aa47a
commit
6381c85fdd
6 changed files with 58 additions and 5 deletions
|
@ -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()));
|
||||
|
|
|
@ -75,6 +75,29 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swRestoreOnLaunch"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:checked="true"
|
||||
android:text="@string/title_advanced_restore_on_launch"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvCaptionGeneral"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvRestoreOnLaunchHint"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="48dp"
|
||||
android:text="@string/title_advanced_restore_on_launch_hint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swRestoreOnLaunch" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swSyncOnlaunch"
|
||||
android:layout_width="0dp"
|
||||
|
@ -83,7 +106,7 @@
|
|||
android:text="@string/title_advanced_sync_on_launch"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvCaptionGeneral"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvRestoreOnLaunchHint"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
|
|
|
@ -574,6 +574,7 @@
|
|||
<string name="title_advanced_authentication_some">Partial authentication</string>
|
||||
<string name="title_advanced_authentication_all">Complete authentication</string>
|
||||
|
||||
<string name="title_advanced_restore_on_launch">Restore app state on start</string>
|
||||
<string name="title_advanced_sync_on_launch">Synchronize on start</string>
|
||||
<string name="title_advanced_double_back">Double \'back\' to exit</string>
|
||||
<string name="title_advanced_conversation_actions">Suggest actions (Android 10+)</string>
|
||||
|
@ -860,6 +861,7 @@
|
|||
<string name="compressed">The contents of compressed files (%1$s) with more than %2$s files or with files larger than %3$s will not be shown</string>
|
||||
<string name="title_advanced_parse_classes_hint">This will more accurately display messages, but possibly with a delay</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_language_detection_hint">Language detection support depends on the device manufacturer</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>
|
||||
|
|
Loading…
Reference in a new issue