aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2015-04-14 15:53:50 +0200
committeriNPUTmice <daniel@gultsch.de>2015-04-14 15:53:50 +0200
commitf99e234b886d043968267323ccb4995f20ee4fa4 (patch)
tree37d2ed5e9a0a6ffc4a577ebdcde043476d32597a /src
parentb6cc8c90a00f55866ea906697a40f582643309c2 (diff)
maintain state when rotating settings activity
Diffstat (limited to 'src')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/SettingsActivity.java30
-rw-r--r--src/main/res/xml/preferences.xml14
2 files changed, 26 insertions, 18 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
index d24cb52b..f91bc953 100644
--- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
@@ -7,6 +7,8 @@ import java.util.Locale;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.xmpp.XmppConnection;
+import android.app.Fragment;
+import android.app.FragmentManager;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Build;
@@ -21,9 +23,12 @@ public class SettingsActivity extends XmppActivity implements
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mSettingsFragment = new SettingsFragment();
- getFragmentManager().beginTransaction()
- .replace(android.R.id.content, mSettingsFragment).commit();
+ FragmentManager fm = getFragmentManager();
+ mSettingsFragment = (SettingsFragment) fm.findFragmentById(android.R.id.content);
+ if (mSettingsFragment == null || !mSettingsFragment.getClass().equals(SettingsFragment.class)) {
+ mSettingsFragment = new SettingsFragment();
+ fm.beginTransaction().replace(android.R.id.content, mSettingsFragment).commit();
+ }
}
@Override
@@ -34,18 +39,15 @@ public class SettingsActivity extends XmppActivity implements
@Override
public void onStart() {
super.onStart();
- PreferenceManager.getDefaultSharedPreferences(this)
- .registerOnSharedPreferenceChangeListener(this);
- ListPreference resources = (ListPreference) mSettingsFragment
- .findPreference("resource");
+ PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
+ ListPreference resources = (ListPreference) mSettingsFragment.findPreference("resource");
if (resources != null) {
- ArrayList<CharSequence> entries = new ArrayList<CharSequence>(
- Arrays.asList(resources.getEntries()));
- entries.add(0, Build.MODEL);
- resources.setEntries(entries.toArray(new CharSequence[entries
- .size()]));
- resources.setEntryValues(entries.toArray(new CharSequence[entries
- .size()]));
+ ArrayList<CharSequence> entries = new ArrayList<>(Arrays.asList(resources.getEntries()));
+ if (!entries.contains(Build.MODEL)) {
+ entries.add(0, Build.MODEL);
+ resources.setEntries(entries.toArray(new CharSequence[entries.size()]));
+ resources.setEntryValues(entries.toArray(new CharSequence[entries.size()]));
+ }
}
}
diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml
index d48124a6..9cf0100f 100644
--- a/src/main/res/xml/preferences.xml
+++ b/src/main/res/xml/preferences.xml
@@ -36,7 +36,9 @@
android:title="@string/pref_chat_states" />
</PreferenceCategory>
- <PreferenceCategory android:title="@string/pref_notification_settings" >
+ <PreferenceCategory
+ android:title="@string/pref_notification_settings"
+ android:key="notifications">
<CheckBoxPreference
android:defaultValue="true"
android:key="show_notification"
@@ -45,7 +47,8 @@
<PreferenceScreen
android:dependency="show_notification"
android:summary="@string/pref_quiet_hours_summary"
- android:title="@string/title_pref_quiet_hours">
+ android:title="@string/title_pref_quiet_hours"
+ android:key="quiet_hours">
<CheckBoxPreference
android:defaultValue="false"
android:key="enable_quiet_hours"
@@ -108,10 +111,13 @@
android:summary="@string/pref_show_dynamic_tags_summary"
android:title="@string/pref_show_dynamic_tags" />
</PreferenceCategory>
- <PreferenceCategory android:title="@string/pref_advanced_options" >
+ <PreferenceCategory
+ android:title="@string/pref_advanced_options"
+ android:key="advanced">
<PreferenceScreen
android:summary="@string/pref_expert_options_summary"
- android:title="@string/pref_expert_options" >
+ android:title="@string/pref_expert_options"
+ android:key="expert">
<PreferenceCategory android:title="@string/pref_encryption_settings" >
<CheckBoxPreference
android:defaultValue="false"