Add reset confirmation dialog initial commit
This commit is contained in:
parent
33a552af84
commit
3a9a8b3bd4
4 changed files with 85 additions and 10 deletions
|
@ -11,6 +11,9 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="reset_confirmation_descr">By clicking %1$s, you will lose all your changes.</string>
|
||||
<string name="reset_all_profile_settings_descr">All profile settings will be reset to the state after installation.</string>
|
||||
<string name="reset_all_profile_settings">Reset all profile settings to default?</string>
|
||||
<string name="select_navigation_icon">Select navigation icon</string>
|
||||
<string name="select_map_icon">Select map icon</string>
|
||||
<string name="delete_profiles_descr">After you tap Apply, deleted profiles will be lost completely.</string>
|
||||
|
|
|
@ -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 {
|
||||
}
|
||||
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);
|
||||
if (savedInstanceState != null) {
|
||||
selectedAppMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(SELECTED_APP_MODE_KEY), null);
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,10 +274,14 @@ 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,
|
||||
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() {
|
||||
Preference exportProfile = findPreference(EXPORT_PROFILE);
|
||||
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue