Better switch logic for Underlay/Overlay

This commit is contained in:
GaidamakUA 2016-04-08 17:32:34 +03:00
parent 2bc8ef25a3
commit c4f3a6fbc2

View file

@ -238,13 +238,10 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
final int defaultColor = IconsCache.getDefaultColorRes(mapActivity);
final MapActivityLayers layers = mapActivity.getMapLayers();
ContextMenuAdapter.ItemClickListener listener = new ItemClickListener() {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
if (itemId == R.string.layer_map) {
layers.selectMapLayer(mapView);
} else if (itemId == R.string.layer_overlay) {
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
if (itemId == R.string.layer_overlay) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.OVERLAY_MAP);
return false;
} else if (itemId == R.string.layer_underlay) {
@ -253,6 +250,53 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
}
return true;
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked) {
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
switch (itemId) {
case R.string.layer_overlay:
toggleUnderlayState(mapActivity, RasterMapType.OVERLAY,
new OnMapSelectedCallback() {
@Override
public void onMapSelected() {
ContextMenuItem item = adapter.getItem(pos);
String overlayMapDescr = settings.MAP_OVERLAY.get();
boolean hasOverlayDescription = overlayMapDescr != null;
overlayMapDescr = hasOverlayDescription ? overlayMapDescr
: mapActivity.getString(R.string.shared_string_none);
item.setDescription(overlayMapDescr);
item.setSelected(hasOverlayDescription);
item.setColorRes(hasOverlayDescription ? R.color.osmand_orange : defaultColor);
adapter.notifyDataSetChanged();
}
});
return false;
case R.string.layer_underlay:
toggleUnderlayState(mapActivity, RasterMapType.UNDERLAY, new
OnMapSelectedCallback() {
@Override
public void onMapSelected() {
ContextMenuItem item = adapter.getItem(pos);
String underlayMapDescr = settings.MAP_UNDERLAY.get();
boolean hasUnderlayDescription = underlayMapDescr != null;
underlayMapDescr = hasUnderlayDescription ? underlayMapDescr
: mapActivity.getString(R.string.shared_string_none);
item.setDescription(underlayMapDescr);
item.setSelected(hasUnderlayDescription);
item.setColorRes(hasUnderlayDescription ? R.color.osmand_orange : defaultColor);
adapter.notifyDataSetChanged();
}
});
return false;
}
return true;
}
};
String overlayMapDescr = settings.MAP_OVERLAY.get();