From b229c7405b001e8aa939d938ccd47c615ed042ae Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 10 Apr 2020 15:30:18 +0300 Subject: [PATCH] fix actions clicks --- OsmAnd/assets/poi_categories.json | 33 +++++++------------ .../net/osmand/plus/ContextMenuAdapter.java | 1 + .../plus/mapcontextmenu/MapContextMenu.java | 13 -------- .../MapContextMenuFragment.java | 26 ++++++++------- 4 files changed, 27 insertions(+), 46 deletions(-) diff --git a/OsmAnd/assets/poi_categories.json b/OsmAnd/assets/poi_categories.json index f386828f4d..51afd627af 100644 --- a/OsmAnd/assets/poi_categories.json +++ b/OsmAnd/assets/poi_categories.json @@ -1,25 +1,14 @@ { - "categories": { - "special": { - "icons": [ - "special_star", - "special_star_stroked", - "special_marker", - "special_flag_stroke", - "special_house", - "special_building" - ] - }, - "amenity": { - "icons": [ - "amenity_bar", - "amenity_cafe", - "amenity_atm", - "amenity_biergarten", - "amenity_cinema", - "amenity_fire_station", - "amenity_parking" - ] + "categories" : { + "special" : { + "icons" : [ + "special_star", "special_star_stroked", "special_marker", "special_flag_stroke", "special_house", "special_building" + ] + }, + "amenity" : { + "icons": [ + "amenity_bar", "amenity_cafe", "amenity_atm", "amenity_biergarten", "amenity_cinema", "amenity_fire_station", "amenity_parking" + ] + } } - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index 8069574dbc..b8f556e9e8 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -87,6 +87,7 @@ public class ContextMenuAdapter { public void addItem(ContextMenuItem item) { try { +// TODO items.add(item.getPos(), item); } catch (IndexOutOfBoundsException ex) { items.add(item); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 31899617ff..b10f57e593 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -1062,19 +1062,6 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } } -// public void buttonMorePressed() { -// MapActivity mapActivity = getMapActivity(); -// if (mapActivity != null) { -// final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(); -// LatLon latLon = getLatLon(); -// for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) { -// layer.populateObjectContextMenu(latLon, getObject(), menuAdapter, mapActivity); -// } -// -// mapActivity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), menuAdapter, getObject()); -// } -// } - public ContextMenuAdapter getActionsContextMenuAdapter(boolean all) { MapActivity mapActivity = getMapActivity(); final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index a5f837db50..01373b6188 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -564,6 +564,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo } // Action buttons +// TODO refactor section ContextMenuAdapter adapter = menu.getActionsContextMenuAdapter(false); adapter.initItemsCustomOrder(requireMyApplication()); List items = adapter.getItems(); @@ -581,8 +582,15 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo 1f ); buttons.removeAllViews(); + ContextMenuAdapter mainAdapter = new ContextMenuAdapter(); + mainAdapter.updateItems(main); + ContextMenuItemClickListener mainListener = menu.getContextMenuItemClickListener(mainAdapter); + ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(); + additionalAdapter.updateItems(additional); + ContextMenuItemClickListener additionalListener = menu.getContextMenuItemClickListener(additionalAdapter); + for (int i = 0; i < main.size(); i++) { - buttons.addView(getActionView(main.get(i), i, adapter, additional,main), params); + buttons.addView(getActionView(main.get(i), i, mainAdapter, additionalAdapter, mainListener, additionalListener), params); } buttons.setGravity(Gravity.CENTER); @@ -645,9 +653,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo private View getActionView(ContextMenuItem contextMenuItem, final int position, - final ContextMenuAdapter adapter, - List additional, - List main) { + final ContextMenuAdapter mainAdapter, + final ContextMenuAdapter additionalAdapter, + final ContextMenuItemClickListener mainListener, + final ContextMenuItemClickListener additionalListener) { UiUtilities uiUtilities = requireMyApplication().getUIUtilities(); LayoutInflater inflater = UiUtilities.getInflater(getMyApplication(), nightMode); View view = inflater.inflate(R.layout.context_menu_action_item, null); @@ -656,23 +665,18 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo TextView title = view.findViewById(R.id.text); icon.setImageDrawable(uiUtilities.getIcon(contextMenuItem.getIcon(), nightMode)); title.setText(contextMenuItem.getTitle()); - adapter.updateItems(main); - final ContextMenuItemClickListener l = menu.getContextMenuItemClickListener(adapter); if (contextMenuItem.getId().equals(MAP_CONTEXT_MENU_MORE_ID)) { - final ContextMenuAdapter aditionalAdapter = adapter; - aditionalAdapter.updateItems(additional); - final ContextMenuItemClickListener listener = menu.getContextMenuItemClickListener(aditionalAdapter); item.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - menu.showAdditionalActionsFragment(aditionalAdapter, listener); + menu.showAdditionalActionsFragment(additionalAdapter, additionalListener); } }); } else { item.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - l.onItemClick(position); + mainListener.onItemClick(position); } }); }