Minor fixes

This commit is contained in:
Vitaliy 2021-01-16 17:05:45 +02:00
parent dea4df61f8
commit 410f01d21e
2 changed files with 72 additions and 63 deletions

View file

@ -102,6 +102,8 @@ public class MenuBuilder {
public static final float SHADOW_HEIGHT_TOP_DP = 17f; public static final float SHADOW_HEIGHT_TOP_DP = 17f;
public static final int TITLE_LIMIT = 60; public static final int TITLE_LIMIT = 60;
protected static final String[] arrowChars = new String[] {"=>", " - "}; protected static final String[] arrowChars = new String[] {"=>", " - "};
protected final String NEAREST_WIKI_KEY = "nearest_wiki_key";
protected final String NEAREST_POI_KEY = "nearest_poi_key";
protected MapActivity mapActivity; protected MapActivity mapActivity;
protected MapContextMenu mapContextMenu; protected MapContextMenu mapContextMenu;
@ -119,9 +121,6 @@ public class MenuBuilder {
private boolean showOnlinePhotos = true; private boolean showOnlinePhotos = true;
protected List<Amenity> nearestWiki = new ArrayList<>(); protected List<Amenity> nearestWiki = new ArrayList<>();
protected List<Amenity> nearestPoi = new ArrayList<>(); protected List<Amenity> nearestPoi = new ArrayList<>();
protected final String keyWiki = "nearest_wiki";
protected final String keyPoi = "nearest_poi";
private PoiUIFilter poiFilter;
private List<OsmandPlugin> menuPlugins = new ArrayList<>(); private List<OsmandPlugin> menuPlugins = new ArrayList<>();
@Nullable @Nullable
private CardsRowBuilder onlinePhotoCardsRow; private CardsRowBuilder onlinePhotoCardsRow;
@ -358,13 +357,13 @@ public class MenuBuilder {
protected void buildNearestWikiRow(View view) { protected void buildNearestWikiRow(View view) {
buildNearestRow(view, nearestWiki, processNearestWiki(), buildNearestRow(view, nearestWiki, processNearestWiki(),
R.drawable.ic_action_wikipedia, app.getString(R.string.wiki_around), keyWiki); R.drawable.ic_action_wikipedia, app.getString(R.string.wiki_around), NEAREST_WIKI_KEY);
} }
protected void buildNearestPoiRow(View view) { protected void buildNearestPoiRow(View view) {
if (amenity != null) { if (amenity != null) {
buildNearestRow(view, nearestPoi, processNearestPoi(), AmenityMenuController.getRightIconId(amenity), buildNearestRow(view, nearestPoi, processNearestPoi(), AmenityMenuController.getRightIconId(amenity),
app.getString(R.string.speak_poi) + " \"" + AmenityMenuController.getTypeStr(amenity) + "\" (" + nearestPoi.size() + ")", keyPoi); app.getString(R.string.speak_poi) + " \"" + AmenityMenuController.getTypeStr(amenity) + "\" (" + nearestPoi.size() + ")", NEAREST_POI_KEY);
} }
} }
@ -1161,8 +1160,8 @@ public class MenuBuilder {
return new CollapsableView(textView, this, collapsed); return new CollapsableView(textView, this, collapsed);
} }
protected CollapsableView getCollapsableView(Context context, boolean collapsed, List<Amenity> nearestAmenities, final String amenityKey) { protected CollapsableView getCollapsableView(Context context, boolean collapsed, List<Amenity> nearestAmenities, String nearestPoiType) {
LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true); LinearLayout view = buildCollapsableContentView(context, collapsed, true);
for (final Amenity poi : nearestAmenities) { for (final Amenity poi : nearestAmenities) {
TextViewEx button = buildButtonInCollapsableView(context, false, false); TextViewEx button = buildButtonInCollapsableView(context, false, false);
@ -1184,58 +1183,52 @@ public class MenuBuilder {
}); });
view.addView(button); view.addView(button);
} }
PoiUIFilter filter = getPoiFilterForType(nearestPoiType);
final PoiUIFilter filter;
if (amenityKey.equals(keyPoi)) {
filter = poiFilter;
} else if (amenityKey.equals(keyWiki)) {
filter = app.getPoiFilters().getTopWikiPoiFilter();
} else {
filter = null;
}
if (filter != null) { if (filter != null) {
TextViewEx buttonShowAll = buildButtonInCollapsableView(context, false, false); view.addView(createShowAllButton(context, filter));
buttonShowAll.setText(app.getString(R.string.shared_string_show_on_map));
buttonShowAll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PoiFiltersHelper ph = app.getPoiFilters();
ph.clearSelectedPoiFilters();
ph.addSelectedPoiFilter(filter);
final QuickSearchToolbarController controller = new QuickSearchToolbarController();
controller.setTitle(filter.getName());
controller.setOnBackButtonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.showQuickSearch(filter);
}
});
controller.setOnTitleClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.showQuickSearch(filter);
}
});
controller.setOnCloseButtonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ph.clearSelectedPoiFilters();
mapActivity.hideTopToolbar(controller);
mapActivity.refreshMap();
}
});
mapContextMenu.hideMenues();
mapActivity.showTopToolbar(controller);
mapActivity.refreshMap();
}
});
view.addView(buttonShowAll);
} }
return new CollapsableView(view, this, collapsed); return new CollapsableView(view, this, collapsed);
} }
private View createShowAllButton(Context context, final PoiUIFilter filter) {
TextViewEx buttonShowAll = buildButtonInCollapsableView(context, false, false);
buttonShowAll.setText(app.getString(R.string.shared_string_show_on_map));
buttonShowAll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PoiFiltersHelper poiFiltersHelper = app.getPoiFilters();
poiFiltersHelper.clearSelectedPoiFilters();
poiFiltersHelper.addSelectedPoiFilter(filter);
final QuickSearchToolbarController controller = new QuickSearchToolbarController();
controller.setTitle(filter.getName());
controller.setOnBackButtonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mapContextMenu.show();
}
});
controller.setOnTitleClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.showQuickSearch(filter);
}
});
controller.setOnCloseButtonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
poiFiltersHelper.clearSelectedPoiFilters();
mapActivity.hideTopToolbar(controller);
mapActivity.refreshMap();
}
});
mapContextMenu.hideMenues();
mapActivity.showTopToolbar(controller);
mapActivity.refreshMap();
}
});
return buttonShowAll;
}
protected LinearLayout buildCollapsableContentView(Context context, boolean collapsed, boolean needMargin) { protected LinearLayout buildCollapsableContentView(Context context, boolean collapsed, boolean needMargin) {
final LinearLayout view = new LinearLayout(context); final LinearLayout view = new LinearLayout(context);
view.setOrientation(LinearLayout.VERTICAL); view.setOrientation(LinearLayout.VERTICAL);
@ -1299,17 +1292,33 @@ public class MenuBuilder {
protected boolean processNearestPoi() { protected boolean processNearestPoi() {
if (showNearestPoi && latLon != null && amenity != null) { if (showNearestPoi && latLon != null && amenity != null) {
PoiCategory pc = amenity.getType(); PoiUIFilter filter = getPoiFilterForAmenity(amenity);
PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType()); if (filter != null) {
poiFilter = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + pt.getKeyName()); nearestPoi = getSortedAmenities(filter, latLon);
if (poiFilter != null) {
nearestPoi = getSortedAmenities(poiFilter, latLon);
return true; return true;
} }
} }
return false; return false;
} }
private PoiUIFilter getPoiFilterForType(String nearestPoiType) {
if (NEAREST_POI_KEY.equals(nearestPoiType)) {
return getPoiFilterForAmenity(amenity);
} else if (NEAREST_WIKI_KEY.equals(nearestPoiType)) {
return app.getPoiFilters().getTopWikiPoiFilter();
}
return null;
}
private PoiUIFilter getPoiFilterForAmenity(Amenity amenity) {
if (amenity != null) {
PoiCategory category = amenity.getType();
PoiType poiType = category.getPoiTypeByKeyName(amenity.getSubType());
return app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + poiType.getKeyName());
}
return null;
}
private List<Amenity> getSortedAmenities(PoiUIFilter filter, final LatLon latLon) { private List<Amenity> getSortedAmenities(PoiUIFilter filter, final LatLon latLon) {
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 250); QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 250);

