Fixed known poi selection bugs.

This commit is contained in:
GaidamakUA 2016-05-06 13:44:23 +03:00
parent 6a684e44ea
commit 174e4ecc4b
3 changed files with 48 additions and 28 deletions

View file

@ -261,7 +261,7 @@ public class MapActivityLayers {
} }
public void showMultichoicePoiFilterDialog(final OsmandMapTileView mapView, final ConfirmListener 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();
@ -295,7 +295,6 @@ public class MapActivityLayers {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mapView.refreshMap(); mapView.refreshMap();
listener.confirm();
} }
}) })
.setNegativeButton(R.string.shared_string_cancel, null) .setNegativeButton(R.string.shared_string_cancel, null)
@ -312,12 +311,19 @@ public class MapActivityLayers {
public void onShow(DialogInterface dialog) { public void onShow(DialogInterface dialog) {
Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL); Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_singleselect); Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_singleselect);
neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); } neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
}
});
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
listener.dismiss();
}
}); });
alertDialog.show(); alertDialog.show();
} }
public void showSingleChoicePoiFilterDialog(final OsmandMapTileView mapView, final ConfirmListener 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();
@ -350,13 +356,12 @@ public class MapActivityLayers {
getApplication().getPoiFilters().clearSelectedPoiFilters(); getApplication().getPoiFilters().clearSelectedPoiFilters();
getApplication().getPoiFilters().addSelectedPoiFilter(pf); getApplication().getPoiFilters().addSelectedPoiFilter(pf);
mapView.refreshMap(); mapView.refreshMap();
listener.confirm();
} }
} }
}); });
builder.setTitle(R.string.show_poi_over_map); builder.setTitle(R.string.show_poi_over_map);
builder.setNegativeButton(R.string.shared_string_cancel, null); builder.setNegativeButton(R.string.shared_string_dismiss, null);
builder.setNeutralButton(" ", new DialogInterface.OnClickListener() { builder.setNeutralButton(" ", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -369,7 +374,14 @@ public class MapActivityLayers {
public void onShow(DialogInterface dialog) { public void onShow(DialogInterface dialog) {
Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL); Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_multiselect); Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_multiselect);
neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); } neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
}
});
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
listener.dismiss();
}
}); });
alertDialog.show(); alertDialog.show();
} }
@ -589,7 +601,7 @@ public class MapActivityLayers {
return downloadedRegionsLayer; return downloadedRegionsLayer;
} }
public interface ConfirmListener { public interface DismissListener {
void confirm(); void dismiss();
} }
} }

View file

@ -125,18 +125,18 @@ public class ConfigureMapMenu {
@Override @Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked) { public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked) {
final OsmandSettings settings = ma.getMyApplication().getSettings(); final OsmandSettings settings = ma.getMyApplication().getSettings();
final PoiFiltersHelper pfh = ma.getMyApplication().getPoiFilters(); final PoiFiltersHelper poiFiltersHelper = ma.getMyApplication().getPoiFilters();
final ContextMenuItem item = cm.getItem(pos); final ContextMenuItem item = cm.getItem(pos);
if (item.getSelected() != null) { if (item.getSelected() != null) {
item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
if (itemId == R.string.layer_poi) { if (itemId == R.string.layer_poi) {
pfh.clearSelectedPoiFilters(); poiFiltersHelper.clearSelectedPoiFilters();
if (isChecked) { if (isChecked) {
showPoiFilterDialog(adapter, adapter.getItem(pos)); showPoiFilterDialog(adapter, adapter.getItem(pos));
} else { } else {
adapter.getItem(pos).setDescription(pfh.getSelectedPoiFiltersName()); adapter.getItem(pos).setDescription(poiFiltersHelper.getSelectedPoiFiltersName());
} }
} else if (itemId == R.string.layer_amenity_label) { } else if (itemId == R.string.layer_amenity_label) {
settings.SHOW_POI_LABEL.set(isChecked); settings.SHOW_POI_LABEL.set(isChecked);
@ -185,18 +185,26 @@ public class ConfigureMapMenu {
protected void showPoiFilterDialog(final ArrayAdapter<ContextMenuItem> adapter, protected void showPoiFilterDialog(final ArrayAdapter<ContextMenuItem> adapter,
final ContextMenuItem item) { final ContextMenuItem item) {
ma.getMapLayers().showSingleChoicePoiFilterDialog(ma.getMapView(), final PoiFiltersHelper poiFiltersHelper = ma.getMyApplication().getPoiFilters();
new MapActivityLayers.ConfirmListener() { MapActivityLayers.DismissListener dismissListener =
@Override new MapActivityLayers.DismissListener() {
public void confirm() { @Override
PoiFiltersHelper pf = ma.getMyApplication().getPoiFilters(); public void dismiss() {
boolean selected = pf.isShowingAnyPoi(); PoiFiltersHelper pf = ma.getMyApplication().getPoiFilters();
item.setSelected(selected); boolean selected = pf.isShowingAnyPoi();
item.setDescription(pf.getSelectedPoiFiltersName()); item.setSelected(selected);
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID); item.setDescription(pf.getSelectedPoiFiltersName());
adapter.notifyDataSetChanged(); item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
} adapter.notifyDataSetChanged();
}); }
};
if (poiFiltersHelper.getSelectedPoiFilters().size() > 1) {
ma.getMapLayers().showMultichoicePoiFilterDialog(ma.getMapView(),
dismissListener);
} else {
ma.getMapLayers().showSingleChoicePoiFilterDialog(ma.getMapView(),
dismissListener);
}
} }
} }

View file

@ -618,9 +618,9 @@ public class WaypointDialogHelper {
thisAdapter.notifyDataSetInvalidated(); thisAdapter.notifyDataSetInvalidated();
MapActivity map = (MapActivity) ctx; MapActivity map = (MapActivity) ctx;
map.getMapLayers().showSingleChoicePoiFilterDialog(map.getMapView(), map.getMapLayers().showSingleChoicePoiFilterDialog(map.getMapView(),
new MapActivityLayers.ConfirmListener() { new MapActivityLayers.DismissListener() {
@Override @Override
public void confirm() { public void dismiss() {
enableType(running, thisAdapter, type, true); enableType(running, thisAdapter, type, true);
} }
}); });
@ -692,9 +692,9 @@ public class WaypointDialogHelper {
!app.getPoiFilters().isPoiFilterSelected(PoiUIFilter.CUSTOM_FILTER_ID)) { !app.getPoiFilters().isPoiFilterSelected(PoiUIFilter.CUSTOM_FILTER_ID)) {
MapActivity map = (MapActivity) ctx; MapActivity map = (MapActivity) ctx;
map.getMapLayers().showSingleChoicePoiFilterDialog(map.getMapView(), map.getMapLayers().showSingleChoicePoiFilterDialog(map.getMapView(),
new MapActivityLayers.ConfirmListener() { new MapActivityLayers.DismissListener() {
@Override @Override
public void confirm() { public void dismiss() {
if (app.getPoiFilters().isShowingAnyPoi()) { if (app.getPoiFilters().isShowingAnyPoi()) {
enableType(running, listAdapter, type, enable); enableType(running, listAdapter, type, enable);
} }