diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index a1e257cef2..0001bfd9b2 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -1290,7 +1290,7 @@ public class GPXUtilities { return pt; } - public TrkSegment getTrkSegment() { + public TrkSegment getNonEmptyTrkSegment() { for (GPXUtilities.Track t : tracks) { for (TrkSegment s : t.segments) { if (s.points.size() > 0) { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/MapLayerMenuListener.java b/OsmAnd/src/net/osmand/plus/dialogs/MapLayerMenuListener.java index 053e2c7536..9234239040 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/MapLayerMenuListener.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/MapLayerMenuListener.java @@ -47,7 +47,7 @@ final class MapLayerMenuListener extends OnRowItemClick { GpxSelectionHelper selectedGpxHelper = mapActivity.getMyApplication().getSelectedGpxHelper(); List selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles(); - List files = GpxUiHelper.getSelectedTrackNames(mapActivity.getMyApplication()); + List files = GpxUiHelper.getSelectedTrackPaths(mapActivity.getMyApplication()); if (selectedGpxFiles.isEmpty()) { Map fls = selectedGpxHelper.getSelectedGpxFilesBackUp(); for (Map.Entry f : fls.entrySet()) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index da701851d1..e6a7677232 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -810,7 +810,7 @@ public class GpxUiHelper { } } - public static List getSelectedTrackNames(OsmandApplication app) { + public static List getSelectedTrackPaths(OsmandApplication app) { List trackNames = new ArrayList<>(); for (SelectedGpxFile file : app.getSelectedGpxHelper().getSelectedGPXFiles()) { trackNames.add(file.getGpxFile().path); diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index 43f51e40c1..3d63266db9 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -117,7 +117,7 @@ public class ImportHelper { public interface OnGpxImportCompleteListener { void onImportComplete(boolean success); - void onSavingComplete(boolean success, GPXFile result); + void onSaveComplete(boolean success, GPXFile result); } public ImportHelper(final AppCompatActivity activity, final OsmandApplication app, final OsmandMapTileView mapView) { @@ -1094,7 +1094,7 @@ public class ImportHelper { boolean success = Algorithms.isEmpty(warning); if (gpxImportCompleteListener != null) { - gpxImportCompleteListener.onSavingComplete(success, result); + gpxImportCompleteListener.onSaveComplete(success, result); } if (success) { if (showInDetailsActivity) { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 4c744dc74b..af0b256032 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -131,7 +131,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route private boolean progressBarVisible; private boolean pointsListOpened; private boolean planRouteMode = false; - private boolean attachToRoads; private Boolean saved; private boolean portrait; private boolean nightMode; @@ -159,10 +158,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route this.planRouteMode = planRouteMode; } - public void setAttachToRoads(boolean attachToRoads) { - this.attachToRoads = attachToRoads; - } - @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @@ -469,7 +464,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route if (editingCtx.isNewData() && planRouteMode) { StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), createStartPlanRouteListener()); - } else if (attachToRoads && !(editingCtx.isNewData() || editingCtx.hasRoutePoints() || editingCtx.isInSnapToRoadMode())) { + } else if (!(editingCtx.isNewData() || editingCtx.hasRoutePoints() || editingCtx.isInSnapToRoadMode())) { SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this); } } @@ -892,7 +887,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route public void addNewGpxData(GPXFile gpxFile) { QuadRect rect = gpxFile.getRect(); - TrkSegment segment = gpxFile.getTrkSegment(); + TrkSegment segment = gpxFile.getNonEmptyTrkSegment(); ActionType actionType = segment == null ? ActionType.ADD_ROUTE_POINTS : ActionType.EDIT_SEGMENT; NewGpxData newGpxData = new NewGpxData(gpxFile, rect, actionType, segment); @@ -1803,12 +1798,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route return showFragment(fragment, fragmentManager); } - public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx, - boolean planRoute, boolean attachToRoads) { + public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx, boolean planRoute) { MeasurementToolFragment fragment = new MeasurementToolFragment(); fragment.setEditingCtx(editingCtx); fragment.setPlanRouteMode(planRoute); - fragment.setAttachToRoads(attachToRoads); return showFragment(fragment, fragmentManager); } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java b/OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java index acd9077f17..de235b0dc5 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java @@ -172,7 +172,7 @@ public class StartPlanRouteBottomSheet extends MenuBottomSheetDialogFragment { } @Override - public void onSavingComplete(boolean success, GPXUtilities.GPXFile result) { + public void onSaveComplete(boolean success, GPXUtilities.GPXFile result) { } }); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java index f238464cba..f310802c44 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java @@ -136,7 +136,7 @@ public class FavoritesActivity extends TabActivity { } @Override - public void onSavingComplete(boolean success, GPXUtilities.GPXFile result) { + public void onSaveComplete(boolean success, GPXUtilities.GPXFile result) { } }); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java index 1084a664c8..1812fb3d2d 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java @@ -21,8 +21,8 @@ import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; -import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.TrkSegment; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.data.QuadRect; @@ -201,13 +201,13 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca boolean osmandRouter = mode.getRouteService() == RouteProvider.RouteService.OSMAND; if (rparams != null && osmandRouter) { // if (!routingHelper.isCurrentGPXRouteV2()) { - int textId = R.string.gpx_option_reverse_route; - String title = app.getString(textId); - LocalRoutingParameter parameter = new OtherLocalRoutingParameter(textId, title, rparams.isReverse()); + int textId = R.string.gpx_option_reverse_route; + String title = app.getString(textId); + LocalRoutingParameter parameter = new OtherLocalRoutingParameter(textId, title, rparams.isReverse()); - ReverseTrackCard reverseTrackCard = new ReverseTrackCard(mapActivity, parameter); - reverseTrackCard.setListener(this); - cardsContainer.addView(reverseTrackCard.build(mapActivity)); + ReverseTrackCard reverseTrackCard = new ReverseTrackCard(mapActivity, parameter); + reverseTrackCard.setListener(this); + cardsContainer.addView(reverseTrackCard.build(mapActivity)); // } if (!gpxFile.hasRtePt()) { AttachTrackToRoadsCard attachTrackCard = new AttachTrackToRoadsCard(mapActivity); @@ -226,7 +226,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR); - List selectedTrackNames = GpxUiHelper.getSelectedTrackNames(app); + List selectedTrackNames = GpxUiHelper.getSelectedTrackPaths(app); List list = GpxUiHelper.getSortedGPXFilesInfo(dir, selectedTrackNames, false); if (list.size() > 0) { String defaultCategory = app.getString(R.string.shared_string_all); @@ -346,12 +346,12 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca if (card instanceof ImportTrackCard) { importTrack(); } else if (card instanceof TrackEditCard) { - openPlanRoute(false); + openPlanRoute(true); close(); } else if (card instanceof SelectTrackCard) { updateSelectionMode(true); } else if (card instanceof AttachTrackToRoadsCard) { - openPlanRoute(true); + openPlanRoute(false); close(); } else if (card instanceof ReverseTrackCard || card instanceof NavigateTrackOptionsCard) { @@ -439,7 +439,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca } @Override - public void onSavingComplete(boolean success, GPXFile result) { + public void onSaveComplete(boolean success, GPXFile result) { if (success) { selectTrackToFollow(result); updateSelectionMode(false); @@ -456,17 +456,20 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca } } - public void openPlanRoute(boolean attachToRoads) { + public void openPlanRoute(boolean useAppMode) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null && gpxFile != null) { QuadRect rect = gpxFile.getRect(); - GPXUtilities.TrkSegment segment = gpxFile.getTrkSegment(); + TrkSegment segment = gpxFile.getNonEmptyTrkSegment(); ActionType actionType = segment == null ? ActionType.ADD_ROUTE_POINTS : ActionType.EDIT_SEGMENT; NewGpxData newGpxData = new NewGpxData(gpxFile, rect, actionType, segment); MeasurementEditingContext editingContext = new MeasurementEditingContext(); editingContext.setNewGpxData(newGpxData); - MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), editingContext, true, attachToRoads); + if (useAppMode) { + editingContext.setAppMode(app.getRoutingHelper().getAppMode()); + } + MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), editingContext, true); } }