From 3a9a8b3bd41fa29a3fbaee32bf8c48a537cf47ac Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 27 Dec 2019 18:20:45 +0200 Subject: [PATCH] Add reset confirmation dialog initial commit --- OsmAnd/res/values/strings.xml | 3 + .../SelectCopyAppModeBottomSheet.java | 13 ++-- .../settings/ConfigureProfileFragment.java | 16 +++-- .../ResetProfilePrefsBottomSheet.java | 63 +++++++++++++++++++ 4 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/settings/bottomsheets/ResetProfilePrefsBottomSheet.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index f0870a3cf0..ab0e60d3ac 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,9 @@ Thx - Hardy --> + By clicking %1$s, you will lose all your changes. + All profile settings will be reset to the state after installation. + Reset all profile settings to default? Select navigation icon Select map icon After you tap Apply, deleted profiles will be lost completely. diff --git a/OsmAnd/src/net/osmand/plus/profiles/SelectCopyAppModeBottomSheet.java b/OsmAnd/src/net/osmand/plus/profiles/SelectCopyAppModeBottomSheet.java index bcd1e10b42..2de6afb21f 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/SelectCopyAppModeBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/profiles/SelectCopyAppModeBottomSheet.java @@ -34,16 +34,16 @@ public class SelectCopyAppModeBottomSheet extends AppModesBottomSheetDialogFragm Bundle args = getArguments(); if (args != null && args.containsKey(CURRENT_APP_MODE_KEY)) { currentAppMode = ApplicationMode.valueOfStringKey(args.getString(CURRENT_APP_MODE_KEY), null); - } else { - OsmandApplication app = requiredMyApplication(); - if (currentAppMode == null) { - currentAppMode = app.getSettings().getApplicationMode(); - } } - super.onCreate(savedInstanceState); if (savedInstanceState != null) { selectedAppMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(SELECTED_APP_MODE_KEY), null); + currentAppMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(CURRENT_APP_MODE_KEY), null); } + OsmandApplication app = requiredMyApplication(); + if (currentAppMode == null) { + currentAppMode = app.getSettings().getApplicationMode(); + } + super.onCreate(savedInstanceState); } public ApplicationMode getSelectedAppMode() { @@ -75,6 +75,7 @@ public class SelectCopyAppModeBottomSheet extends AppModesBottomSheetDialogFragm super.onSaveInstanceState(outState); if (selectedAppMode != null) { outState.putString(SELECTED_APP_MODE_KEY, selectedAppMode.getStringKey()); + outState.putString(CURRENT_APP_MODE_KEY, currentAppMode.getStringKey()); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java index 386bb818fa..6421a9bbf4 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java @@ -46,6 +46,7 @@ import net.osmand.plus.activities.PluginActivity; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.profiles.SelectCopyAppModeBottomSheet; +import net.osmand.plus.settings.bottomsheets.ResetProfilePrefsBottomSheet; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; import net.osmand.plus.skimapsplugin.SkiMapsPlugin; @@ -273,9 +274,13 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { } private void setupResetToDefaultPref() { - Preference copyProfilePrefs = findPreference(RESET_TO_DEFAULT); - copyProfilePrefs.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_reset_to_default_dark, - isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light)); + Preference resetToDefault = findPreference(RESET_TO_DEFAULT); + if (getSelectedAppMode().isCustomProfile()) { + resetToDefault.setVisible(false); + } else { + resetToDefault.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_reset_to_default_dark, + isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light)); + } } private void setupExportProfilePref() { @@ -397,7 +402,10 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { ConfigureProfileFragment.this, false, getSelectedAppMode()); } } else if (RESET_TO_DEFAULT.equals(prefId)) { - app.getSettings().resetPreferencesForProfile(getSelectedAppMode()); + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + ResetProfilePrefsBottomSheet.showInstance(fragmentManager, prefId, this, false, getSelectedAppMode()); + } } else if (EXPORT_PROFILE.equals(prefId)) { Context ctx = requireContext(); final ApplicationMode profile = getSelectedAppMode(); diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ResetProfilePrefsBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ResetProfilePrefsBottomSheet.java new file mode 100644 index 0000000000..f53abd7ef7 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ResetProfilePrefsBottomSheet.java @@ -0,0 +1,63 @@ +package net.osmand.plus.settings.bottomsheets; + +import android.content.Context; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; + +import net.osmand.plus.ApplicationMode; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; + +public class ResetProfilePrefsBottomSheet extends BasePreferenceBottomSheet { + + public static final String TAG = ResetProfilePrefsBottomSheet.class.getSimpleName(); + + @Override + public void createMenuItems(Bundle savedInstanceState) { + Context ctx = getContext(); + if (ctx == null) { + return; + } + + items.add(new TitleItem(getString(R.string.reset_all_profile_settings))); + items.add(new TitleItem(getAppMode().toHumanString(ctx))); + items.add(new LongDescriptionItem(getString(R.string.reset_all_profile_settings_descr))); + items.add(new LongDescriptionItem(getString(R.string.reset_confirmation_descr, getString(R.string.shared_string_reset)))); + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_reset; + } + + @Override + protected void onRightBottomButtonClick() { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getSettings().resetPreferencesForProfile(getAppMode()); + } + dismiss(); + } + + public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target, + boolean usedOnMap, @NonNull ApplicationMode appMode) { + try { + Bundle args = new Bundle(); + args.putString(PREFERENCE_ID, key); + + ResetProfilePrefsBottomSheet fragment = new ResetProfilePrefsBottomSheet(); + fragment.setArguments(args); + fragment.setUsedOnMap(usedOnMap); + fragment.setAppMode(appMode); + fragment.setTargetFragment(target, 0); + fragment.show(fragmentManager, TAG); + return true; + } catch (RuntimeException e) { + return false; + } + } +} \ No newline at end of file