Merge pull request #10561 from osmandapp/share_address_poi_type

Share address. Nearby POI (update)
This commit is contained in:
Vitaliy 2021-01-16 17:17:31 +02:00 committed by GitHub
commit 57c27167ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 23 deletions

View file

@ -66,8 +66,10 @@ import net.osmand.plus.openplacereviews.AddPhotosBottomSheetDialogFragment;
import net.osmand.plus.openplacereviews.OPRConstants;
import net.osmand.plus.openplacereviews.OprStartFragment;
import net.osmand.plus.osmedit.opr.OpenDBAPI;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchToolbarController;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.views.layers.POIMapLayer;
import net.osmand.plus.views.layers.TransportStopsLayer;
@ -100,6 +102,8 @@ public class MenuBuilder {
public static final float SHADOW_HEIGHT_TOP_DP = 17f;
public static final int TITLE_LIMIT = 60;
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 MapContextMenu mapContextMenu;
@ -353,19 +357,20 @@ public class MenuBuilder {
protected void buildNearestWikiRow(View view) {
buildNearestRow(view, nearestWiki, processNearestWiki(),
R.drawable.ic_action_wikipedia, app.getString(R.string.wiki_around));
R.drawable.ic_action_wikipedia, app.getString(R.string.wiki_around), NEAREST_WIKI_KEY);
}
protected void buildNearestPoiRow(View view) {
buildNearestRow(view, nearestPoi, processNearestPoi(),
nearestPoi.isEmpty() ? 0 : AmenityMenuController.getRightIconId(nearestPoi.get(0)),
app.getString(R.string.speak_poi));
if (amenity != null) {
buildNearestRow(view, nearestPoi, processNearestPoi(), AmenityMenuController.getRightIconId(amenity),
app.getString(R.string.speak_poi) + " \"" + AmenityMenuController.getTypeStr(amenity) + "\" (" + nearestPoi.size() + ")", NEAREST_POI_KEY);
}
}
protected void buildNearestRow(View view, List<Amenity> nearestAmenities, boolean process, int iconId, String text) {
protected void buildNearestRow(View view, List<Amenity> nearestAmenities, boolean process, int iconId, String text, String amenityKey) {
if (process && nearestAmenities.size() > 0) {
buildRow(view, iconId, null, text + " (" + nearestAmenities.size() + ")", 0, true,
getCollapsableView(view.getContext(), true, nearestAmenities), false, 0, false, null, false);
getCollapsableView(view.getContext(), true, nearestAmenities, amenityKey), false, 0, false, null, false);
}
}
@ -1155,8 +1160,8 @@ public class MenuBuilder {
return new CollapsableView(textView, this, collapsed);
}
protected CollapsableView getCollapsableView(Context context, boolean collapsed, List<Amenity> nearestAmenities) {
LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true);
protected CollapsableView getCollapsableView(Context context, boolean collapsed, List<Amenity> nearestAmenities, String nearestPoiType) {
LinearLayout view = buildCollapsableContentView(context, collapsed, true);
for (final Amenity poi : nearestAmenities) {
TextViewEx button = buildButtonInCollapsableView(context, false, false);
@ -1164,6 +1169,8 @@ public class MenuBuilder {
if (Algorithms.isBlank(name)) {
name = AmenityMenuController.getTypeStr(poi);
}
float dist = (float) MapUtils.getDistance(latLon, poi.getLocation());
name += " (" + OsmAndFormatter.getFormattedDistance(dist, app) + ")";
button.setText(name);
button.setOnClickListener(new View.OnClickListener() {
@ -1176,10 +1183,52 @@ public class MenuBuilder {
});
view.addView(button);
}
PoiUIFilter filter = getPoiFilterForType(nearestPoiType);
if (filter != null) {
view.addView(createShowAllButton(context, filter));
}
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) {
final LinearLayout view = new LinearLayout(context);
view.setOrientation(LinearLayout.VERTICAL);
@ -1243,9 +1292,7 @@ public class MenuBuilder {
protected boolean processNearestPoi() {
if (showNearestPoi && latLon != null && amenity != null) {
PoiCategory pc = amenity.getType();
PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
PoiUIFilter filter = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + pt.getKeyName());
PoiUIFilter filter = getPoiFilterForAmenity(amenity);
if (filter != null) {
nearestPoi = getSortedAmenities(filter, latLon);
return true;
@ -1254,6 +1301,24 @@ public class MenuBuilder {
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) {
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 250);
@ -1273,8 +1338,8 @@ public class MenuBuilder {
return nearestAmenities;
}
private List<Amenity> getAmenities(QuadRect rect, PoiUIFilter wikiPoiFilter) {
return wikiPoiFilter.searchAmenities(rect.top, rect.left,
private List<Amenity> getAmenities(QuadRect rect, PoiUIFilter filter) {
return filter.searchAmenities(rect.top, rect.left,
rect.bottom, rect.right, -1, null);
}

View file

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

View file

@ -59,9 +59,9 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
}
@Override
protected void buildNearestRow(View view, List<Amenity> nearestAmenities, boolean process, int iconId, String text) {
protected void buildNearestRow(View view, List<Amenity> nearestAmenities, boolean process, int iconId, String text, String amenityKey) {
if (originObject == null || !(originObject instanceof Amenity)) {
super.buildNearestRow(view, nearestAmenities, process, iconId, text);
super.buildNearestRow(view, nearestAmenities, process, iconId, text, amenityKey);
}
}

View file

@ -23,6 +23,7 @@ public class TransportStopMenuBuilder extends MenuBuilder {
AmenityMenuBuilder builder = new AmenityMenuBuilder(mapActivity, amenity);
builder.setLatLon(getLatLon());
builder.setLight(light);
builder.setShowNearestPoi(false);
builder.buildInternal(view);
}
}

View file

@ -36,7 +36,7 @@ public class ShareMenu extends BaseMenuController {
public enum ShareItem {
MESSAGE(R.drawable.ic_action_message, R.string.shared_string_send),
CLIPBOARD(R.drawable.ic_action_copy, R.string.shared_string_copy),
ADDRESS(R.drawable.ic_action_copy, R.string.copy_address),
ADDRESS(R.drawable.ic_action_street_name, R.string.copy_address),
NAME(R.drawable.ic_action_copy, R.string.copy_location_name),
COORDINATES(R.drawable.ic_action_copy, R.string.copy_coordinates),
GEO(R.drawable.ic_world_globe_dark, R.string.share_geo),