POI-Panel: Allow to search for other POIs of the same category

This commit is contained in:
androiddevkotlin 2021-04-08 12:42:01 +03:00
parent acff47bf8a
commit 62313cc468
4 changed files with 49 additions and 28 deletions

View file

@ -12,6 +12,7 @@
--> -->
<string name="search_more">Search more…</string>
<string name="map_quick_action_pattern">%1$s → …</string> <string name="map_quick_action_pattern">%1$s → …</string>
<string name="output">Output</string> <string name="output">Output</string>
<string name="user_points">User points</string> <string name="user_points">User points</string>

View file

@ -1217,33 +1217,40 @@ 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, String nearestPoiType) { protected CollapsableView getCollapsableView(final Context context, boolean collapsed, List<Amenity> nearestAmenities, String nearestPoiType) {
LinearLayout view = buildCollapsableContentView(context, collapsed, true); final 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);
String name = poi.getName(preferredMapAppLang, transliterateNames); final PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(poi);
String name = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(poi).getName();
if (Algorithms.isBlank(name)) { if (Algorithms.isBlank(name)) {
name = AmenityMenuController.getTypeStr(poi); name = AmenityMenuController.getTypeStr(poi);
} }
float dist = (float) MapUtils.getDistance(latLon, poi.getLocation()); float dist = (float) MapUtils.getDistance(latLon, poi.getLocation());
name += " (" + OsmAndFormatter.getFormattedDistance(dist, app) + ")"; name += " (" + OsmAndFormatter.getFormattedDistance(dist, app) + ")";
button.setText(name); button.setText(name);
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
LatLon latLon = new LatLon(poi.getLocation().getLatitude(), poi.getLocation().getLongitude()); LatLon latLon = new LatLon(poi.getLocation().getLatitude(), poi.getLocation().getLongitude());
PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(poi);
mapActivity.getContextMenu().show(latLon, pointDescription, poi); mapActivity.getContextMenu().show(latLon, pointDescription, poi);
mapActivity.getContextMenu().update(latLon, pointDescription, poi);
mapActivity.setMapLocation(poi.getLocation().getLatitude(), poi.getLocation().getLongitude());
} }
}); });
view.addView(button); view.addView(button);
} }
PoiUIFilter filter = getPoiFilterForType(nearestPoiType); PoiUIFilter filter = getPoiFilterForType(nearestPoiType);
if (filter != null) { boolean isPoiFilter = nearestPoiType.equals(NEAREST_POI_KEY);
if (filter != null && nearestPoi.size() > 0) {
view.addView(createShowAllButton(context, filter)); view.addView(createShowAllButton(context, filter));
} }
if (isPoiFilter && nearestPoi.size() == 0) {
view.addView(createSearchMoreButton(context, filter));
}
return new CollapsableView(view, this, collapsed); return new CollapsableView(view, this, collapsed);
} }
@ -1288,6 +1295,18 @@ public class MenuBuilder {
return buttonShowAll; return buttonShowAll;
} }
private View createSearchMoreButton(Context context, final PoiUIFilter filter) {
TextViewEx buttonShowAll = buildButtonInCollapsableView(context, false, false);
buttonShowAll.setText(app.getString(R.string.search_more));
buttonShowAll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.showQuickSearch(filter);
}
});
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);
@ -1381,8 +1400,8 @@ public class MenuBuilder {
} }
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); boolean isWikiFilter = filter.getFilterId().equals("std_osmwiki");
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), isWikiFilter ? 250 : 1000);
List<Amenity> nearestAmenities = getAmenities(rect, filter); List<Amenity> nearestAmenities = getAmenities(rect, filter);
nearestAmenities.remove(amenity); nearestAmenities.remove(amenity);
@ -1395,8 +1414,11 @@ public class MenuBuilder {
return Double.compare(d1, d2); return Double.compare(d1, d2);
} }
}); });
if (isWikiFilter) {
return nearestAmenities; return nearestAmenities;
} else {
return nearestAmenities.subList(0, Math.min(10, nearestAmenities.size()));
}
} }
private List<Amenity> getAmenities(QuadRect rect, PoiUIFilter filter) { private List<Amenity> getAmenities(QuadRect rect, PoiUIFilter filter) {

View file

@ -28,6 +28,7 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.mapcontextmenu.CollapsableView; import net.osmand.plus.mapcontextmenu.CollapsableView;
import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuBuilder;
@ -68,7 +69,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
private static final String WIKI_LINK = ".wikipedia.org/w"; private static final String WIKI_LINK = ".wikipedia.org/w";
public final static Log LOG = PlatformUtil.getLog(AmenityMenuBuilder.class); public final static Log LOG = PlatformUtil.getLog(AmenityMenuBuilder.class);
private final static DecimalFormat DF = new DecimalFormat("#.##"); private final static DecimalFormat DF = new DecimalFormat("#.##");
private MetricsConstants metricSystem; private final MetricsConstants metricSystem;
private final Amenity amenity; private final Amenity amenity;
@ -417,7 +418,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
} else if (Amenity.OPENING_HOURS.equals(key)) { } else if (Amenity.OPENING_HOURS.equals(key)) {
iconId = R.drawable.ic_action_time; iconId = R.drawable.ic_action_time;
collapsableView = getCollapsableTextView(view.getContext(), true, collapsableView = getCollapsableTextView(view.getContext(), true,
amenity.getAdditionalInfo(key).replace("; ", "\n").replace(",", ", ")); amenity.getAdditionalInfo(key).replace("; ", "\n").replace(",", ", "));
collapsable = true; collapsable = true;
OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getAdditionalInfo(key)); OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getAdditionalInfo(key));
if (rs != null) { if (rs != null) {
@ -459,7 +460,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
vl = sb.toString(); vl = sb.toString();
} else if (key.contains(Amenity.ROUTE) } else if (key.contains(Amenity.ROUTE)
|| key.equals(Amenity.WIKIDATA) || key.equals(Amenity.WIKIDATA)
|| key.equals(Amenity.WIKIMEDIA_COMMONS)) { || key.equals(Amenity.WIKIMEDIA_COMMONS)) {
continue; continue;
} else { } else {
if (key.contains(Amenity.DESCRIPTION)) { if (key.contains(Amenity.DESCRIPTION)) {
@ -661,7 +662,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
buildAmenityRow(view, wikiInfo); buildAmenityRow(view, wikiInfo);
} }
if (processNearestPoi() && nearestPoi.size() > 0) { if (processNearestPoi()) {
AmenityInfoRow poiInfo = new AmenityInfoRow( AmenityInfoRow poiInfo = new AmenityInfoRow(
NEAREST_POI_KEY, 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() + ")",
@ -725,35 +726,35 @@ public class AmenityMenuBuilder extends MenuBuilder {
} }
break; break;
case "distance": case "distance":
if(Algorithms.isFloat(value)) { if (Algorithms.isFloat(value)) {
float valueAsFloatInMeters = Float.parseFloat(value) * 1000; float valueAsFloatInMeters = Float.parseFloat(value) * 1000;
if (metricSystem == MetricsConstants.KILOMETERS_AND_METERS) { if (metricSystem == MetricsConstants.KILOMETERS_AND_METERS) {
formattedValue = formattedValue =
value + " " + mapActivity.getResources().getString(R.string.km); value + " " + mapActivity.getResources().getString(R.string.km);
} else { } else {
formattedValue = OsmAndFormatter.getFormattedDistance(valueAsFloatInMeters, formattedValue = OsmAndFormatter.getFormattedDistance(valueAsFloatInMeters,
mapActivity.getMyApplication()); mapActivity.getMyApplication());
} }
formattedPrefix = formatPrefix(prefix, formattedPrefix = formatPrefix(prefix,
mapActivity.getResources().getString(R.string.distance)); mapActivity.getResources().getString(R.string.distance));
break; break;
} }
case "capacity": case "capacity":
if (amenity.getSubType().equals("water_tower") || amenity.getSubType().equals("storage_tank")) { if (amenity.getSubType().equals("water_tower") || amenity.getSubType().equals("storage_tank")) {
if(Algorithms.isFloat(value)) { if (Algorithms.isFloat(value)) {
formattedValue = value + " " + mapActivity.getResources().getString(R.string.cubic_m); formattedValue = value + " " + mapActivity.getResources().getString(R.string.cubic_m);
} }
} }
break; break;
case "maxweight": case "maxweight":
if(Algorithms.isInt(value)) { if (Algorithms.isInt(value)) {
formattedValue = value + " " + mapActivity.getResources().getString(R.string.metric_ton); formattedValue = value + " " + mapActivity.getResources().getString(R.string.metric_ton);
} }
break; break;
case "students": case "students":
case "spots": case "spots":
case "seats": case "seats":
if(Algorithms.isInt(value)) { if (Algorithms.isInt(value)) {
formattedPrefix = formatPrefix(prefix, mapActivity.getResources().getString(R.string.shared_string_capacity)); formattedPrefix = formatPrefix(prefix, mapActivity.getResources().getString(R.string.shared_string_capacity));
} }
break; break;
@ -764,7 +765,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
} }
private String formatPrefix(String prefix, String units) { private String formatPrefix(String prefix, String units) {
return (!prefix.isEmpty()) ? (prefix + ", " + units): units; return (!prefix.isEmpty()) ? (prefix + ", " + units) : units;
} }
public void buildAmenityRow(View view, AmenityInfoRow info) { public void buildAmenityRow(View view, AmenityInfoRow info) {

View file

@ -604,9 +604,6 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
selectedItems.clear(); selectedItems.clear();
} }
notifyDataSetChanged(); notifyDataSetChanged();
if (selectionListener != null) {
selectionListener.onUpdateSelectionMode(selectedItems);
}
} else { } else {
QuickSearchListItem listItem = getItem(position); QuickSearchListItem listItem = getItem(position);
if (ch.isChecked()) { if (ch.isChecked()) {
@ -614,9 +611,9 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
} else { } else {
selectedItems.remove(listItem); selectedItems.remove(listItem);
} }
if (selectionListener != null) { }
selectionListener.onUpdateSelectionMode(selectedItems); if (selectionListener != null) {
} selectionListener.onUpdateSelectionMode(selectedItems);
} }
} }