WeakReference - mapActivity, import header

This commit is contained in:
androiddevkotlin 2021-03-29 12:49:11 +03:00
parent 99c432d9ff
commit 03a450f9e2
2 changed files with 15 additions and 13 deletions

View file

@ -31,6 +31,8 @@ import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.plus.track.TrackSelectSegmentBottomSheet; import net.osmand.plus.track.TrackSelectSegmentBottomSheet;
import net.osmand.plus.widgets.TextViewExProgress; import net.osmand.plus.widgets.TextViewExProgress;
import static net.osmand.plus.track.TrackMenuFragment.startNavigationForGPX;
public class MapRouteInfoMenuFragment extends ContextMenuFragment implements TrackSelectSegmentBottomSheet.OnSegmentSelectedListener { public class MapRouteInfoMenuFragment extends ContextMenuFragment implements TrackSelectSegmentBottomSheet.OnSegmentSelectedListener {
public static final String TAG = MapRouteInfoMenuFragment.class.getName(); public static final String TAG = MapRouteInfoMenuFragment.class.getName();
@ -508,18 +510,16 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment implements Tra
@Override @Override
public void onSegmentSelect(GPXUtilities.GPXFile gpxFile, int selectedSegment) { public void onSegmentSelect(GPXUtilities.GPXFile gpxFile, int selectedSegment) {
if (getMyApplication() != null) { MapActivity mapActivity = getMapActivity();
getMyApplication().getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment); if (mapActivity != null) {
MapActivity mapActivity = getMapActivity(); mapActivity.getMyApplication().getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment);
if (mapActivity != null) { startNavigationForGPX(gpxFile, mapActivity.getMapActions(), mapActivity);
TrackMenuFragment.startNavigationForGPX(gpxFile, mapActivity.getMapActions(), mapActivity); GPXRouteParams.GPXRouteParamsBuilder paramsBuilder = getMyApplication().getRoutingHelper().getCurrentGPXRoute();
GPXRouteParams.GPXRouteParamsBuilder paramsBuilder = getMyApplication().getRoutingHelper().getCurrentGPXRoute(); if (paramsBuilder != null) {
if (paramsBuilder != null) { paramsBuilder.setSelectedSegment(selectedSegment);
paramsBuilder.setSelectedSegment(selectedSegment); getMyApplication().getRoutingHelper().onSettingsChanged(true);
getMyApplication().getRoutingHelper().onSettingsChanged(true);
}
dismiss();
} }
dismiss();
} }
} }
} }

View file

@ -906,11 +906,13 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
public static void startNavigationForGPX(final GPXFile gpxFile, MapActivityActions mapActions, final MapActivity mapActivity) { public static void startNavigationForGPX(final GPXFile gpxFile, MapActivityActions mapActions, final MapActivity mapActivity) {
if (mapActivity.getMyApplication().getRoutingHelper().isFollowingMode()) { if (mapActivity.getMyApplication().getRoutingHelper().isFollowingMode()) {
final WeakReference<MapActivity> activityRef = new WeakReference<>(mapActivity);
mapActions.stopNavigationActionConfirm(null, new Runnable() { mapActions.stopNavigationActionConfirm(null, new Runnable() {
@Override @Override
public void run() { public void run() {
if (mapActivity != null) { MapActivity activity = activityRef.get();
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null, if (activity != null) {
activity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null,
null, null, true, true, MenuState.HEADER_ONLY); null, null, true, true, MenuState.HEADER_ONLY);
} }
} }