View file

@ -684,18 +684,18 @@ public class AmenityMenuBuilder extends MenuBuilder {
if (processNearestWiki() && nearestWiki.size() > 0) { if (processNearestWiki() && nearestWiki.size() > 0) {
AmenityInfoRow wikiInfo = new AmenityInfoRow( AmenityInfoRow wikiInfo = new AmenityInfoRow(
keyWiki, R.drawable.ic_plugin_wikipedia, null, NEAREST_WIKI_KEY, R.drawable.ic_plugin_wikipedia, null,
app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")",
null, true, getCollapsableView(view.getContext(), true, nearestWiki, keyWiki), null, true, getCollapsableView(view.getContext(), true, nearestWiki, NEAREST_WIKI_KEY),
0, false, false, false, 1000, null, false, false, false, 0); 0, false, false, false, 1000, null, false, false, false, 0);
buildAmenityRow(view, wikiInfo); buildAmenityRow(view, wikiInfo);
} }
if (processNearestPoi() && nearestPoi.size() > 0) { if (processNearestPoi() && nearestPoi.size() > 0) {
AmenityInfoRow poiInfo = new AmenityInfoRow( AmenityInfoRow poiInfo = new AmenityInfoRow(
keyPoi, AmenityMenuController.getRightIconId(amenity), null, NEAREST_POI_KEY, AmenityMenuController.getRightIconId(amenity), null,
app.getString(R.string.speak_poi) + " \"" + AmenityMenuController.getTypeStr(amenity) + "\" (" + nearestPoi.size() + ")", app.getString(R.string.speak_poi) + " \"" + AmenityMenuController.getTypeStr(amenity) + "\" (" + nearestPoi.size() + ")",
null, true, getCollapsableView(view.getContext(), true, nearestPoi, keyPoi), null, true, getCollapsableView(view.getContext(), true, nearestPoi, NEAREST_POI_KEY),
0, false, false, false, 1000, null, false, false, false, 0); 0, false, false, false, 1000, null, false, false, false, 0);
buildAmenityRow(view, poiInfo); buildAmenityRow(view, poiInfo);
} }