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.widgets.TextViewExProgress;
import static net.osmand.plus.track.TrackMenuFragment.startNavigationForGPX;
public class MapRouteInfoMenuFragment extends ContextMenuFragment implements TrackSelectSegmentBottomSheet.OnSegmentSelectedListener {
public static final String TAG = MapRouteInfoMenuFragment.class.getName();
@ -508,18 +510,16 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment implements Tra
@Override
public void onSegmentSelect(GPXUtilities.GPXFile gpxFile, int selectedSegment) {
if (getMyApplication() != null) {
getMyApplication().getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment);
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
TrackMenuFragment.startNavigationForGPX(gpxFile, mapActivity.getMapActions(), mapActivity);
GPXRouteParams.GPXRouteParamsBuilder paramsBuilder = getMyApplication().getRoutingHelper().getCurrentGPXRoute();
if (paramsBuilder != null) {
paramsBuilder.setSelectedSegment(selectedSegment);
getMyApplication().getRoutingHelper().onSettingsChanged(true);
}
dismiss();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMyApplication().getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment);
startNavigationForGPX(gpxFile, mapActivity.getMapActions(), mapActivity);
GPXRouteParams.GPXRouteParamsBuilder paramsBuilder = getMyApplication().getRoutingHelper().getCurrentGPXRoute();
if (paramsBuilder != null) {
paramsBuilder.setSelectedSegment(selectedSegment);
getMyApplication().getRoutingHelper().onSettingsChanged(true);
}
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) {
if (mapActivity.getMyApplication().getRoutingHelper().isFollowingMode()) {
final WeakReference<MapActivity> activityRef = new WeakReference<>(mapActivity);
mapActions.stopNavigationActionConfirm(null, new Runnable() {
@Override
public void run() {
if (mapActivity != null) {
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null,
MapActivity activity = activityRef.get();
if (activity != null) {
activity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null,
null, null, true, true, MenuState.HEADER_ONLY);
}
}