From 6f2f305ae85f3c415308f231c340d21a337fe39f Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 3 Dec 2018 17:39:13 +0100 Subject: [PATCH] Fixed stop on sort --- app/src/main/java/eu/faircode/email/ActivityBase.java | 9 +++++++-- .../main/java/eu/faircode/email/FragmentMessages.java | 8 +++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index 83f77cabcc..c73d898994 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -27,12 +27,18 @@ import android.preference.PreferenceManager; import android.util.Log; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; abstract class ActivityBase extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { + private static String[] restart = new String[]{ + "unified", "threading", "compact", "avatars", "identicons", "preview", + "browse", "actionbar", "autoclose", "confirm", "debug" + }; + @Override protected void onCreate(Bundle savedInstanceState) { Log.i(Helper.TAG, "Create " + this.getClass().getName() + " version=" + BuildConfig.VERSION_NAME); @@ -83,7 +89,6 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc super.onActivityResult(requestCode, resultCode, data); } - @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { Log.i(Helper.TAG, "Preference " + key + "=" + prefs.getAll().get(key)); @@ -91,7 +96,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc finish(); if (this.getClass().equals(ActivitySetup.class)) startActivity(getIntent()); - } else if (!this.getClass().equals(ActivitySetup.class)) + } else if (!this.getClass().equals(ActivitySetup.class) && Arrays.asList(restart).contains(key)) finish(); } diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 7621a0d7ca..05f3d59dc7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -1308,8 +1308,13 @@ public class FragmentMessages extends FragmentEx { return true; case R.id.menu_sort_on_unread: + prefs.edit().putString("sort", "unread").apply(); + item.setChecked(true); + loadMessages(); + return true; + case R.id.menu_sort_on_starred: - prefs.edit().putString("sort", item.getItemId() == R.id.menu_sort_on_unread ? "unread" : "starred").apply(); + prefs.edit().putString("sort", "starred").apply(); item.setChecked(true); loadMessages(); return true; @@ -1396,6 +1401,7 @@ public class FragmentMessages extends FragmentEx { boolean browse = prefs.getBoolean("browse", true); boolean debug = prefs.getBoolean("debug", false); + // Sort changed if (messages != null) messages.removeObservers(getViewLifecycleOwner());