fix actions clicks

This commit is contained in:
veliymolfar 2020-04-10 15:30:18 +03:00
parent c86a3fea30
commit b229c7405b
4 changed files with 27 additions and 46 deletions

View file

@ -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"
]
}
}
}
}

View file

@ -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);

View file

@ -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();

View file

@ -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<ContextMenuItem> 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<ContextMenuItem> additional,
List<ContextMenuItem> 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);
}
});
}