"Set destination" > Favorites, favorite point name should be shown in the "To:" section

This commit is contained in:
androiddevkkotlin 2020-12-22 18:39:08 +02:00
parent a654cd7439
commit 2872df857b

View file

@ -9,6 +9,7 @@ import android.os.Build;
import android.os.Build.VERSION_CODES; import android.os.Build.VERSION_CODES;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.util.Pair;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -285,9 +286,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (selectFromMapTouch) { if (selectFromMapTouch) {
selectFromMapTouch = false; selectFromMapTouch = false;
LatLon latLon = tileBox.getLatLonFromPixel(point.x, point.y); LatLon latLon = tileBox.getLatLonFromPixel(point.x, point.y);
LatLon objectLatLon = getObjectLocation(mapActivity.getMapView(), point, tileBox); Pair<LatLon, PointDescription> pair = getObjectLocation(mapActivity.getMapView(), point, tileBox);
LatLon selectedPoint = objectLatLon != null ? objectLatLon : latLon; LatLon selectedPoint = pair != null ? pair.first : latLon;
choosePointTypeAction(mapActivity, selectedPoint, selectFromMapPointType, null, null); PointDescription name = pair != null ? pair.second : null;
choosePointTypeAction(mapActivity, selectedPoint, selectFromMapPointType, name, null);
if (selectFromMapWaypoints) { if (selectFromMapWaypoints) {
WaypointsFragment.showInstance(mapActivity.getSupportFragmentManager(), true); WaypointsFragment.showInstance(mapActivity.getSupportFragmentManager(), true);
} else { } else {
@ -299,8 +301,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
return false; return false;
} }
private LatLon getObjectLocation(OsmandMapTileView mapView, PointF point, RotatedTileBox tileBox) { private Pair<LatLon, PointDescription> getObjectLocation(OsmandMapTileView mapView, PointF point, RotatedTileBox tileBox) {
LatLon latLon = null;
List<Object> objects = new ArrayList<>(); List<Object> objects = new ArrayList<>();
for (OsmandMapLayer layer : mapView.getLayers()) { for (OsmandMapLayer layer : mapView.getLayers()) {
if (layer instanceof IContextMenuProvider) { if (layer instanceof IContextMenuProvider) {
@ -309,12 +310,17 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
provider.collectObjectsFromPoint(point, tileBox, objects, true); provider.collectObjectsFromPoint(point, tileBox, objects, true);
for (Object o : objects) { for (Object o : objects) {
if (provider.isObjectClickable(o)) { if (provider.isObjectClickable(o)) {
latLon = provider.getObjectLocation(o); LatLon latLon = provider.getObjectLocation(o);
PointDescription name = null;
if (o instanceof FavouritePoint) {
name = ((FavouritePoint) o).getPointDescription(mapView.getApplication());
}
return new Pair<>(latLon, name);
} }
} }
} }
} }
return latLon; return null;
} }
private void choosePointTypeAction(MapActivity mapActivity, LatLon latLon, PointType pointType, PointDescription pd, String address) { private void choosePointTypeAction(MapActivity mapActivity, LatLon latLon, PointType pointType, PointDescription pd, String address) {