From edbb876830ba405d7b5d6b05f55d6c44cabafa76 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Tue, 5 May 2020 15:50:33 +0300 Subject: [PATCH] reset configure map item if hidden --- OsmAnd/res/values/strings.xml | 1 + .../src/net/osmand/plus/ContextMenuItem.java | 12 ++-- .../audionotes/AudioVideoNotesPlugin.java | 2 + .../osmand/plus/dialogs/ConfigureMapMenu.java | 60 ++++++++++++++-- .../plus/mapillary/MapillaryPlugin.java | 3 + .../osmand/plus/osmedit/OsmEditingPlugin.java | 4 ++ .../rastermaps/OsmandRasterMapsPlugin.java | 4 ++ .../settings/ConfigureMenuItemsFragment.java | 71 +++++++++++++++++-- .../ChangeGeneralProfilesPrefBottomSheet.java | 6 +- .../osmand/plus/srtmplugin/SRTMPlugin.java | 3 + 10 files changed, 146 insertions(+), 20 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index d87c0fe778..3318a15b13 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Reset hidden items? Add / Edit Parking positions Create/Edit POI diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuItem.java b/OsmAnd/src/net/osmand/plus/ContextMenuItem.java index 80f7bf87af..9863b31e65 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuItem.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuItem.java @@ -278,7 +278,7 @@ public class ContextMenuItem { private ContextMenuAdapter.ItemClickListener mItemClickListener = null; private ContextMenuAdapter.OnIntegerValueChangedListener mIntegerListener = null; private ContextMenuAdapter.ProgressListener mProgressListener = null; - private OnItemDeleteAction itemDeleteAction; + private OnItemDeleteAction mItemDeleteAction = null; private boolean mSkipPaintingWithoutColor; private boolean mHideDivider; private boolean mHideCompoundButton; @@ -380,8 +380,9 @@ public class ContextMenuItem { return this; } - public void setItemDeleteAction(OnItemDeleteAction itemDeleteAction) { - this.itemDeleteAction = itemDeleteAction; + public ItemBuilder setItemDeleteAction(OnItemDeleteAction itemDeleteAction) { + this.mItemDeleteAction = itemDeleteAction; + return this; } public ItemBuilder hideDivider(boolean hideDivider) { @@ -416,14 +417,13 @@ public class ContextMenuItem { public ContextMenuItem createItem() { return new ContextMenuItem(mTitleId, mTitle, mIcon, mColorRes, mSecondaryIcon, mSelected, mProgress, mLayout, mLoading, mIsCategory, mIsClickable, mSkipPaintingWithoutColor, - mPosition, mOrder, mDescription, mItemClickListener, mIntegerListener, mProgressListener, itemDeleteAction, + mPosition, mOrder, mDescription, mItemClickListener, mIntegerListener, mProgressListener, mItemDeleteAction, mHideDivider, mHideCompoundButton, mMinHeight, mTag, mId); } } - // when action is deleted or reset public interface OnItemDeleteAction { - boolean itemWasDeleted(boolean profileOnly); + void itemWasDeleted(ApplicationMode appMode, boolean profileOnly); } } diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index ba8dc4c8b8..a1432fce3b 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -61,6 +61,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.TabActivity.TabItem; import net.osmand.plus.dashboard.tools.DashFragmentData; +import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; @@ -652,6 +653,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { .setSelected(SHOW_RECORDINGS.get()) .setIcon(R.drawable.ic_action_micro_dark) .setColor(SHOW_RECORDINGS.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(SHOW_RECORDINGS))) .setListener(listener).createItem()); } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 224226f818..32c4e48086 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -31,6 +31,7 @@ import net.osmand.CallbackWithObject; import net.osmand.GPXUtilities; import net.osmand.PlatformUtil; import net.osmand.core.android.MapRendererContext; +import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.ItemClickListener; import net.osmand.plus.ContextMenuAdapter.OnRowItemClick; @@ -40,6 +41,7 @@ import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.ListStringPreference; import net.osmand.plus.R; @@ -53,7 +55,6 @@ import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.render.RendererRegistry; -import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.corenative.NativeCoreContext; @@ -317,6 +318,32 @@ public class ConfigureMapMenu { } } + public static final class ItemResetListener implements ContextMenuItem.OnItemDeleteAction { + + private List prefs; + + public ItemResetListener(@NonNull List prefs) { + this.prefs = prefs; + } + + @Override + public void itemWasDeleted(@NonNull ApplicationMode appMode, boolean profileOnly) { + for (OsmandSettings.OsmandPreference pref : prefs) { + resetSetting(appMode, pref, profileOnly); + } + } + + private void resetSetting(ApplicationMode appMode, OsmandPreference preference, boolean profileOnly) { + if (profileOnly) { + preference.resetModeToDefault(appMode); + } else { + for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { + preference.resetModeToDefault(mode); + } + } + } + } + private void createLayersItems(List customRules, ContextMenuAdapter adapter, final MapActivity activity, final int themeRes, final boolean nightMode) { final OsmandApplication app = activity.getMyApplication(); @@ -336,7 +363,9 @@ public class ConfigureMapMenu { .setSelected(settings.SHOW_FAVORITES.get()) .setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setIcon(R.drawable.ic_action_fav_dark) - .setListener(l).createItem()); + .setItemDeleteAction(new ItemResetListener(Arrays.asList(settings.SHOW_FAVORITES))) + .setListener(l) + .createItem()); selected = app.getPoiFilters().isShowingAnyPoi(PoiTemplateList.POI); adapter.addItem(new ContextMenuItem.ItemBuilder() .setId(POI_OVERLAY_ID) @@ -354,6 +383,7 @@ public class ConfigureMapMenu { .setSelected(settings.SHOW_POI_LABEL.get()) .setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setIcon(R.drawable.ic_action_text_dark) + .setItemDeleteAction(new ItemResetListener(Arrays.asList(settings.SHOW_POI_LABEL))) .setListener(l).createItem()); /* @@ -392,6 +422,7 @@ public class ConfigureMapMenu { .setSecondaryIcon(R.drawable.ic_action_additional_option) .setSelected(transportSelected) .setColor(transportSelected ? selectedProfileColorRes : ContextMenuItem.INVALID_ID) + .setItemDeleteAction(new ItemResetListener(new ArrayList(transportPrefs))) .setListener(new ContextMenuAdapter.OnRowItemClick() { ArrayAdapter adapter; boolean transportSelectedInner = transportSelected; @@ -557,6 +588,7 @@ public class ConfigureMapMenu { .setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setIcon(R.drawable.ic_plugin_wikipedia) .setSecondaryIcon(R.drawable.ic_action_additional_option) + .setItemDeleteAction(new ItemResetListener(Arrays.asList(settings.SHOW_WIKIPEDIA_POI))) .setListener(l).createItem()); selected = settings.SHOW_MAP_MARKERS.get(); @@ -566,6 +598,7 @@ public class ConfigureMapMenu { .setSelected(selected) .setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setIcon(R.drawable.ic_action_flag_dark) + .setItemDeleteAction(new ItemResetListener(Arrays.asList(settings.SHOW_MAP_MARKERS))) .setListener(l).createItem()); adapter.addItem(new ContextMenuItem.ItemBuilder() @@ -573,6 +606,7 @@ public class ConfigureMapMenu { .setTitleId(R.string.layer_map, activity) .setIcon(R.drawable.ic_world_globe_dark) .setDescription(settings.MAP_ONLINE_DATA.get() ? settings.MAP_TILE_SOURCES.get() : null) + .setItemDeleteAction(new ItemResetListener(Arrays.asList(settings.MAP_ONLINE_DATA, settings.MAP_TILE_SOURCES))) .setListener(l).createItem()); OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity); @@ -615,7 +649,9 @@ public class ConfigureMapMenu { SelectMapStyleBottomSheetDialogFragment.TAG); return false; } - }).createItem()); + }) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(settings.RENDERER))) + .createItem()); String description = ""; SunriseSunset sunriseSunset = activity.getMyApplication().getDaynightHelper().getSunriseSunset(); @@ -670,7 +706,9 @@ public class ConfigureMapMenu { dialogAdapter.setDialog(bld.show()); return false; } - }).createItem()); + }) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(settings.DAYNIGHT_MODE))) + .createItem()); adapter.addItem(new ContextMenuItem.ItemBuilder() .setId(MAP_MAGNIFIER_ID) @@ -734,7 +772,9 @@ public class ConfigureMapMenu { dialogAdapter.setDialog(bld.show()); return false; } - }).createItem()); + }) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(settings.MAP_DENSITY))) + .createItem()); ContextMenuItem props; props = createRenderingProperty(customRules, adapter, activity, R.drawable.ic_action_intersection, ROAD_STYLE_ATTR, ROAD_STYLE_ID, app, selectedProfileColor, nightMode, themeRes); @@ -778,7 +818,9 @@ public class ConfigureMapMenu { dialogAdapter.setDialog(b.show()); return false; } - }).createItem()); + }) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(settings.TEXT_SCALE))) + .createItem()); String localeDescr = activity.getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get(); localeDescr = localeDescr == null || localeDescr.equals("") ? activity.getString(R.string.local_map_names) @@ -876,7 +918,9 @@ public class ConfigureMapMenu { b.show(); return false; } - }).createItem()); + }) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(settings.MAP_PREFERRED_LOCALE))) + .createItem()); props = createProperties(customRules, null, R.string.rendering_category_transport, R.drawable.ic_action_transport_bus, "transport", null, adapter, activity, true, TRANSPORT_RENDERING_ID, themeRes, nightMode, selectedProfileColor); @@ -1063,6 +1107,7 @@ public class ConfigureMapMenu { builder.setSecondaryIcon(R.drawable.ic_action_additional_option); builder.setSelected(selected); } + builder.setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(new ArrayList(prefs))); return builder.createItem(); // createCustomRenderingProperties(adapter, activity, ps); } @@ -1399,6 +1444,7 @@ public class ConfigureMapMenu { } }) .setDescription(descr) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(pref))) .setLayout(R.layout.list_item_single_line_descrition_narrow); if (icon != 0) { builder.setIcon(icon); diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java index 60fd23c047..2796379235 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java @@ -31,6 +31,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.dashboard.DashboardOnMap; +import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.OsmandMapTileView; @@ -39,6 +40,7 @@ import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.util.Algorithms; import java.text.MessageFormat; +import java.util.Arrays; import java.util.List; import static android.content.Intent.ACTION_VIEW; @@ -185,6 +187,7 @@ public class MapillaryPlugin extends OsmandPlugin { .setColor(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setIcon(R.drawable.ic_action_mapillary) .setSecondaryIcon(R.drawable.ic_action_additional_option) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(settings.SHOW_MAPILLARY))) .setListener(listener) .createItem()); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 7a0f79e1c2..8e4014706c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -38,6 +38,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TabActivity; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.dashboard.tools.DashFragmentData; +import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.myplaces.AvailableGPXFragment; import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo; import net.osmand.plus.myplaces.FavoritesActivity; @@ -50,6 +51,7 @@ import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_CREATE_POI; @@ -364,6 +366,7 @@ public class OsmEditingPlugin extends OsmandPlugin { return true; } }) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(settings.SHOW_OSM_BUGS))) .createItem()); adapter.addItem(new ContextMenuItem.ItemBuilder() @@ -385,6 +388,7 @@ public class OsmEditingPlugin extends OsmandPlugin { return true; } }) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(settings.SHOW_OSM_EDITS))) .createItem()); } diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index 3172bf0416..223159d990 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -45,6 +45,7 @@ import net.osmand.plus.activities.DownloadTilesDialog; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; +import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.dialogs.RasterMapMenu; import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.views.MapTileLayer; @@ -53,6 +54,7 @@ import net.osmand.util.Algorithms; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -358,6 +360,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { .setIcon(R.drawable.ic_layer_top) .setSecondaryIcon(R.drawable.ic_action_additional_option) .setListener(listener) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(settings.MAP_OVERLAY, settings.MAP_OVERLAY_PREVIOUS, settings.MAP_OVERLAY_TRANSPARENCY))) .createItem()); String underlayMapDescr = settings.MAP_UNDERLAY.get(); if (underlayMapDescr!=null && underlayMapDescr.contains(".sqlitedb")) { @@ -373,6 +376,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { .setIcon(R.drawable.ic_layer_bottom) .setSecondaryIcon(R.drawable.ic_action_additional_option) .setListener(listener) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(settings.MAP_UNDERLAY, settings.MAP_UNDERLAY_PREVIOUS))) .createItem()); } diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java index c29b0e2f3e..c3d96d2e94 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java @@ -51,7 +51,33 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.CONTOUR_LINES; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.DETAILS_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.FAVORITES_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.GPX_FILES_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.HIDE_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAPILLARY; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MORE_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_LANGUAGE_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_MAGNIFIER_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_MARKERS_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_MODE_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_SOURCE_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_STYLE_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.OSM_EDITS; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.OSM_NOTES; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.OVERLAY_MAP; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.POI_OVERLAY_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.POI_OVERLAY_LABELS_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.RECORDING_LAYER; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.ROAD_STYLE_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.ROUTES_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.TERRAIN; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.TEXT_SIZE_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.TRANSPORT_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.TRANSPORT_RENDERING_ID; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.UNDERLAY_MAP; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID; import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.BUTTON; import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DESCRIPTION; import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DIVIDER; @@ -239,7 +265,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment } } FragmentManager fm = getFragmentManager(); - OsmandSettings.ContextMenuItemsSettings prefToSave; + final OsmandSettings.ContextMenuItemsSettings prefToSave; if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) { prefToSave = new OsmandSettings.MapContextMenuItemsSettings(mainActionItems, hiddenMenuItems, ids); } else { @@ -254,8 +280,12 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment appMode, new ChangeGeneralProfilesPrefBottomSheet.OnChangeSettingListener() { @Override - public void onApplied() { - dismissFragment(); + public void onApplied(boolean profileOnly) { + if (screenType == ScreenType.CONFIGURE_MAP && !hiddenMenuItems.isEmpty()) { + showResetConfigureMapItemsDialog(profileOnly); + } else { + dismissFragment(); + } } @Override @@ -397,7 +427,9 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment items.addAll(visible); } if (!hiddenItems.isEmpty()) { - items.add(new RearrangeMenuAdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.shared_string_hidden, R.string.hidden_items_descr))); + items.add(new RearrangeMenuAdapterItem(HEADER, + new RearrangeMenuItemsAdapter.HeaderItem(R.string.shared_string_hidden, + screenType == ScreenType.CONFIGURE_MAP ? R.string.reset_items_descr : R.string.hidden_items_descr))); items.addAll(hiddenItems); } items.add(new RearrangeMenuAdapterItem(DIVIDER, 1)); @@ -478,6 +510,27 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment dismissDialog.show(); } + public void showResetConfigureMapItemsDialog(final boolean profileOnly) { + Context themedContext = UiUtilities.getThemedContext(getActivity(), nightMode); + final AlertDialog.Builder dismissDialog = new AlertDialog.Builder(themedContext); + dismissDialog.setTitle(getString(R.string.shared_string_reset)); + dismissDialog.setMessage(getString(R.string.reset_hidden_items)); + dismissDialog.setNegativeButton(R.string.shared_string_cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + dismissFragment(); + } + }); + dismissDialog.setPositiveButton(R.string.shared_string_reset, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + resetHiddenItems(profileOnly); + dismissFragment(); + } + }); + dismissDialog.show(); + } + private void dismissFragment() { FragmentManager fm = getFragmentManager(); if (fm != null && !fm.isStateSaved()) { @@ -548,4 +601,14 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment } }); } + + private void resetHiddenItems(boolean profileOnly) { + for (ContextMenuItem item : contextMenuAdapter.getItems()) { + if (hiddenMenuItems.contains(item.getId())) { + if (item.getItemDeleteAction() != null) { + item.getItemDeleteAction().itemWasDeleted(appMode, profileOnly); + } + } + } + } } diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java index 5e50dd5820..7efd6c3d6d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java @@ -69,7 +69,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh app.getSettings().setPreferenceForAllModes(prefId, newValue); updateTargetSettings(false, true); if (listener != null) { - listener.onApplied(); + listener.onApplied(false); } dismiss(); } @@ -89,7 +89,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh app.getSettings().setPreference(prefId, newValue, getAppMode()); updateTargetSettings(false, false); if (listener != null) { - listener.onApplied(); + listener.onApplied(true); } dismiss(); } @@ -195,7 +195,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh } public interface OnChangeSettingListener { - void onApplied(); + void onApplied(boolean profileOnly); void onDiscard(); } diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java index 4c0cdf30db..9321aa5c61 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java @@ -27,6 +27,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.dashboard.DashboardOnMap; +import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadResources; @@ -347,6 +348,7 @@ public class SRTMPlugin extends OsmandPlugin { .setIcon(R.drawable.ic_plugin_srtm) .setDescription(app.getString(R.string.display_zoom_level, descr)) .setColor(contourLinesSelected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(settings.CONTOUR_LINES_ZOOM))) .setSecondaryIcon(R.drawable.ic_action_additional_option) .setListener(listener).createItem()); } @@ -362,6 +364,7 @@ public class SRTMPlugin extends OsmandPlugin { .setColor(terrainEnabled ? R.color.osmand_orange : ContextMenuItem.INVALID_ID) .setIcon(R.drawable.ic_action_hillshade_dark) .setSecondaryIcon(R.drawable.ic_action_additional_option) + .setItemDeleteAction(new ConfigureMapMenu.ItemResetListener(Arrays.asList(settings.TERRAIN, settings.TERRAIN_MODE))) .setListener(listener) .createItem() );