Select current navigation profile in attach roads

This commit is contained in:
Vitaliy 2020-09-23 23:18:44 +03:00
parent 1f65840dd4
commit 95af82e531
5 changed files with 24 additions and 20 deletions

View file

@ -119,9 +119,11 @@ public class Algorithms {
} }
public static String getFileNameWithoutExtension(String name) { public static String getFileNameWithoutExtension(String name) {
int i = name.lastIndexOf('.'); if (name != null) {
if (i >= 0) { int index = name.lastIndexOf('.');
name = name.substring(0, i); if (index != -1) {
return name.substring(0, index);
}
} }
return name; return name;
} }

View file

@ -153,16 +153,6 @@ public class AndroidUtils {
R.color.icon_color_default_light, R.color.wikivoyage_active_dark); 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) { public static String addColon(OsmandApplication app, @StringRes int stringRes) {
return app.getString(R.string.ltr_or_rtl_combine_via_colon, app.getString(stringRes), "").trim(); return app.getString(R.string.ltr_or_rtl_combine_via_colon, app.getString(stringRes), "").trim();
} }

View file

@ -8,7 +8,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.FileUtils; import net.osmand.FileUtils;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
@ -526,7 +525,7 @@ public class MapMarkersHelper {
private MapMarkersGroup createGPXMarkerGroup(File fl) { private MapMarkersGroup createGPXMarkerGroup(File fl) {
return new MapMarkersGroup(getMarkerGroupId(fl), return new MapMarkersGroup(getMarkerGroupId(fl),
AndroidUtils.trimExtension(fl.getName()), Algorithms.getFileNameWithoutExtension(fl.getName()),
MapMarkersGroup.GPX_TYPE); MapMarkersGroup.GPX_TYPE);
} }

View file

@ -298,13 +298,15 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
return (menuState & (MenuState.HEADER_ONLY | MenuState.HALF_SCREEN)) != 0; 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 { try {
if (!fm.isStateSaved()) { if (!fm.isStateSaved()) {
GpxApproximationFragment fragment = new GpxApproximationFragment(); GpxApproximationFragment fragment = new GpxApproximationFragment();
fragment.setRetainInstance(true); fragment.setRetainInstance(true);
fragment.setTargetFragment(targetFragment, REQUEST_CODE); fragment.setTargetFragment(targetFragment, REQUEST_CODE);
fragment.setLocationsHolder(locationsHolder); fragment.setLocationsHolder(locationsHolder);
fragment.setSnapToRoadAppMode(appMode);
fm.beginTransaction() fm.beginTransaction()
.replace(R.id.fragmentContainer, fragment, TAG) .replace(R.id.fragmentContainer, fragment, TAG)
.addToBackStack(TAG) .addToBackStack(TAG)
@ -348,12 +350,19 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
@Override @Override
public void onProfileSelect(ApplicationMode applicationMode) { public void onProfileSelect(ApplicationMode applicationMode) {
if (snapToRoadAppMode != applicationMode) { if (setSnapToRoadAppMode(applicationMode)) {
snapToRoadAppMode = applicationMode;
calculateGpxApproximation(); calculateGpxApproximation();
} }
} }
public boolean setSnapToRoadAppMode(ApplicationMode appMode) {
if (appMode != null && snapToRoadAppMode != appMode) {
snapToRoadAppMode = appMode;
return true;
}
return false;
}
public LocationsHolder getLocationsHolder() { public LocationsHolder getLocationsHolder() {
return locationsHolder; return locationsHolder;
} }

View file

@ -706,8 +706,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
case SnapTrackWarningFragment.CONTINUE_RESULT_CODE: case SnapTrackWarningFragment.CONTINUE_RESULT_CODE:
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
ApplicationMode mode = editingCtx.getAppMode();
if (mode == ApplicationMode.DEFAULT || "public_transport".equals(mode.getRoutingProfile())) {
mode = null;
}
GpxApproximationFragment.showInstance(mapActivity.getSupportFragmentManager(), GpxApproximationFragment.showInstance(mapActivity.getSupportFragmentManager(),
this, new LocationsHolder(editingCtx.getPoints())); this, new LocationsHolder(editingCtx.getPoints()), mode);
} }
break; 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()); String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date());
displayedName = FileUtils.createUniqueFileName(requireMyApplication(), suggestedName, GPX_INDEX_DIR, GPX_FILE_EXT); displayedName = FileUtils.createUniqueFileName(requireMyApplication(), suggestedName, GPX_INDEX_DIR, GPX_FILE_EXT);
} else { } else {
displayedName = AndroidUtils.trimExtension(new File(gpxData.getGpxFile().path).getName()); displayedName = Algorithms.getFileNameWithoutExtension(new File(gpxData.getGpxFile().path).getName());
} }
return displayedName; return displayedName;
} }