1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-27 10:17:18 +00:00

Add files to draft edited within 3 minutes

This commit is contained in:
M66B 2021-08-23 12:22:42 +02:00
parent 228b1092f2
commit 501686111f
2 changed files with 16 additions and 1 deletions

View file

@ -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<Fragment> fragments = fm.getFragments();
if (fragments.size() == 1) {

View file

@ -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();