Fix saved track name
This commit is contained in:
parent
c2146eb441
commit
41e4654a62
3 changed files with 30 additions and 6 deletions
|
@ -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,
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<GPXUtilities.WptPt> 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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue