Update settings ui after app mode change
This commit is contained in:
parent
4b664f6ee6
commit
10346798fe
5 changed files with 28 additions and 24 deletions
|
@ -15,12 +15,12 @@
|
|||
android:layout="@layout/preference_with_descr"
|
||||
android:title="@string/preferred_locale" />
|
||||
|
||||
<!-- <Preference-->
|
||||
<!-- android:icon="@drawable/ic_action_folder"-->
|
||||
<!-- android:key="external_storage_dir"-->
|
||||
<!-- android:layout="@layout/preference_with_descr"-->
|
||||
<!-- android:persistent="false"-->
|
||||
<!-- android:title="@string/application_dir" />-->
|
||||
<Preference
|
||||
android:key="external_storage_dir"
|
||||
android:layout="@layout/preference_with_descr"
|
||||
android:persistent="false"
|
||||
android:title="@string/application_dir"
|
||||
tools:icon="@drawable/ic_action_folder" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="privacy_and_security"
|
||||
|
|
|
@ -1944,7 +1944,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
Fragment fragment = Fragment.instantiate(this, fragmentName);
|
||||
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, fragment, fragmentName)
|
||||
.replace(R.id.fragmentContainer, fragment, fragmentName)
|
||||
.addToBackStack(fragmentName)
|
||||
.commitAllowingStateLoss();
|
||||
|
||||
|
|
|
@ -58,7 +58,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
protected OsmandApplication app;
|
||||
protected OsmandSettings settings;
|
||||
protected UiUtilities iconsCache;
|
||||
protected List<ApplicationMode> modes = new ArrayList<ApplicationMode>();
|
||||
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue