From 00bb5273332344af1a6a825c05f9c2f9d1c82334 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 5 Jun 2017 14:57:09 +0200 Subject: [PATCH] recreate settingsactivity when theme changed --- .../eu/siacs/conversations/ui/ContactDetailsActivity.java | 2 +- .../java/eu/siacs/conversations/ui/SettingsActivity.java | 7 +++++++ .../siacs/conversations/ui/StartConversationActivity.java | 6 ++++-- src/main/java/eu/siacs/conversations/ui/XmppActivity.java | 2 +- .../eu/siacs/conversations/ui/adapter/ListItemAdapter.java | 6 +++++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index f7c4c7b2f..772f32690 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -250,7 +250,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp recreate(); } else { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); - this.showDynamicTags = preferences.getBoolean("show_dynamic_tags", false); + this.showDynamicTags = preferences.getBoolean(SettingsActivity.SHOW_DYNAMIC_TAGS, false); this.showLastSeen = preferences.getBoolean("last_activity", false); } } diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index ad24b7b0b..28a167a3b 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -46,6 +46,8 @@ public class SettingsActivity extends XmppActivity implements public static final String BLIND_TRUST_BEFORE_VERIFICATION = "btbv"; public static final String AUTOMATIC_MESSAGE_DELETION = "automatic_message_deletion"; public static final String BROADCAST_LAST_ACTIVITY = "last_activity"; + public static final String THEME = "theme"; + public static final String SHOW_DYNAMIC_TAGS = "show_dynamic_tags"; public static final int REQUEST_WRITE_LOGS = 0xbf8701; private SettingsFragment mSettingsFragment; @@ -371,6 +373,11 @@ public class SettingsActivity extends XmppActivity implements reconnectAccounts(); } else if (name.equals(AUTOMATIC_MESSAGE_DELETION)) { xmppConnectionService.expireOldMessages(true); + } else if (name.equals(THEME)) { + final int theme = findTheme(); + if (this.mTheme != theme) { + recreate(); + } } } diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index aa7adff03..540d8defa 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -90,9 +90,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU private ViewPager mViewPager; private ListPagerAdapter mListPagerAdapter; private List contacts = new ArrayList<>(); - private ArrayAdapter mContactsAdapter; + private ListItemAdapter mContactsAdapter; private List conferences = new ArrayList<>(); - private ArrayAdapter mConferenceAdapter; + private ListItemAdapter mConferenceAdapter; private List mActivatedAccounts = new ArrayList<>(); private List mKnownHosts; private List mKnownConferenceHosts; @@ -289,6 +289,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } else { askForContactsPermissions(); } + mConferenceAdapter.refreshSettings(); + mContactsAdapter.refreshSettings(); } @Override diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 758913887..0586a1f9a 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -1038,7 +1038,7 @@ public abstract class XmppActivity extends Activity { } protected int findTheme() { - Boolean dark = getPreferences().getString("theme", "light").equals("dark"); + Boolean dark = getPreferences().getString(SettingsActivity.THEME, "light").equals("dark"); Boolean larger = getPreferences().getBoolean("use_larger_font", false); if(dark) { diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java index 89775e137..11027d800 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java @@ -23,6 +23,7 @@ import java.util.concurrent.RejectedExecutionException; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.ListItem; +import eu.siacs.conversations.ui.SettingsActivity; import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.utils.UIHelper; @@ -45,8 +46,11 @@ public class ListItemAdapter extends ArrayAdapter { public ListItemAdapter(XmppActivity activity, List objects) { super(activity, 0, objects); this.activity = activity; + } + + public void refreshSettings() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); - this.showDynamicTags = preferences.getBoolean("show_dynamic_tags",false); + this.showDynamicTags = preferences.getBoolean(SettingsActivity.SHOW_DYNAMIC_TAGS,false); } @Override