diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
index 77f5640950..0501e7f969 100644
--- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
+++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
@@ -19,6 +19,8 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
+import android.app.ActivityManager;
+import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
@@ -50,6 +52,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swAuthentication;
private SwitchCompat swParanoid;
private TextView tvParanoidHint;
+ private SwitchCompat swCacheLists;
+ private TextView tvCacheListsHint;
private SwitchCompat swWatchdog;
private SwitchCompat swUpdates;
private SwitchCompat swCrashReports;
@@ -60,7 +64,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private Group grpSearchLocal;
private final static String[] RESET_OPTIONS = new String[]{
- "badge", "subscriptions", "english", "authentication", "paranoid", "watchdog", "updates", "crash_reports", "debug"
+ "badge", "subscriptions", "english", "authentication", "paranoid", "cache_lists", "watchdog", "updates", "crash_reports", "debug"
};
private final static String[] RESET_QUESTIONS = new String[]{
@@ -83,6 +87,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swAuthentication = view.findViewById(R.id.swAuthentication);
swParanoid = view.findViewById(R.id.swParanoid);
tvParanoidHint = view.findViewById(R.id.tvParanoidHint);
+ swCacheLists = view.findViewById(R.id.swCacheLists);
+ tvCacheListsHint = view.findViewById(R.id.tvCacheListsHint);
swWatchdog = view.findViewById(R.id.swWatchdog);
swUpdates = view.findViewById(R.id.swUpdates);
swCrashReports = view.findViewById(R.id.swCrashReports);
@@ -148,6 +154,14 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
});
}
+ swCacheLists.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
+ prefs.edit().putBoolean("cache_lists", checked).apply();
+ WorkerWatchdog.init(getContext());
+ }
+ });
+
swWatchdog.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -238,12 +252,18 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swEnglish.setChecked(prefs.getBoolean("english", false));
swAuthentication.setChecked(prefs.getBoolean("authentication", false));
swParanoid.setChecked(prefs.getBoolean("paranoid", true));
+ swCacheLists.setChecked(prefs.getBoolean("cache_lists", true));
swWatchdog.setChecked(prefs.getBoolean("watchdog", true));
swUpdates.setChecked(prefs.getBoolean("updates", true));
swUpdates.setVisibility(Helper.isPlayStoreInstall(getContext()) ? View.GONE : View.VISIBLE);
swCrashReports.setChecked(prefs.getBoolean("crash_reports", false));
swDebug.setChecked(prefs.getBoolean("debug", false));
+ ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
+ int class_mb = am.getMemoryClass();
+
+ tvCacheListsHint.setText(getString(R.string.title_advanced_cache_list_hint, class_mb + " MB"));
+
grpSearchLocal.setVisibility(Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M ? View.GONE : View.VISIBLE);
}
diff --git a/app/src/main/java/eu/faircode/email/ViewModelMessages.java b/app/src/main/java/eu/faircode/email/ViewModelMessages.java
index 19dd07a605..e0bb36f3cb 100644
--- a/app/src/main/java/eu/faircode/email/ViewModelMessages.java
+++ b/app/src/main/java/eu/faircode/email/ViewModelMessages.java
@@ -51,9 +51,10 @@ public class ViewModelMessages extends ViewModel {
private static final int LOCAL_PAGE_SIZE = 100;
private static final int REMOTE_PAGE_SIZE = 10;
+ private static final int LOW_MEM_MB = 64;
Model getModel(
- Context context, final LifecycleOwner owner,
+ final Context context, final LifecycleOwner owner,
final AdapterMessage.ViewType viewType,
long account, long folder, String thread, long id,
String query, boolean server) {
@@ -153,8 +154,21 @@ public class ViewModelMessages extends ViewModel {
public void onDestroyed() {
Log.i("Destroy model " + viewType);
- if (viewType == AdapterMessage.ViewType.THREAD)
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ boolean cache = prefs.getBoolean("cache_lists", true);
+
+ Runtime rt = Runtime.getRuntime();
+ long used = (rt.totalMemory() - rt.freeMemory());
+ long max = rt.maxMemory();
+ long free_mb = (max - used) / 1024L / 1024L;
+
+ boolean lowmem = (free_mb < LOW_MEM_MB);
+
+ if (viewType == AdapterMessage.ViewType.THREAD || !cache || lowmem) {
+ Log.i("Remove model " + viewType +
+ " cache=" + cache + " lowmem=" + lowmem + " free=" + free_mb + " MB");
remove(viewType);
+ }
dump();
}
diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml
index 2eb6ee6a2d..1c0a319803 100644
--- a/app/src/main/res/layout/fragment_options_misc.xml
+++ b/app/src/main/res/layout/fragment_options_misc.xml
@@ -127,6 +127,28 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swParanoid" />
+
+
+
+
Force English language
Show a warning when the receiving server could not authenticate the message
Extra privacy features
+ Cache message lists
Periodically check if FairEmail is still active
Check for updates
Send error reports
@@ -250,6 +251,7 @@
Only available on supported launchers
This will restart the app
See the FAQ for details
+ Memory available: %1$s
Enable extra logging and show debug information at various places
Select …