diff options
author | Александр Зацепин <az@mapswithme.com> | 2017-07-30 16:09:01 +0300 |
---|---|---|
committer | Arsentiy Milchakov <milcars@mapswithme.com> | 2017-07-31 11:17:04 +0300 |
commit | 08cd782072c4182ced7b88345f0869fdaa15b169 (patch) | |
tree | f0a0b4a7c5f24e4b42b37050bfb39f0a3b352e6b | |
parent | c2d5dcba5bcde0e312f5503f0b965d9796b59c3c (diff) |
[android] Fixed removing the preference when it's needed
-rw-r--r-- | android/res/xml/prefs_main.xml | 4 | ||||
-rw-r--r-- | android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java | 30 |
2 files changed, 25 insertions, 9 deletions
diff --git a/android/res/xml/prefs_main.xml b/android/res/xml/prefs_main.xml index cb7a623bf2..68aa670622 100644 --- a/android/res/xml/prefs_main.xml +++ b/android/res/xml/prefs_main.xml @@ -88,7 +88,7 @@ android:order="11"/> <SwitchPreferenceCompat android:key="@string/pref_enable_logging" - android:title="Enable logging" + android:title="@string/enable_logging" android:defaultValue="false" android:order="12"/> <ListPreference @@ -167,4 +167,4 @@ android:fragment="com.mapswithme.maps.settings.AboutFragment" android:order="2"/> </android.support.v7.preference.PreferenceCategory> -</android.support.v7.preference.PreferenceScreen>
\ No newline at end of file +</android.support.v7.preference.PreferenceScreen> diff --git a/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java b/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java index d44a209a13..4de65837f9 100644 --- a/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java +++ b/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java @@ -13,6 +13,7 @@ import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.support.v7.preference.ListPreference; import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceCategory; import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.TwoStatePreference; import android.text.Spannable; @@ -87,12 +88,16 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment if (singleStorageOnly()) { if (old != null) - getPreferenceScreen().removePreference(old); + { + removePreference(getString(R.string.pref_settings_general), old); + } } else { if (old == null && mStoragePref != null) + { getPreferenceScreen().addPreference(mStoragePref); + } } } @@ -129,7 +134,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment if (mPrefEnabled != null) mPrefEnabled.setTitle(R.string.on); if (mLangInfoLink != null) - getPreferenceScreen().removePreference(mLangInfoLink); + removePreference(getString(R.string.pref_navigation), mLangInfoLink); if (mCurrentLanguage != null && mCurrentLanguage.downloaded) { @@ -220,7 +225,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment mLangInfo.setSummary(enabled ? R.string.prefs_languages_information : R.string.prefs_languages_information_off); if (enabled) - getPreferenceScreen().removePreference(mLangInfoLink); + removePreference(getString(R.string.pref_navigation), mLangInfoLink); else if (isOnTtsScreen()) getPreferenceScreen().addPreference(mLangInfoLink); @@ -357,7 +362,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment if (pref == null) return; - getPreferenceScreen().removePreference(pref); + removePreference(getString(R.string.pref_settings_general), pref); } private void initLangInfoLink() @@ -380,7 +385,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment return false; } }); - mPreferenceScreen.removePreference(mLangInfoLink); + removePreference(getString(R.string.pref_navigation), mLangInfoLink); } } @@ -511,7 +516,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment if (!MwmApplication.prefs().getBoolean(SearchFragment.PREFS_SHOW_ENABLE_LOGGING_SETTING, BuildConfig.BUILD_TYPE.equals("beta"))) { - getPreferenceScreen().removePreference(pref); + removePreference(getString(R.string.pref_settings_general), pref); } else { @@ -560,7 +565,9 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment return; if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(MwmApplication.get()) != ConnectionResult.SUCCESS) - getPreferenceScreen().removePreference(pref); + { + removePreference(getString(R.string.pref_settings_general), pref); + } else { ((TwoStatePreference) pref).setChecked(Config.useGoogleServices()); @@ -831,6 +838,15 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment }); } + private void removePreference(@NonNull String categoryKey, @NonNull Preference preference) + { + PreferenceCategory category = (PreferenceCategory) findPreference(categoryKey); + if (category == null) + return; + + category.removePreference(preference); + } + @Override public void onAttach(Context context) { |