From 41e4654a626bf8d034ef9bb6daf2a7898beb83b9 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 25 Sep 2020 13:44:45 +0300 Subject: [PATCH] Fix saved track name --- .../routepreparationmenu/ChooseRouteFragment.java | 15 +++++++++++---- .../RouteOptionsBottomSheet.java | 11 +++++++++-- .../routepreparationmenu/cards/TracksCard.java | 10 ++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java index 62827e1e67..5c283c670d 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java @@ -37,6 +37,7 @@ import androidx.viewpager.widget.ViewPager; import net.osmand.AndroidUtils; import net.osmand.FileUtils; import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; import net.osmand.IndexConstants; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -482,12 +483,18 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe OsmandApplication app = mapActivity.getMyApplication(); GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute(); - String fileName; - if (paramsBuilder == null || paramsBuilder.getFile() == null || paramsBuilder.getFile().path == null) { + String fileName = null; + if (paramsBuilder != null && paramsBuilder.getFile() != null) { + GPXFile gpxFile = paramsBuilder.getFile(); + if (!Algorithms.isEmpty(gpxFile.path)) { + fileName = Algorithms.getFileNameWithoutExtension(new File(gpxFile.path).getName()); + } else if (!Algorithms.isEmpty(gpxFile.tracks)) { + fileName = gpxFile.tracks.get(0).name; + } + } + if (Algorithms.isEmpty(fileName)) { String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date()); fileName = FileUtils.createUniqueFileName(app, suggestedName, IndexConstants.GPX_INDEX_DIR, GPX_FILE_EXT); - } else { - fileName = Algorithms.getFileNameWithoutExtension(new File(paramsBuilder.getFile().path).getName()); } SaveAsNewTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), ChooseRouteFragment.this, null, fileName, diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index 0d23e78673..d18537bfb8 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -16,6 +16,7 @@ import androidx.core.content.ContextCompat; import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; +import net.osmand.GPXUtilities.GPXFile; import net.osmand.StateChangedListener; import net.osmand.plus.OsmAndLocationSimulation; import net.osmand.plus.OsmandApplication; @@ -47,6 +48,7 @@ import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.fragments.BaseSettingsFragment; import net.osmand.router.GeneralRouter; +import net.osmand.util.Algorithms; import java.io.File; import java.util.Arrays; @@ -342,14 +344,19 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { private BaseBottomSheetItem createGpxRoutingItem(final LocalRoutingParameter optionsItem) { RouteProvider.GPXRouteParamsBuilder routeParamsBuilder = mapActivity.getRoutingHelper().getCurrentGPXRoute(); - String description; + String description = null; int descriptionColorId; if (routeParamsBuilder == null) { descriptionColorId = nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light; description = mapActivity.getString(R.string.follow_track_descr); } else { descriptionColorId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; - description = new File(routeParamsBuilder.getFile().path).getName(); + GPXFile gpxFile = routeParamsBuilder.getFile(); + if (!Algorithms.isEmpty(gpxFile.path)) { + description = new File(gpxFile.path).getName(); + } else if (!Algorithms.isEmpty(gpxFile.tracks)) { + description = gpxFile.tracks.get(0).name; + } } return new BottomSheetItemWithDescription.Builder() diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java index 78bd52085e..3312371a56 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java @@ -12,6 +12,7 @@ import androidx.appcompat.view.ContextThemeWrapper; import androidx.core.content.ContextCompat; import net.osmand.AndroidUtils; +import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.IndexConstants; import net.osmand.plus.GPXDatabase.GpxDataItem; @@ -19,6 +20,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; +import net.osmand.plus.settings.backend.ApplicationMode; import java.io.File; import java.util.ArrayList; @@ -115,6 +117,14 @@ public class TracksCard extends BaseCard { v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + List points = item.file.getRoutePoints(); + if (!points.isEmpty()) { + ApplicationMode mode = ApplicationMode.valueOfStringKey(points.get(0).getProfileType(), null); + if (mode != null) { + app.getRoutingHelper().setAppMode(mode); + app.initVoiceCommandPlayer(mapActivity, mode, true, null, false, false, true); + } + } mapActivity.getMapActions().setGPXRouteParams(item.file); app.getTargetPointsHelper().updateRouteAndRefresh(true); }