Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
81739b11d2
4 changed files with 78 additions and 25 deletions
|
@ -90,25 +90,15 @@ public class MapMarkersHelper {
|
|||
|
||||
if (colorIndex != mapMarker.colorIndex) return false;
|
||||
if (pos != mapMarker.pos) return false;
|
||||
//if (index != mapMarker.index) return false;
|
||||
//if (history != mapMarker.history) return false;
|
||||
//if (selected != mapMarker.selected) return false;
|
||||
//if (dist != mapMarker.dist) return false;
|
||||
return point.equals(mapMarker.point);
|
||||
//return pointDescription != null ? pointDescription.equals(mapMarker.pointDescription) : mapMarker.pointDescription == null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = point.hashCode();
|
||||
result = 31 * result + (pointDescription != null ? pointDescription.hashCode() : 0);
|
||||
result = 31 * result + colorIndex;
|
||||
result = 31 * result + pos;
|
||||
result = 31 * result + index;
|
||||
result = 31 * result + (history ? 1 : 0);
|
||||
result = 31 * result + (selected ? 1 : 0);
|
||||
result = 31 * result + dist;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,11 +26,16 @@ public class TargetPointsHelper {
|
|||
private OsmandSettings settings;
|
||||
private RoutingHelper routingHelper;
|
||||
private List<StateChangedListener<Void>> listeners = new ArrayList<>();
|
||||
private List<TargetPointChangedListener> pointListeners = new ArrayList<>();
|
||||
private OsmandApplication ctx;
|
||||
|
||||
private AddressLookupRequest startPointRequest;
|
||||
private AddressLookupRequest targetPointRequest;
|
||||
|
||||
public interface TargetPointChangedListener {
|
||||
void onTargetPointChanged(TargetPoint targetPoint);
|
||||
}
|
||||
|
||||
public static class TargetPoint implements LocationPoint {
|
||||
public LatLon point;
|
||||
private PointDescription pointDescription;
|
||||
|
@ -49,7 +54,30 @@ public class TargetPointsHelper {
|
|||
this.index = index;
|
||||
this.intermediate = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
TargetPoint targetPoint = (TargetPoint) o;
|
||||
|
||||
if (start != targetPoint.start) return false;
|
||||
if (intermediate != targetPoint.intermediate) return false;
|
||||
if (index != targetPoint.index) return false;
|
||||
return point.equals(targetPoint.point);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = point.hashCode();
|
||||
result = 31 * result + index;
|
||||
result = 31 * result + (start ? 10 : 20);
|
||||
result = 31 * result + (intermediate ? 100 : 200);
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
public PointDescription getPointDescription(Context ctx) {
|
||||
if (!intermediate) {
|
||||
|
@ -154,6 +182,7 @@ public class TargetPointsHelper {
|
|||
settings.updateIntermediatePoint(p.point.getLatitude(), p.point.getLongitude(),
|
||||
p.pointDescription);
|
||||
updateRouteAndRefresh(false);
|
||||
updateTargetPoint(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -176,6 +205,7 @@ public class TargetPointsHelper {
|
|||
settings.setPointToStart(pointToStart.point.getLatitude(), pointToStart.point.getLongitude(),
|
||||
pointToStart.pointDescription);
|
||||
updateRouteAndRefresh(false);
|
||||
updateTargetPoint(pointToStart);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
|
@ -196,6 +226,7 @@ public class TargetPointsHelper {
|
|||
settings.setPointToNavigate(pointToNavigate.point.getLatitude(), pointToNavigate.point.getLongitude(),
|
||||
pointToNavigate.pointDescription);
|
||||
updateRouteAndRefresh(false);
|
||||
updateTargetPoint(pointToNavigate);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
|
@ -558,4 +589,20 @@ public class TargetPointsHelper {
|
|||
ctx.getGeocodingLookupService().cancel(latLon);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPointListener(TargetPointChangedListener l) {
|
||||
if (!pointListeners.contains(l)) {
|
||||
pointListeners.add(l);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePointListener(TargetPointChangedListener l) {
|
||||
pointListeners.remove(l);
|
||||
}
|
||||
|
||||
private void updateTargetPoint(TargetPoint targetPoint) {
|
||||
for (TargetPointChangedListener l : pointListeners) {
|
||||
l.onTargetPointChanged(targetPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
||||
import net.osmand.plus.TargetPointsHelper.TargetPointChangedListener;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.dashboard.DashboardOnMap;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
|
@ -49,7 +50,7 @@ import java.lang.ref.WeakReference;
|
|||
import java.util.List;
|
||||
|
||||
public class MapContextMenu extends MenuTitleController implements StateChangedListener<ApplicationMode>,
|
||||
MapMarkerChangedListener {
|
||||
MapMarkerChangedListener, TargetPointChangedListener {
|
||||
|
||||
private MapActivity mapActivity;
|
||||
private OsmandSettings settings;
|
||||
|
@ -80,6 +81,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
private MenuAction searchDoneAction;
|
||||
|
||||
public MapContextMenu() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapActivity getMapActivity() {
|
||||
return mapActivity;
|
||||
|
@ -214,9 +218,6 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
return menuController;
|
||||
}
|
||||
|
||||
public MapContextMenu() {
|
||||
}
|
||||
|
||||
public boolean init(@NonNull LatLon latLon,
|
||||
@Nullable PointDescription pointDescription,
|
||||
@Nullable Object object) {
|
||||
|
@ -281,6 +282,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
if (object instanceof MapMarker) {
|
||||
mapActivity.getMyApplication().getMapMarkersHelper().addListener(this);
|
||||
} else if (object instanceof TargetPoint) {
|
||||
mapActivity.getMyApplication().getTargetPointsHelper().addPointListener(this);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -382,13 +385,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
@Override
|
||||
public void onMapMarkerChanged(MapMarker mapMarker) {
|
||||
if (object.equals(mapMarker)) {
|
||||
if (object != null && object.equals(mapMarker)) {
|
||||
String address = mapMarker.getOnlyName();
|
||||
nameStr = address;
|
||||
pointDescription.setName(address);
|
||||
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
|
||||
if (fragmentRef != null)
|
||||
fragmentRef.get().refreshTitle();
|
||||
updateTitle(address);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -396,6 +395,22 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
public void onMapMarkersChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTargetPointChanged(TargetPoint targetPoint) {
|
||||
if (object != null && object.equals(targetPoint)) {
|
||||
String address = targetPoint.getOnlyName();
|
||||
updateTitle(address);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTitle(String address) {
|
||||
nameStr = address;
|
||||
pointDescription.setName(address);
|
||||
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
|
||||
if (fragmentRef != null)
|
||||
fragmentRef.get().refreshTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged(ApplicationMode change) {
|
||||
appModeChanged = active;
|
||||
|
|
|
@ -268,14 +268,15 @@ public class PointNavigationLayer extends OsmandMapLayer implements
|
|||
public void applyNewObjectPosition(@NonNull Object o, @NonNull LatLon position,
|
||||
@Nullable ContextMenuLayer.ApplyMovedObjectCallback callback) {
|
||||
boolean result = false;
|
||||
TargetPoint newTargetPoint = null;
|
||||
if (o instanceof TargetPoint) {
|
||||
TargetPoint point = (TargetPoint) o;
|
||||
TargetPointsHelper tph = map.getMyApplication().getTargetPointsHelper();
|
||||
tph.navigateToPoint(position, true, -1, point.getPointDescription(map));
|
||||
TargetPointsHelper targetPointsHelper = map.getMyApplication().getTargetPointsHelper();
|
||||
targetPointsHelper.navigateToPoint(position, true, -1, new PointDescription(PointDescription.POINT_TYPE_LOCATION, ""));
|
||||
newTargetPoint = targetPointsHelper.getPointToNavigate();
|
||||
result = true;
|
||||
}
|
||||
if (callback != null) {
|
||||
callback.onApplyMovedObject(result, o);
|
||||
callback.onApplyMovedObject(result, newTargetPoint == null ? o : newTargetPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue