diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index 77db91a312..e6ba0a0b54 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -69,9 +69,17 @@ public class ContextMenuAdapter { @LayoutRes private int DEFAULT_LAYOUT_ID = R.layout.list_menu_item_native; List items = new ArrayList<>(); + List hiddenItems = new ArrayList<>(); private boolean profileDependent = false; private boolean nightMode; private ConfigureMapMenu.OnClickListener changeAppModeListener = null; + private OsmandApplication app; + private HashMap ordersMap; + private ContextMenuItemsPreference contextMenuItemsPreference; + + public ContextMenuAdapter(OsmandApplication app) { + this.app = app; + } public int length() { return items.size(); @@ -87,12 +95,17 @@ public class ContextMenuAdapter { public void addItem(ContextMenuItem item) { try { - - - if (!item.isHidden()){ + String id = item.getId(); + if (id != null) { + item.setHidden(isItemHidden(id)); + item.setOrder(getItemCustomOrder(id, item.getOrder())); + } + if (item.isHidden()) { + hiddenItems.add(item); + } else { items.add(item.getPos(), item); } - + sortItemsByOrder(); } catch (IndexOutOfBoundsException ex) { items.add(item); } @@ -152,42 +165,42 @@ public class ContextMenuAdapter { }); } - public void sortItemsByCustomOrder(OsmandApplication app) { - ContextMenuItemsPreference pref = getPreference(app); - if (pref == null) { - sortItemsByOrder(); - return; - } - - List hiddenIds = pref.getHiddenIds(); - List orderIds = pref.getOrderIds(); - - if (!Algorithms.isEmpty(orderIds)) { - HashMap ordersMap = new HashMap<>(); - for (int i = 0; i < orderIds.size(); i++) { - ordersMap.put(orderIds.get(i), i); + private boolean isItemHidden(@NonNull String id) { + if (contextMenuItemsPreference == null) { + contextMenuItemsPreference = getPreference(id); + if (contextMenuItemsPreference == null) { + return false; } - - for (ContextMenuItem item : items) { - Integer order = ordersMap.get(item.getId()); - if (order != null) { - item.setOrder(order); - } - } - sortItemsByOrder(); } - + List hiddenIds = contextMenuItemsPreference.getHiddenIds(); if (!Algorithms.isEmpty(hiddenIds)) { - List filtered = new ArrayList<>(); - for (ContextMenuItem item : items) { - if (!hiddenIds.contains(item.getId())) { - filtered.add(item); - } - } - items = filtered; + return hiddenIds.contains(id); } + return false; } + private int getItemCustomOrder(@NonNull String id, int defaultOrder) { + if (contextMenuItemsPreference == null) { + contextMenuItemsPreference = getPreference(id); + if (contextMenuItemsPreference == null) { + return defaultOrder; + } + } + List orderIds = contextMenuItemsPreference.getOrderIds(); + if (!Algorithms.isEmpty(orderIds)) { + if (ordersMap == null) { + ordersMap = new HashMap<>(); + for (int i = 0; i < orderIds.size(); i++) { + ordersMap.put(orderIds.get(i), i); + } + } + Integer order = ordersMap.get(id); + if (order != null) { + return order; + } + } + return defaultOrder; + } public ArrayAdapter createListAdapter(final Activity activity, final boolean lightTheme) { final int layoutId = DEFAULT_LAYOUT_ID; @@ -606,6 +619,10 @@ public class ContextMenuAdapter { return items; } + public List getHiddenItems() { + return hiddenItems; + } + private String getIdScheme() { String idScheme = ""; for (ContextMenuItem item : items) { @@ -626,17 +643,14 @@ public class ContextMenuAdapter { return idScheme; } - private ContextMenuItemsPreference getPreference(OsmandApplication app) { - for (ContextMenuItem item : items) { - String id = item.getId(); - if (id != null) { - if (id.startsWith(DRAWER_ITEM_ID_SCHEME)) { - return app.getSettings().DRAWER_ITEMS; - } else if (id.startsWith(CONFIGURE_MAP_ITEM_ID_SCHEME)) { - return app.getSettings().CONFIGURE_MAP_ITEMS; - } else if (id.startsWith(MAP_CONTEXT_MENU_ACTIONS)) { - return app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS; - } + private ContextMenuItemsPreference getPreference(@NonNull String id) { + if (app != null) { + if (id.startsWith(DRAWER_ITEM_ID_SCHEME)) { + return app.getSettings().DRAWER_ITEMS; + } else if (id.startsWith(CONFIGURE_MAP_ITEM_ID_SCHEME)) { + return app.getSettings().CONFIGURE_MAP_ITEMS; + } else if (id.startsWith(MAP_CONTEXT_MENU_ACTIONS)) { + return app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS; } } return null; diff --git a/OsmAnd/src/net/osmand/plus/activities/HelpActivity.java b/OsmAnd/src/net/osmand/plus/activities/HelpActivity.java index f16f9bc9f0..3a4cb98f91 100644 --- a/OsmAnd/src/net/osmand/plus/activities/HelpActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/HelpActivity.java @@ -42,7 +42,7 @@ public class HelpActivity extends OsmandActionBarActivity implements AdapterView super.onCreate(savedInstanceState); setContentView(R.layout.fragment_help_screen); - ContextMenuAdapter contextMenuAdapter = new ContextMenuAdapter(); + ContextMenuAdapter contextMenuAdapter = new ContextMenuAdapter(getMyApplication()); contextMenuAdapter.setDefaultLayoutId(R.layout.two_line_with_images_list_item); createBeginWithOsmandItems(contextMenuAdapter); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 8010fa90ba..3fb019b46e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -437,7 +437,7 @@ public class MapActivityActions implements DialogProvider { } public void contextMenuPoint(final double latitude, final double longitude, final ContextMenuAdapter iadapter, Object selectedObj) { - final ContextMenuAdapter adapter = iadapter == null ? new ContextMenuAdapter() : iadapter; + final ContextMenuAdapter adapter = iadapter == null ? new ContextMenuAdapter(getMyApplication()) : iadapter; addActionsToAdapter(latitude, longitude, adapter, selectedObj, false); showAdditionalActionsFragment(adapter, getContextMenuItemClickListener(latitude, longitude, adapter)); } @@ -705,7 +705,7 @@ public class MapActivityActions implements DialogProvider { public ContextMenuAdapter createMainOptionsMenu() { final OsmandMapTileView mapView = mapActivity.getMapView(); final OsmandApplication app = mapActivity.getMyApplication(); - ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(); + ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app); boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); if (drawerMode == DRAWER_MODE_SWITCH_PROFILE) { @@ -1182,7 +1182,6 @@ public class MapActivityActions implements DialogProvider { } menuItemsListView.setDivider(null); final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu(); - contextMenuAdapter.sortItemsByCustomOrder(getMyApplication()); contextMenuAdapter.setDefaultLayoutId(R.layout.simple_list_menu_item); final ArrayAdapter simpleListAdapter = contextMenuAdapter.createListAdapter(mapActivity, !nightMode); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index e516f997be..eef820706b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -270,7 +270,7 @@ public class MapActivityLayers { public void showMultichoicePoiFilterDialog(final OsmandMapTileView mapView, final DismissListener listener) { final OsmandApplication app = getApplication(); final PoiFiltersHelper poiFilters = app.getPoiFilters(); - final ContextMenuAdapter adapter = new ContextMenuAdapter(); + final ContextMenuAdapter adapter = new ContextMenuAdapter(app); final List list = new ArrayList<>(); for (PoiUIFilter f : poiFilters.getSortedPoiFilters(true)) { addFilterToList(adapter, list, f, true); @@ -344,7 +344,7 @@ public class MapActivityLayers { public void showSingleChoicePoiFilterDialog(final OsmandMapTileView mapView, final DismissListener listener) { final OsmandApplication app = getApplication(); final PoiFiltersHelper poiFilters = app.getPoiFilters(); - final ContextMenuAdapter adapter = new ContextMenuAdapter(); + final ContextMenuAdapter adapter = new ContextMenuAdapter(app); adapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.shared_string_search, app) .setIcon(R.drawable.ic_action_search_dark).createItem()); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index c7854100ba..f6a55a77a0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -475,7 +475,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { return true; } else if (preference == autoZoom) { final ApplicationMode am = settings.getApplicationMode(); - final ContextMenuAdapter adapter = new ContextMenuAdapter(); + final ContextMenuAdapter adapter = new ContextMenuAdapter(getMyApplication()); int i = 0; int selectedIndex = -1; adapter.addItem(ContextMenuItem.createBuilder(getString(R.string.auto_zoom_none)) @@ -546,7 +546,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { return true; } else if (preference == reliefFactorRouting) { final ApplicationMode am = settings.getApplicationMode(); - final ContextMenuAdapter adapter = new ContextMenuAdapter(); + final ContextMenuAdapter adapter = new ContextMenuAdapter(getMyApplication()); int i = 0; int selectedIndex = -1; for (RoutingParameter p : reliefFactorParameters) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index c5a9f729e4..243750ecd8 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -702,7 +702,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity); } else if (visibleType == DashboardType.CONFIGURE_MAP) { cm = new ConfigureMapMenu().createListAdapter(mapActivity); - cm.sortItemsByCustomOrder(getMyApplication()); } else if (visibleType == DashboardType.LIST_MENU) { cm = mapActivity.getMapActions().createMainOptionsMenu(); } else if (visibleType == DashboardType.ROUTE_PREFERENCES) { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index b5e4cfbcd5..c9ee6a331c 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -129,7 +129,7 @@ public class ConfigureMapMenu { OsmandApplication app = ma.getMyApplication(); boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - ContextMenuAdapter adapter = new ContextMenuAdapter(); + ContextMenuAdapter adapter = new ContextMenuAdapter(app); adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu); adapter.addItem(new ContextMenuItem.ItemBuilder() .setId(APP_PROFILES_ID) diff --git a/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java index 0f837c7565..70392ce7b3 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java @@ -24,7 +24,7 @@ public class RasterMapMenu { public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity, final RasterMapType type) { boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); - ContextMenuAdapter adapter = new ContextMenuAdapter(); + ContextMenuAdapter adapter = new ContextMenuAdapter(mapActivity.getMyApplication()); adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu); adapter.setProfileDependent(true); adapter.setNightMode(nightMode); diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index ddf99ce9ab..cffef21b6e 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -164,7 +164,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement private void showContextMenu(final LocalIndexInfo info) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - final ContextMenuAdapter adapter = new ContextMenuAdapter(); + final ContextMenuAdapter adapter = new ContextMenuAdapter(getMyApplication()); basicFileOperation(info, adapter); OsmandPlugin.onContextMenuActivity(getActivity(), null, info, adapter); @@ -704,7 +704,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement //hide action bar from downloadindexfragment actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); int iconColorResId = getMyApplication().getSettings().isLightContent() ? R.color.active_buttons_and_links_text_light : R.color.active_buttons_and_links_text_dark; - optionsMenuAdapter = new ContextMenuAdapter(); + optionsMenuAdapter = new ContextMenuAdapter(requireMyApplication()); ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index 917ee1abc8..fdba6f7a26 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -234,7 +234,7 @@ public class GpxUiHelper { } allGpxList.add(0, new GPXInfo(activity.getString(R.string.show_current_gpx_title), 0, 0)); - final ContextMenuAdapter adapter = createGpxContextMenuAdapter(allGpxList, selectedGpxList, true); + final ContextMenuAdapter adapter = createGpxContextMenuAdapter(allGpxList, selectedGpxList, true, app); return createDialog(activity, true, true, true, callbackWithObject, allGpxList, adapter, dialogThemeRes, nightMode); } @@ -253,7 +253,7 @@ public class GpxUiHelper { list.add(0, new GPXInfo(activity.getString(R.string.show_current_gpx_title), 0, 0)); } - final ContextMenuAdapter adapter = createGpxContextMenuAdapter(list, null, showCurrentGpx); + final ContextMenuAdapter adapter = createGpxContextMenuAdapter(list, null, showCurrentGpx, app); return createDialog(activity, showCurrentGpx, multipleChoice, false, callbackWithObject, list, adapter, dialogThemeRes, nightMode); } return null; @@ -280,16 +280,17 @@ public class GpxUiHelper { } } - final ContextMenuAdapter adapter = createGpxContextMenuAdapter(list, null, showCurrentGpx); + final ContextMenuAdapter adapter = createGpxContextMenuAdapter(list, null, showCurrentGpx, app); return createSingleChoiceDialog(activity, showCurrentGpx, callbackWithObject, list, adapter); } return null; } private static ContextMenuAdapter createGpxContextMenuAdapter(List allGpxList, - List selectedGpxList, - boolean showCurrentTrack) { - final ContextMenuAdapter adapter = new ContextMenuAdapter(); + List selectedGpxList, + boolean showCurrentTrack, + OsmandApplication app) { + final ContextMenuAdapter adapter = new ContextMenuAdapter(app); //element position in adapter int i = 0; for (GPXInfo gpxInfo : allGpxList) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index b10f57e593..4e3afe1412 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -1064,7 +1064,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL public ContextMenuAdapter getActionsContextMenuAdapter(boolean all) { MapActivity mapActivity = getMapActivity(); - final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(); + final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(getMyApplication()); if (mapActivity != null) { LatLon latLon = getLatLon(); for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index d79d728c9b..c3aa675fec 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -566,7 +566,6 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo // Action buttons // TODO refactor section ContextMenuAdapter adapter = menu.getActionsContextMenuAdapter(false); - adapter.sortItemsByCustomOrder(requireMyApplication()); List items = adapter.getItems(); List main = new ArrayList<>(); List additional = new ArrayList<>(); @@ -582,10 +581,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo 1f ); buttons.removeAllViews(); - ContextMenuAdapter mainAdapter = new ContextMenuAdapter(); + ContextMenuAdapter mainAdapter = new ContextMenuAdapter(requireMyApplication()); mainAdapter.updateItems(main); ContextMenuItemClickListener mainListener = menu.getContextMenuItemClickListener(mainAdapter); - ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(); + ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(requireMyApplication()); additionalAdapter.updateItems(additional); ContextMenuItemClickListener additionalListener = menu.getContextMenuItemClickListener(additionalAdapter); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java index ba5792988c..afab462022 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java @@ -84,7 +84,7 @@ public class RoutePreferencesMenu { Object obj = listAdapter.getItem(item); if (obj instanceof LocalRoutingParameterGroup) { final LocalRoutingParameterGroup group = (LocalRoutingParameterGroup) obj; - final ContextMenuAdapter adapter = new ContextMenuAdapter(); + final ContextMenuAdapter adapter = new ContextMenuAdapter(app); int i = 0; int selectedIndex = -1; for (LocalRoutingParameter p : group.getRoutingParameters()) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 96e759796f..9e98e66710 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -475,7 +475,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement ((FavoritesActivity) getActivity()).updateListViewFooter(footerView); // TODO Rewrite without ContextMenuAdapter - optionsMenuAdapter = new ContextMenuAdapter(); + optionsMenuAdapter = new ContextMenuAdapter(app); ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, final int itemId, int pos, boolean isChecked, int[] viewCoordinates) { @@ -760,7 +760,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement private void moveGpx(final GpxInfo info) { - final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(); + final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(app); ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder(); final List dirs = new ArrayList<>(); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmNotesMenu.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmNotesMenu.java index 3558a69c59..9ac5b4c3da 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmNotesMenu.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmNotesMenu.java @@ -26,7 +26,7 @@ public class OsmNotesMenu { private static Integer[] zoomIntValues = {8, 9, 10, 11, 12, 13, 14, 15, 16}; public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity) { - ContextMenuAdapter adapter = new ContextMenuAdapter(); + ContextMenuAdapter adapter = new ContextMenuAdapter(mapActivity.getMyApplication()); boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu); adapter.setProfileDependent(true); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java index 2052bbe020..44fd583074 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java @@ -288,7 +288,7 @@ public class ShowHidePoiAction extends QuickAction { private void showSingleChoicePoiFilterDialog(final OsmandApplication app, final MapActivity activity, final Adapter filtersAdapter) { final PoiFiltersHelper poiFilters = app.getPoiFilters(); - final ContextMenuAdapter adapter = new ContextMenuAdapter(); + final ContextMenuAdapter adapter = new ContextMenuAdapter(app); final List list = new ArrayList<>(); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java index 8b5c122638..57f4b56e4a 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java @@ -113,7 +113,7 @@ public class RoutingOptionsHelper { } public void selectVoiceGuidance(final MapActivity mapActivity, final CallbackWithObject callback, ApplicationMode applicationMode) { - final ContextMenuAdapter adapter = new ContextMenuAdapter(); + final ContextMenuAdapter adapter = new ContextMenuAdapter(app); String[] entries; final String[] entrieValues; @@ -310,7 +310,7 @@ public class RoutingOptionsHelper { public void showLocalRoutingParameterGroupDialog(final LocalRoutingParameterGroup group, final MapActivity mapActivity, final OnClickListener listener) { OsmandSettings settings = app.getSettings(); - final ContextMenuAdapter adapter = new ContextMenuAdapter(); + final ContextMenuAdapter adapter = new ContextMenuAdapter(app); int i = 0; int selectedIndex = -1; for (LocalRoutingParameter p : group.getRoutingParameters()) { diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java index 00d35f16ed..45fc3f25d2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuItemsFragment.java @@ -261,6 +261,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment @Override public void onClick(View v) { List defItems = contextMenuAdapter.getDefaultItems(); + defItems.addAll(contextMenuAdapter.getHiddenItems()); sortByCustomOrder(defItems, menuItemsOrder); List ids = new ArrayList<>(); for (ContextMenuItem item : defItems) { @@ -435,6 +436,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment public List getItemsForRearrangeAdapter(@Nullable List hiddenItemsIds, @Nullable HashMap itemsOrderIds, boolean hidden) { List defItems = contextMenuAdapter.getDefaultItems(); + defItems.addAll(contextMenuAdapter.getHiddenItems()); if (itemsOrderIds == null || itemsOrderIds.isEmpty()) { initDefaultOrders(defItems); } else { diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuRootFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuRootFragment.java index 5b8373f671..aeb799ae2e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuRootFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureMenuRootFragment.java @@ -264,8 +264,8 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment { contextMenuAdapter = menu.getActionsContextMenuAdapter(true); break; } - int hiddenCount = ConfigureMenuItemsFragment.getSettingForScreen(app, type).getHiddenIds().size(); - int allCount = contextMenuAdapter.getDefaultItems().size(); + int hiddenCount = contextMenuAdapter.getHiddenItems().size(); + int allCount = contextMenuAdapter.getDefaultItems().size() + contextMenuAdapter.getHiddenItems().size(); String amount = getString(R.string.n_items_of_z, String.valueOf(allCount - hiddenCount), String.valueOf(allCount)); return getString(R.string.ltr_or_rtl_combine_via_colon, getString(R.string.shared_string_items), amount); } diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java index cd8e45fd12..5e50dd5820 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java @@ -66,6 +66,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + app.getSettings().setPreferenceForAllModes(prefId, newValue); updateTargetSettings(false, true); if (listener != null) { listener.onApplied(); @@ -85,6 +86,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + app.getSettings().setPreference(prefId, newValue, getAppMode()); updateTargetSettings(false, false); if (listener != null) { listener.onApplied(); diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesMenu.java b/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesMenu.java index d8d0f39c1c..97d27e8526 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesMenu.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesMenu.java @@ -38,7 +38,7 @@ public class ContourLinesMenu { OsmandPlugin.enablePlugin(mapActivity, mapActivity.getMyApplication(), plugin, true); } boolean nightMode = isNightMode(mapActivity.getMyApplication()); - ContextMenuAdapter adapter = new ContextMenuAdapter(); + ContextMenuAdapter adapter = new ContextMenuAdapter(mapActivity.getMyApplication()); adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu); adapter.setProfileDependent(true); adapter.setNightMode(nightMode); diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java index 3b1403f320..f7113e6764 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainFragment.java @@ -404,7 +404,7 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL } private void updateDownloadSection() { - final ContextMenuAdapter adapter = new ContextMenuAdapter(); + final ContextMenuAdapter adapter = new ContextMenuAdapter(app); adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu); adapter.setProfileDependent(true); adapter.setNightMode(nightMode); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index 855c8e0b94..b1740e4307 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -798,7 +798,7 @@ public class MapWidgetRegistry { } public ContextMenuAdapter getViewConfigureMenuAdapter(final MapActivity map) { - final ContextMenuAdapter cm = new ContextMenuAdapter(); + final ContextMenuAdapter cm = new ContextMenuAdapter(app); boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); cm.setProfileDependent(true); cm.setNightMode(nightMode); diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java index ec7ca88d26..e8125018a5 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPoiMenu.java @@ -54,7 +54,7 @@ public class WikipediaPoiMenu { final int languageActionStringId = R.string.shared_string_language; final int spaceHeight = app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_big_item_height); final boolean enabled = app.getPoiFilters().isShowingAnyPoi(PoiTemplateList.WIKI); - ContextMenuAdapter adapter = new ContextMenuAdapter(); + ContextMenuAdapter adapter = new ContextMenuAdapter(app); adapter.setDefaultLayoutId(R.layout.dash_item_with_description_72dp); adapter.setProfileDependent(true); adapter.setNightMode(nightMode);