sort items on add

This commit is contained in:
veliymolfar 2020-04-13 15:39:34 +03:00
parent 52fdde1dc6
commit b6938eafb9
24 changed files with 97 additions and 81 deletions

View file

@ -69,9 +69,17 @@ public class ContextMenuAdapter {
@LayoutRes @LayoutRes
private int DEFAULT_LAYOUT_ID = R.layout.list_menu_item_native; private int DEFAULT_LAYOUT_ID = R.layout.list_menu_item_native;
List<ContextMenuItem> items = new ArrayList<>(); List<ContextMenuItem> items = new ArrayList<>();
List<ContextMenuItem> hiddenItems = new ArrayList<>();
private boolean profileDependent = false; private boolean profileDependent = false;
private boolean nightMode; private boolean nightMode;
private ConfigureMapMenu.OnClickListener changeAppModeListener = null; private ConfigureMapMenu.OnClickListener changeAppModeListener = null;
private OsmandApplication app;
private HashMap<String, Integer> ordersMap;
private ContextMenuItemsPreference contextMenuItemsPreference;
public ContextMenuAdapter(OsmandApplication app) {
this.app = app;
}
public int length() { public int length() {
return items.size(); return items.size();
@ -87,12 +95,17 @@ public class ContextMenuAdapter {
public void addItem(ContextMenuItem item) { public void addItem(ContextMenuItem item) {
try { try {
String id = item.getId();
if (id != null) {
if (!item.isHidden()){ item.setHidden(isItemHidden(id));
item.setOrder(getItemCustomOrder(id, item.getOrder()));
}
if (item.isHidden()) {
hiddenItems.add(item);
} else {
items.add(item.getPos(), item); items.add(item.getPos(), item);
} }
sortItemsByOrder();
} catch (IndexOutOfBoundsException ex) { } catch (IndexOutOfBoundsException ex) {
items.add(item); items.add(item);
} }
@ -152,42 +165,42 @@ public class ContextMenuAdapter {
}); });
} }
public void sortItemsByCustomOrder(OsmandApplication app) { private boolean isItemHidden(@NonNull String id) {
ContextMenuItemsPreference pref = getPreference(app); if (contextMenuItemsPreference == null) {
if (pref == null) { contextMenuItemsPreference = getPreference(id);
sortItemsByOrder(); if (contextMenuItemsPreference == null) {
return; return false;
}
List<String> hiddenIds = pref.getHiddenIds();
List<String> orderIds = pref.getOrderIds();
if (!Algorithms.isEmpty(orderIds)) {
HashMap<String, Integer> ordersMap = new HashMap<>();
for (int i = 0; i < orderIds.size(); i++) {
ordersMap.put(orderIds.get(i), i);
} }
for (ContextMenuItem item : items) {
Integer order = ordersMap.get(item.getId());
if (order != null) {
item.setOrder(order);
}
}
sortItemsByOrder();
} }
List<String> hiddenIds = contextMenuItemsPreference.getHiddenIds();
if (!Algorithms.isEmpty(hiddenIds)) { if (!Algorithms.isEmpty(hiddenIds)) {
List<ContextMenuItem> filtered = new ArrayList<>(); return hiddenIds.contains(id);
for (ContextMenuItem item : items) {
if (!hiddenIds.contains(item.getId())) {
filtered.add(item);
}
}
items = filtered;
} }
return false;
} }
private int getItemCustomOrder(@NonNull String id, int defaultOrder) {
if (contextMenuItemsPreference == null) {
contextMenuItemsPreference = getPreference(id);
if (contextMenuItemsPreference == null) {
return defaultOrder;
}
}
List<String> 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<ContextMenuItem> createListAdapter(final Activity activity, final boolean lightTheme) { public ArrayAdapter<ContextMenuItem> createListAdapter(final Activity activity, final boolean lightTheme) {
final int layoutId = DEFAULT_LAYOUT_ID; final int layoutId = DEFAULT_LAYOUT_ID;
@ -606,6 +619,10 @@ public class ContextMenuAdapter {
return items; return items;
} }
public List<ContextMenuItem> getHiddenItems() {
return hiddenItems;
}
private String getIdScheme() { private String getIdScheme() {
String idScheme = ""; String idScheme = "";
for (ContextMenuItem item : items) { for (ContextMenuItem item : items) {
@ -626,17 +643,14 @@ public class ContextMenuAdapter {
return idScheme; return idScheme;
} }
private ContextMenuItemsPreference getPreference(OsmandApplication app) { private ContextMenuItemsPreference getPreference(@NonNull String id) {
for (ContextMenuItem item : items) { if (app != null) {
String id = item.getId(); if (id.startsWith(DRAWER_ITEM_ID_SCHEME)) {
if (id != null) { return app.getSettings().DRAWER_ITEMS;
if (id.startsWith(DRAWER_ITEM_ID_SCHEME)) { } else if (id.startsWith(CONFIGURE_MAP_ITEM_ID_SCHEME)) {
return app.getSettings().DRAWER_ITEMS; return app.getSettings().CONFIGURE_MAP_ITEMS;
} else if (id.startsWith(CONFIGURE_MAP_ITEM_ID_SCHEME)) { } else if (id.startsWith(MAP_CONTEXT_MENU_ACTIONS)) {
return app.getSettings().CONFIGURE_MAP_ITEMS; return app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS;
} else if (id.startsWith(MAP_CONTEXT_MENU_ACTIONS)) {
return app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS;
}
} }
} }
return null; return null;

View file

@ -42,7 +42,7 @@ public class HelpActivity extends OsmandActionBarActivity implements AdapterView
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_help_screen); 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); contextMenuAdapter.setDefaultLayoutId(R.layout.two_line_with_images_list_item);
createBeginWithOsmandItems(contextMenuAdapter); createBeginWithOsmandItems(contextMenuAdapter);

View file

@ -437,7 +437,7 @@ public class MapActivityActions implements DialogProvider {
} }
public void contextMenuPoint(final double latitude, final double longitude, final ContextMenuAdapter iadapter, Object selectedObj) { 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); addActionsToAdapter(latitude, longitude, adapter, selectedObj, false);
showAdditionalActionsFragment(adapter, getContextMenuItemClickListener(latitude, longitude, adapter)); showAdditionalActionsFragment(adapter, getContextMenuItemClickListener(latitude, longitude, adapter));
} }
@ -705,7 +705,7 @@ public class MapActivityActions implements DialogProvider {
public ContextMenuAdapter createMainOptionsMenu() { public ContextMenuAdapter createMainOptionsMenu() {
final OsmandMapTileView mapView = mapActivity.getMapView(); final OsmandMapTileView mapView = mapActivity.getMapView();
final OsmandApplication app = mapActivity.getMyApplication(); final OsmandApplication app = mapActivity.getMyApplication();
ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(); ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app);
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
if (drawerMode == DRAWER_MODE_SWITCH_PROFILE) { if (drawerMode == DRAWER_MODE_SWITCH_PROFILE) {
@ -1182,7 +1182,6 @@ public class MapActivityActions implements DialogProvider {
} }
menuItemsListView.setDivider(null); menuItemsListView.setDivider(null);
final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu(); final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu();
contextMenuAdapter.sortItemsByCustomOrder(getMyApplication());
contextMenuAdapter.setDefaultLayoutId(R.layout.simple_list_menu_item); contextMenuAdapter.setDefaultLayoutId(R.layout.simple_list_menu_item);
final ArrayAdapter<ContextMenuItem> simpleListAdapter = contextMenuAdapter.createListAdapter(mapActivity, final ArrayAdapter<ContextMenuItem> simpleListAdapter = contextMenuAdapter.createListAdapter(mapActivity,
!nightMode); !nightMode);

View file

@ -270,7 +270,7 @@ public class MapActivityLayers {
public void showMultichoicePoiFilterDialog(final OsmandMapTileView mapView, final DismissListener listener) { public void showMultichoicePoiFilterDialog(final OsmandMapTileView mapView, final DismissListener listener) {
final OsmandApplication app = getApplication(); final OsmandApplication app = getApplication();
final PoiFiltersHelper poiFilters = app.getPoiFilters(); final PoiFiltersHelper poiFilters = app.getPoiFilters();
final ContextMenuAdapter adapter = new ContextMenuAdapter(); final ContextMenuAdapter adapter = new ContextMenuAdapter(app);
final List<PoiUIFilter> list = new ArrayList<>(); final List<PoiUIFilter> list = new ArrayList<>();
for (PoiUIFilter f : poiFilters.getSortedPoiFilters(true)) { for (PoiUIFilter f : poiFilters.getSortedPoiFilters(true)) {
addFilterToList(adapter, list, f, true); addFilterToList(adapter, list, f, true);
@ -344,7 +344,7 @@ public class MapActivityLayers {
public void showSingleChoicePoiFilterDialog(final OsmandMapTileView mapView, final DismissListener listener) { public void showSingleChoicePoiFilterDialog(final OsmandMapTileView mapView, final DismissListener listener) {
final OsmandApplication app = getApplication(); final OsmandApplication app = getApplication();
final PoiFiltersHelper poiFilters = app.getPoiFilters(); final PoiFiltersHelper poiFilters = app.getPoiFilters();
final ContextMenuAdapter adapter = new ContextMenuAdapter(); final ContextMenuAdapter adapter = new ContextMenuAdapter(app);
adapter.addItem(new ContextMenuItem.ItemBuilder() adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.shared_string_search, app) .setTitleId(R.string.shared_string_search, app)
.setIcon(R.drawable.ic_action_search_dark).createItem()); .setIcon(R.drawable.ic_action_search_dark).createItem());

View file

@ -475,7 +475,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
return true; return true;
} else if (preference == autoZoom) { } else if (preference == autoZoom) {
final ApplicationMode am = settings.getApplicationMode(); final ApplicationMode am = settings.getApplicationMode();
final ContextMenuAdapter adapter = new ContextMenuAdapter(); final ContextMenuAdapter adapter = new ContextMenuAdapter(getMyApplication());
int i = 0; int i = 0;
int selectedIndex = -1; int selectedIndex = -1;
adapter.addItem(ContextMenuItem.createBuilder(getString(R.string.auto_zoom_none)) adapter.addItem(ContextMenuItem.createBuilder(getString(R.string.auto_zoom_none))
@ -546,7 +546,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
return true; return true;
} else if (preference == reliefFactorRouting) { } else if (preference == reliefFactorRouting) {
final ApplicationMode am = settings.getApplicationMode(); final ApplicationMode am = settings.getApplicationMode();
final ContextMenuAdapter adapter = new ContextMenuAdapter(); final ContextMenuAdapter adapter = new ContextMenuAdapter(getMyApplication());
int i = 0; int i = 0;
int selectedIndex = -1; int selectedIndex = -1;
for (RoutingParameter p : reliefFactorParameters) { for (RoutingParameter p : reliefFactorParameters) {

View file

@ -702,7 +702,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, IRouteInfo
cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity); cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity);
} else if (visibleType == DashboardType.CONFIGURE_MAP) { } else if (visibleType == DashboardType.CONFIGURE_MAP) {
cm = new ConfigureMapMenu().createListAdapter(mapActivity); cm = new ConfigureMapMenu().createListAdapter(mapActivity);
cm.sortItemsByCustomOrder(getMyApplication());
} else if (visibleType == DashboardType.LIST_MENU) { } else if (visibleType == DashboardType.LIST_MENU) {
cm = mapActivity.getMapActions().createMainOptionsMenu(); cm = mapActivity.getMapActions().createMainOptionsMenu();
} else if (visibleType == DashboardType.ROUTE_PREFERENCES) { } else if (visibleType == DashboardType.ROUTE_PREFERENCES) {

View file

@ -129,7 +129,7 @@ public class ConfigureMapMenu {
OsmandApplication app = ma.getMyApplication(); OsmandApplication app = ma.getMyApplication();
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; 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.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
adapter.addItem(new ContextMenuItem.ItemBuilder() adapter.addItem(new ContextMenuItem.ItemBuilder()
.setId(APP_PROFILES_ID) .setId(APP_PROFILES_ID)

View file

@ -24,7 +24,7 @@ public class RasterMapMenu {
public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity, public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity,
final RasterMapType type) { final RasterMapType type) {
boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); 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.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
adapter.setProfileDependent(true); adapter.setProfileDependent(true);
adapter.setNightMode(nightMode); adapter.setNightMode(nightMode);

View file

@ -164,7 +164,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
private void showContextMenu(final LocalIndexInfo info) { private void showContextMenu(final LocalIndexInfo info) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final ContextMenuAdapter adapter = new ContextMenuAdapter(); final ContextMenuAdapter adapter = new ContextMenuAdapter(getMyApplication());
basicFileOperation(info, adapter); basicFileOperation(info, adapter);
OsmandPlugin.onContextMenuActivity(getActivity(), null, info, adapter); OsmandPlugin.onContextMenuActivity(getActivity(), null, info, adapter);
@ -704,7 +704,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
//hide action bar from downloadindexfragment //hide action bar from downloadindexfragment
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); 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; 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() { ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter,

View file

@ -234,7 +234,7 @@ public class GpxUiHelper {
} }
allGpxList.add(0, new GPXInfo(activity.getString(R.string.show_current_gpx_title), 0, 0)); 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); 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)); 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 createDialog(activity, showCurrentGpx, multipleChoice, false, callbackWithObject, list, adapter, dialogThemeRes, nightMode);
} }
return null; 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 createSingleChoiceDialog(activity, showCurrentGpx, callbackWithObject, list, adapter);
} }
return null; return null;
} }
private static ContextMenuAdapter createGpxContextMenuAdapter(List<GPXInfo> allGpxList, private static ContextMenuAdapter createGpxContextMenuAdapter(List<GPXInfo> allGpxList,
List<String> selectedGpxList, List<String> selectedGpxList,
boolean showCurrentTrack) { boolean showCurrentTrack,
final ContextMenuAdapter adapter = new ContextMenuAdapter(); OsmandApplication app) {
final ContextMenuAdapter adapter = new ContextMenuAdapter(app);
//element position in adapter //element position in adapter
int i = 0; int i = 0;
for (GPXInfo gpxInfo : allGpxList) { for (GPXInfo gpxInfo : allGpxList) {

View file

@ -1064,7 +1064,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
public ContextMenuAdapter getActionsContextMenuAdapter(boolean all) { public ContextMenuAdapter getActionsContextMenuAdapter(boolean all) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(); final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(getMyApplication());
if (mapActivity != null) { if (mapActivity != null) {
LatLon latLon = getLatLon(); LatLon latLon = getLatLon();
for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) { for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) {

View file

@ -566,7 +566,6 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
// Action buttons // Action buttons
// TODO refactor section // TODO refactor section
ContextMenuAdapter adapter = menu.getActionsContextMenuAdapter(false); ContextMenuAdapter adapter = menu.getActionsContextMenuAdapter(false);
adapter.sortItemsByCustomOrder(requireMyApplication());
List<ContextMenuItem> items = adapter.getItems(); List<ContextMenuItem> items = adapter.getItems();
List<ContextMenuItem> main = new ArrayList<>(); List<ContextMenuItem> main = new ArrayList<>();
List<ContextMenuItem> additional = new ArrayList<>(); List<ContextMenuItem> additional = new ArrayList<>();
@ -582,10 +581,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
1f 1f
); );
buttons.removeAllViews(); buttons.removeAllViews();
ContextMenuAdapter mainAdapter = new ContextMenuAdapter(); ContextMenuAdapter mainAdapter = new ContextMenuAdapter(requireMyApplication());
mainAdapter.updateItems(main); mainAdapter.updateItems(main);
ContextMenuItemClickListener mainListener = menu.getContextMenuItemClickListener(mainAdapter); ContextMenuItemClickListener mainListener = menu.getContextMenuItemClickListener(mainAdapter);
ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(); ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(requireMyApplication());
additionalAdapter.updateItems(additional); additionalAdapter.updateItems(additional);
ContextMenuItemClickListener additionalListener = menu.getContextMenuItemClickListener(additionalAdapter); ContextMenuItemClickListener additionalListener = menu.getContextMenuItemClickListener(additionalAdapter);

View file

@ -84,7 +84,7 @@ public class RoutePreferencesMenu {
Object obj = listAdapter.getItem(item); Object obj = listAdapter.getItem(item);
if (obj instanceof LocalRoutingParameterGroup) { if (obj instanceof LocalRoutingParameterGroup) {
final LocalRoutingParameterGroup group = (LocalRoutingParameterGroup) obj; final LocalRoutingParameterGroup group = (LocalRoutingParameterGroup) obj;
final ContextMenuAdapter adapter = new ContextMenuAdapter(); final ContextMenuAdapter adapter = new ContextMenuAdapter(app);
int i = 0; int i = 0;
int selectedIndex = -1; int selectedIndex = -1;
for (LocalRoutingParameter p : group.getRoutingParameters()) { for (LocalRoutingParameter p : group.getRoutingParameters()) {

View file

@ -475,7 +475,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
((FavoritesActivity) getActivity()).updateListViewFooter(footerView); ((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
// TODO Rewrite without ContextMenuAdapter // TODO Rewrite without ContextMenuAdapter
optionsMenuAdapter = new ContextMenuAdapter(); optionsMenuAdapter = new ContextMenuAdapter(app);
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() { ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, final int itemId, int pos, boolean isChecked, int[] viewCoordinates) { public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> 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) { private void moveGpx(final GpxInfo info) {
final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(); final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(app);
ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder(); ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder();
final List<File> dirs = new ArrayList<>(); final List<File> dirs = new ArrayList<>();

View file

@ -26,7 +26,7 @@ public class OsmNotesMenu {
private static Integer[] zoomIntValues = {8, 9, 10, 11, 12, 13, 14, 15, 16}; private static Integer[] zoomIntValues = {8, 9, 10, 11, 12, 13, 14, 15, 16};
public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity) { public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity) {
ContextMenuAdapter adapter = new ContextMenuAdapter(); ContextMenuAdapter adapter = new ContextMenuAdapter(mapActivity.getMyApplication());
boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu); adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
adapter.setProfileDependent(true); adapter.setProfileDependent(true);

View file

@ -288,7 +288,7 @@ public class ShowHidePoiAction extends QuickAction {
private void showSingleChoicePoiFilterDialog(final OsmandApplication app, final MapActivity activity, final Adapter filtersAdapter) { private void showSingleChoicePoiFilterDialog(final OsmandApplication app, final MapActivity activity, final Adapter filtersAdapter) {
final PoiFiltersHelper poiFilters = app.getPoiFilters(); final PoiFiltersHelper poiFilters = app.getPoiFilters();
final ContextMenuAdapter adapter = new ContextMenuAdapter(); final ContextMenuAdapter adapter = new ContextMenuAdapter(app);
final List<PoiUIFilter> list = new ArrayList<>(); final List<PoiUIFilter> list = new ArrayList<>();

View file

@ -113,7 +113,7 @@ public class RoutingOptionsHelper {
} }
public void selectVoiceGuidance(final MapActivity mapActivity, final CallbackWithObject<String> callback, ApplicationMode applicationMode) { public void selectVoiceGuidance(final MapActivity mapActivity, final CallbackWithObject<String> callback, ApplicationMode applicationMode) {
final ContextMenuAdapter adapter = new ContextMenuAdapter(); final ContextMenuAdapter adapter = new ContextMenuAdapter(app);
String[] entries; String[] entries;
final String[] entrieValues; final String[] entrieValues;
@ -310,7 +310,7 @@ public class RoutingOptionsHelper {
public void showLocalRoutingParameterGroupDialog(final LocalRoutingParameterGroup group, final MapActivity mapActivity, final OnClickListener listener) { public void showLocalRoutingParameterGroupDialog(final LocalRoutingParameterGroup group, final MapActivity mapActivity, final OnClickListener listener) {
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
final ContextMenuAdapter adapter = new ContextMenuAdapter(); final ContextMenuAdapter adapter = new ContextMenuAdapter(app);
int i = 0; int i = 0;
int selectedIndex = -1; int selectedIndex = -1;
for (LocalRoutingParameter p : group.getRoutingParameters()) { for (LocalRoutingParameter p : group.getRoutingParameters()) {

View file

@ -261,6 +261,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
@Override @Override
public void onClick(View v) { public void onClick(View v) {
List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems(); List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems();
defItems.addAll(contextMenuAdapter.getHiddenItems());
sortByCustomOrder(defItems, menuItemsOrder); sortByCustomOrder(defItems, menuItemsOrder);
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
for (ContextMenuItem item : defItems) { for (ContextMenuItem item : defItems) {
@ -435,6 +436,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
public List<AdapterItem> getItemsForRearrangeAdapter(@Nullable List<String> hiddenItemsIds, @Nullable HashMap<String, Integer> itemsOrderIds, boolean hidden) { public List<AdapterItem> getItemsForRearrangeAdapter(@Nullable List<String> hiddenItemsIds, @Nullable HashMap<String, Integer> itemsOrderIds, boolean hidden) {
List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems(); List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems();
defItems.addAll(contextMenuAdapter.getHiddenItems());
if (itemsOrderIds == null || itemsOrderIds.isEmpty()) { if (itemsOrderIds == null || itemsOrderIds.isEmpty()) {
initDefaultOrders(defItems); initDefaultOrders(defItems);
} else { } else {

View file

@ -264,8 +264,8 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
contextMenuAdapter = menu.getActionsContextMenuAdapter(true); contextMenuAdapter = menu.getActionsContextMenuAdapter(true);
break; break;
} }
int hiddenCount = ConfigureMenuItemsFragment.getSettingForScreen(app, type).getHiddenIds().size(); int hiddenCount = contextMenuAdapter.getHiddenItems().size();
int allCount = contextMenuAdapter.getDefaultItems().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)); 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); return getString(R.string.ltr_or_rtl_combine_via_colon, getString(R.string.shared_string_items), amount);
} }

View file

@ -66,6 +66,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
app.getSettings().setPreferenceForAllModes(prefId, newValue);
updateTargetSettings(false, true); updateTargetSettings(false, true);
if (listener != null) { if (listener != null) {
listener.onApplied(); listener.onApplied();
@ -85,6 +86,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
app.getSettings().setPreference(prefId, newValue, getAppMode());
updateTargetSettings(false, false); updateTargetSettings(false, false);
if (listener != null) { if (listener != null) {
listener.onApplied(); listener.onApplied();

View file

@ -38,7 +38,7 @@ public class ContourLinesMenu {
OsmandPlugin.enablePlugin(mapActivity, mapActivity.getMyApplication(), plugin, true); OsmandPlugin.enablePlugin(mapActivity, mapActivity.getMyApplication(), plugin, true);
} }
boolean nightMode = isNightMode(mapActivity.getMyApplication()); 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.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
adapter.setProfileDependent(true); adapter.setProfileDependent(true);
adapter.setNightMode(nightMode); adapter.setNightMode(nightMode);

View file

@ -404,7 +404,7 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
} }
private void updateDownloadSection() { private void updateDownloadSection() {
final ContextMenuAdapter adapter = new ContextMenuAdapter(); final ContextMenuAdapter adapter = new ContextMenuAdapter(app);
adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu); adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
adapter.setProfileDependent(true); adapter.setProfileDependent(true);
adapter.setNightMode(nightMode); adapter.setNightMode(nightMode);

View file

@ -798,7 +798,7 @@ public class MapWidgetRegistry {
} }
public ContextMenuAdapter getViewConfigureMenuAdapter(final MapActivity map) { public ContextMenuAdapter getViewConfigureMenuAdapter(final MapActivity map) {
final ContextMenuAdapter cm = new ContextMenuAdapter(); final ContextMenuAdapter cm = new ContextMenuAdapter(app);
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
cm.setProfileDependent(true); cm.setProfileDependent(true);
cm.setNightMode(nightMode); cm.setNightMode(nightMode);

View file

@ -54,7 +54,7 @@ public class WikipediaPoiMenu {
final int languageActionStringId = R.string.shared_string_language; final int languageActionStringId = R.string.shared_string_language;
final int spaceHeight = app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_big_item_height); final int spaceHeight = app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_big_item_height);
final boolean enabled = app.getPoiFilters().isShowingAnyPoi(PoiTemplateList.WIKI); 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.setDefaultLayoutId(R.layout.dash_item_with_description_72dp);
adapter.setProfileDependent(true); adapter.setProfileDependent(true);
adapter.setNightMode(nightMode); adapter.setNightMode(nightMode);