diff --git a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java index ea2869aaa3..bff9377ec3 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java @@ -119,9 +119,11 @@ public class Algorithms { } public static String getFileNameWithoutExtension(String name) { - int i = name.lastIndexOf('.'); - if (i >= 0) { - name = name.substring(0, i); + if (name != null) { + int index = name.lastIndexOf('.'); + if (index != -1) { + return name.substring(0, index); + } } return name; } diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 740c826ab5..0efdd133f3 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -153,16 +153,6 @@ public class AndroidUtils { R.color.icon_color_default_light, R.color.wikivoyage_active_dark); } - public static String trimExtension(String src) { - if (src != null) { - int index = src.lastIndexOf('.'); - if (index != -1) { - return src.substring(0, index); - } - } - return src; - } - public static String addColon(OsmandApplication app, @StringRes int stringRes) { return app.getString(R.string.ltr_or_rtl_combine_via_colon, app.getString(stringRes), "").trim(); } diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 636fcddb72..c168047ba9 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -8,7 +8,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; -import net.osmand.AndroidUtils; import net.osmand.FileUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; @@ -526,7 +525,7 @@ public class MapMarkersHelper { private MapMarkersGroup createGPXMarkerGroup(File fl) { return new MapMarkersGroup(getMarkerGroupId(fl), - AndroidUtils.trimExtension(fl.getName()), + Algorithms.getFileNameWithoutExtension(fl.getName()), MapMarkersGroup.GPX_TYPE); } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/GpxApproximationFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/GpxApproximationFragment.java index 87edaaf71b..924cea3ab0 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/GpxApproximationFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/GpxApproximationFragment.java @@ -298,13 +298,15 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment return (menuState & (MenuState.HEADER_ONLY | MenuState.HALF_SCREEN)) != 0; } - public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment, @NonNull LocationsHolder locationsHolder) { + public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment, + @NonNull LocationsHolder locationsHolder, @Nullable ApplicationMode appMode) { try { if (!fm.isStateSaved()) { GpxApproximationFragment fragment = new GpxApproximationFragment(); fragment.setRetainInstance(true); fragment.setTargetFragment(targetFragment, REQUEST_CODE); fragment.setLocationsHolder(locationsHolder); + fragment.setSnapToRoadAppMode(appMode); fm.beginTransaction() .replace(R.id.fragmentContainer, fragment, TAG) .addToBackStack(TAG) @@ -348,12 +350,19 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment @Override public void onProfileSelect(ApplicationMode applicationMode) { - if (snapToRoadAppMode != applicationMode) { - snapToRoadAppMode = applicationMode; + if (setSnapToRoadAppMode(applicationMode)) { calculateGpxApproximation(); } } + public boolean setSnapToRoadAppMode(ApplicationMode appMode) { + if (appMode != null && snapToRoadAppMode != appMode) { + snapToRoadAppMode = appMode; + return true; + } + return false; + } + public LocationsHolder getLocationsHolder() { return locationsHolder; } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 7d6818a9d6..42b176201b 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -706,8 +706,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route case SnapTrackWarningFragment.CONTINUE_RESULT_CODE: MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { + ApplicationMode mode = editingCtx.getAppMode(); + if (mode == ApplicationMode.DEFAULT || "public_transport".equals(mode.getRoutingProfile())) { + mode = null; + } GpxApproximationFragment.showInstance(mapActivity.getSupportFragmentManager(), - this, new LocationsHolder(editingCtx.getPoints())); + this, new LocationsHolder(editingCtx.getPoints()), mode); } break; } @@ -1522,7 +1526,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date()); displayedName = FileUtils.createUniqueFileName(requireMyApplication(), suggestedName, GPX_INDEX_DIR, GPX_FILE_EXT); } else { - displayedName = AndroidUtils.trimExtension(new File(gpxData.getGpxFile().path).getName()); + displayedName = Algorithms.getFileNameWithoutExtension(new File(gpxData.getGpxFile().path).getName()); } return displayedName; }