diff --git a/app/src/main/java/eu/faircode/email/ActivityCompose.java b/app/src/main/java/eu/faircode/email/ActivityCompose.java index de2af17dad..fb0736b6ca 100644 --- a/app/src/main/java/eu/faircode/email/ActivityCompose.java +++ b/app/src/main/java/eu/faircode/email/ActivityCompose.java @@ -22,6 +22,7 @@ package eu.faircode.email; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; import android.text.Html; @@ -35,15 +36,19 @@ import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleOwner; +import androidx.preference.PreferenceManager; import java.io.File; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; public class ActivityCompose extends ActivityBase implements FragmentManager.OnBackStackChangedListener { static final int PI_REPLY = 1; + private static final long APPEND_ATTACHMENT_INTERVAL = 3 * 60 * 1000L; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -207,8 +212,13 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB args = intent.getExtras(); FragmentManager fm = getSupportFragmentManager(); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + + long now = new Date().getTime(); + long last = prefs.getLong("last_composed", 0L); if (!create && + now - last < APPEND_ATTACHMENT_INTERVAL && args.size() == 1 && args.containsKey("attachments")) { List fragments = fm.getFragments(); if (fragments.size() == 1) { diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 6f251faef3..850c384e6b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1419,13 +1419,18 @@ public class FragmentCompose extends FragmentBase { @Override public void onPause() { + final Context context = getContext(); + if (state == State.LOADED) { Bundle extras = new Bundle(); extras.putBoolean("autosave", true); onAction(R.id.action_save, extras, "pause"); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + prefs.edit().putLong("last_composed", new Date().getTime()).apply(); } - ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); cm.unregisterNetworkCallback(networkCallback); super.onPause();