From 10346798feba2a5bb352da32ad1ed6f7ec5a9756 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 9 Sep 2019 11:46:12 +0300 Subject: [PATCH] Update settings ui after app mode change --- OsmAnd/res/xml/global_settings.xml | 12 ++++----- .../osmand/plus/activities/MapActivity.java | 2 +- .../plus/settings/BaseSettingsFragment.java | 27 +++++++++---------- .../settings/ConfigureProfileFragment.java | 2 +- .../plus/settings/GlobalSettingsFragment.java | 9 ++++++- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/OsmAnd/res/xml/global_settings.xml b/OsmAnd/res/xml/global_settings.xml index 0ea38d0019..6edd48ef4d 100644 --- a/OsmAnd/res/xml/global_settings.xml +++ b/OsmAnd/res/xml/global_settings.xml @@ -15,12 +15,12 @@ android:layout="@layout/preference_with_descr" android:title="@string/preferred_locale" /> - - - - - - + modes = new ArrayList(); private boolean nightMode; private boolean wasDrawerDisabled; @@ -67,20 +66,19 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl public void onCreate(Bundle savedInstanceState) { app = requireMyApplication(); settings = app.getSettings(); - nightMode = !settings.isLightContent(); super.onCreate(savedInstanceState); - modes.clear(); - modes.addAll(ApplicationMode.values(app)); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = super.onCreateView(inflater, container, savedInstanceState); + nightMode = !settings.isLightContent(); + View view = super.onCreateView(inflater, container, savedInstanceState); if (view != null) { AndroidUtils.addStatusBarPadding21v(getContext(), view); createToolbar(inflater, view); setDivider(null); + updateAllSettings(); } return view; @@ -89,6 +87,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl @Override public void onResume() { super.onResume(); + MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { wasDrawerDisabled = mapActivity.isDrawerDisabled(); @@ -114,7 +113,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl if (toolbarRes != -1) { Context activityContext = getActivity(); - final int themeRes = nightMode ? darkTheme : lightTheme; + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final Context themedContext = new ContextThemeWrapper(activityContext, themeRes); LayoutInflater themedInflater = LayoutInflater.from(themedContext); @@ -176,22 +175,17 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl view.setBackgroundColor(ContextCompat.getColor(app, getBackgroundColor())); } - int darkTheme = R.style.OsmandDarkTheme; - int lightTheme = R.style.OsmandLightTheme; - @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { getPreferenceManager().setPreferenceDataStore(settings.getDataStore()); - updatePreferencesScreen(); } @Override public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { + Context activityContext = getActivity(); - - final int themeRes = nightMode ? darkTheme : lightTheme; + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final Context themedContext = new ContextThemeWrapper(activityContext, themeRes); - LayoutInflater themedInflater = LayoutInflater.from(themedContext); return super.onCreateRecyclerView(themedInflater, parent, savedInstanceState); @@ -253,7 +247,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl singleSelectDialogBuilder.setAdapter(modeNames, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - ApplicationMode selectedAppMode = modes.get(which); + ApplicationMode selectedAppMode = ApplicationMode.values(app).get(which); requireSettings().APPLICATION_MODE.set(selectedAppMode); updateAllSettings(); } @@ -278,7 +272,10 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl public void updateAllSettings() { getListView().getRecycledViewPool().clear(); - getPreferenceScreen().removeAll(); + PreferenceScreen screen = getPreferenceScreen(); + if (screen != null) { + getPreferenceScreen().removeAll(); + } updatePreferencesScreen(); updateToolbar(getView()); } diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java index 3d169e6262..2d07367c01 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java @@ -125,7 +125,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { private Drawable getPluginIcon(OsmandPlugin plugin) { int iconResId = plugin.getLogoResourceId(); - return plugin.isActive() ? getActiveIcon(iconResId) : getContentIcon(iconResId); + return plugin.isActive() ? getActiveIcon(iconResId) : getIcon(iconResId, isNightMode() ? R.color.icon_color_secondary_dark : R.color.icon_color_secondary_light); } private Intent getPluginIntent(OsmandPlugin plugin) { diff --git a/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java index f8472e81b8..04629a829c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java @@ -9,6 +9,7 @@ import android.util.Pair; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.SettingsGeneralActivity; import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment; @@ -41,7 +42,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send protected void setupPreferences() { setupDefaultAppModePref(); setupPreferredLocalePref(); -// setupExternalStorageDirPref(); + setupExternalStorageDirPref(); setupSendAnonymousDataPref(); setupEnableProxyPref(); @@ -147,6 +148,12 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send } } + private void setupExternalStorageDirPref() { + Preference externalStorageDir = (Preference) findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR); + externalStorageDir.setIcon(getContentIcon(R.drawable.ic_action_folder)); + + } + private void setupSendAnonymousDataPref() { boolean enabled = settings.SEND_ANONYMOUS_MAP_DOWNLOADS_DATA.get() || settings.SEND_ANONYMOUS_APP_USAGE_DATA.get();