remove APP_PROFILES_ID check from ContextMenuAdapter

This commit is contained in:
veliymolfar 2020-05-05 17:37:59 +03:00
parent edbb876830
commit 8b10342d33
3 changed files with 18 additions and 34 deletions

View file

@ -163,7 +163,7 @@ public class ContextMenuAdapter {
if (!Algorithms.isEmpty(orderIds)) { if (!Algorithms.isEmpty(orderIds)) {
int index = orderIds.indexOf(id); int index = orderIds.indexOf(id);
if (index != -1) { if (index != -1) {
return index + ITEMS_ORDER_STEP; return index;
} }
} }
} }
@ -584,7 +584,7 @@ public class ContextMenuAdapter {
List<ContextMenuItem> items = new ArrayList<>(); List<ContextMenuItem> items = new ArrayList<>();
for (ContextMenuItem item : this.items) { for (ContextMenuItem item : this.items) {
String id = item.getId(); String id = item.getId();
if (id != null && (id.startsWith(idScheme) && !APP_PROFILES_ID.equals(id))) { if (id != null && (id.startsWith(idScheme))) {
items.add(item); items.add(item);
} }
} }

View file

@ -32,7 +32,6 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
@ -51,33 +50,8 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.CONTOUR_LINES; import static net.osmand.aidlapi.OsmAndCustomizationConstants.APP_PROFILES_ID;
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_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.BUTTON;
import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DESCRIPTION; import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DESCRIPTION;
import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DIVIDER; import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DIVIDER;
@ -184,7 +158,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
} }
private void initDefaultMainActions() { private void initDefaultMainActions() {
List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems(); List<ContextMenuItem> defItems = getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems());
OsmandSettings.ContextMenuItemsSettings pref = getSettingForScreen(app, screenType).getModeValue(appMode); OsmandSettings.ContextMenuItemsSettings pref = getSettingForScreen(app, screenType).getModeValue(appMode);
if (pref instanceof OsmandSettings.MapContextMenuItemsSettings) { if (pref instanceof OsmandSettings.MapContextMenuItemsSettings) {
mainActionItems = new ArrayList<>(((OsmandSettings.MapContextMenuItemsSettings) pref).getMainActionIds()); mainActionItems = new ArrayList<>(((OsmandSettings.MapContextMenuItemsSettings) pref).getMainActionIds());
@ -196,6 +170,16 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
} }
} }
public static List<ContextMenuItem> getCustomizableDefaultItems(List<ContextMenuItem> defItems) {
List<ContextMenuItem> items = new ArrayList<>();
for (ContextMenuItem item : defItems) {
if (!APP_PROFILES_ID.equals(item.getId())) {
items.add(item);
}
}
return items;
}
private void instantiateContextMenuAdapter() { private void instantiateContextMenuAdapter() {
if (activity instanceof MapActivity) { if (activity instanceof MapActivity) {
switch (screenType) { switch (screenType) {
@ -256,7 +240,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
applyButton.setOnClickListener(new View.OnClickListener() { applyButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems(); List<ContextMenuItem> defItems = getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems());
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
if (!menuItemsOrder.isEmpty()) { if (!menuItemsOrder.isEmpty()) {
sortByCustomOrder(defItems, menuItemsOrder); sortByCustomOrder(defItems, menuItemsOrder);
@ -307,7 +291,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
instantiateContextMenuAdapter(); instantiateContextMenuAdapter();
if (menuItemsOrder.isEmpty()) { if (menuItemsOrder.isEmpty()) {
for (ContextMenuItem item : contextMenuAdapter.getDefaultItems()) { for (ContextMenuItem item : getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems())) {
menuItemsOrder.put(item.getId(), item.getOrder()); menuItemsOrder.put(item.getId(), item.getOrder());
} }
} }
@ -566,7 +550,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
} }
private List<RearrangeMenuAdapterItem> getItemsForRearrangeAdapter(List<String> hiddenItemsIds, HashMap<String, Integer> itemsOrderIds, boolean hidden) { private List<RearrangeMenuAdapterItem> getItemsForRearrangeAdapter(List<String> hiddenItemsIds, HashMap<String, Integer> itemsOrderIds, boolean hidden) {
List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems(); List<ContextMenuItem> defItems = getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems());
if (!itemsOrderIds.isEmpty()) { if (!itemsOrderIds.isEmpty()) {
sortByCustomOrder(defItems, itemsOrderIds); sortByCustomOrder(defItems, itemsOrderIds);
} }

View file

@ -285,7 +285,7 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
break; break;
} }
int hiddenCount = ConfigureMenuItemsFragment.getSettingForScreen(app, type).getModeValue(appMode).getHiddenIds().size(); int hiddenCount = ConfigureMenuItemsFragment.getSettingForScreen(app, type).getModeValue(appMode).getHiddenIds().size();
int allCount = contextMenuAdapter.getDefaultItems().size(); int allCount = ConfigureMenuItemsFragment.getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems()).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);
} }