diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 3c95d75e9f..5ec4f28736 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -291,10 +291,12 @@ public class GpxSelectionHelper { return group; } - private String getGroupName(GPXFile g) { + public String getGroupName(GPXFile g) { String name = g.path; if (g.showCurrentTrack) { name = getString(R.string.shared_string_currently_recording_track); + } else if (Algorithms.isEmpty(name)) { + name = getString(R.string.current_route); } else { int i = name.lastIndexOf('/'); if (i >= 0) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index 87f9d4e579..c5eca0edb1 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -79,6 +79,7 @@ import net.osmand.plus.ContextMenuItem; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxDbHelper; import net.osmand.plus.GpxDbHelper.GpxDataItemCallback; +import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; @@ -2228,17 +2229,18 @@ public class GpxUiHelper { return dataSet; } - public static GpxDisplayItem makeGpxDisplayItem(OsmandApplication app, GPXUtilities.GPXFile gpx) { - GpxDisplayItem gpxItem = null; - String groupName = app.getString(R.string.current_route); - GpxDisplayGroup group = app.getSelectedGpxHelper().buildGpxDisplayGroup(gpx, 0, groupName); + public static GpxDisplayItem makeGpxDisplayItem(OsmandApplication app, GPXFile gpxFile) { + GpxSelectionHelper helper = app.getSelectedGpxHelper(); + String groupName = helper.getGroupName(gpxFile); + GpxDisplayGroup group = helper.buildGpxDisplayGroup(gpxFile, 0, groupName); if (group != null && group.getModifiableList().size() > 0) { - gpxItem = group.getModifiableList().get(0); + GpxDisplayItem gpxItem = group.getModifiableList().get(0); if (gpxItem != null) { gpxItem.route = true; } + return gpxItem; } - return gpxItem; + return null; } public static void saveAndShareGpx(@NonNull final Context context, @NonNull final GPXFile gpxFile) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java index 76b8ff1c7b..ef38b823ed 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java @@ -7,12 +7,13 @@ import android.os.AsyncTask; import androidx.annotation.NonNull; import net.osmand.AndroidUtils; -import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -24,7 +25,6 @@ import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.track.TrackMenuFragment; import net.osmand.util.Algorithms; -import java.io.File; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; @@ -93,27 +93,14 @@ public class SelectedGpxMenuController extends MenuController { @Override protected GpxSelectionHelper.GpxDisplayItem doInBackground(Void... voids) { - GpxSelectionHelper.GpxDisplayGroup gpxDisplayGroup = null; - GPXUtilities.GPXFile gpxFile = null; - GPXUtilities.Track generalTrack = null; - if (selectedGpxFile.getGpxFile().path != null) { - gpxFile = GPXUtilities.loadGPXFile(new File(selectedGpxFile.getGpxFile().path)); - } - if (gpxFile != null) { - generalTrack = gpxFile.getGeneralTrack(); - } - if (generalTrack != null) { - gpxFile.addGeneralTrack(); - gpxDisplayGroup = app.getSelectedGpxHelper().buildGeneralGpxDisplayGroup(gpxFile, generalTrack); - } else if (gpxFile != null && gpxFile.tracks.size() > 0) { - gpxDisplayGroup = app.getSelectedGpxHelper().buildGeneralGpxDisplayGroup(gpxFile, gpxFile.tracks.get(0)); - } - List items = null; - if (gpxDisplayGroup != null) { - items = gpxDisplayGroup.getModifiableList(); - } - if (items != null && items.size() > 0) { - return items.get(0); + GPXFile gpxFile = selectedGpxFile.getGpxFile(); + if (gpxFile.tracks.size() > 0) { + GpxDisplayGroup gpxDisplayGroup = app.getSelectedGpxHelper().buildGeneralGpxDisplayGroup(gpxFile, gpxFile.tracks.get(0)); + + List items = gpxDisplayGroup.getModifiableList(); + if (!Algorithms.isEmpty(items)) { + return items.get(0); + } } return null; } diff --git a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java index d4bef49ecf..f3048a2867 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java @@ -45,7 +45,6 @@ import java.util.Date; import java.util.List; import static net.osmand.plus.liveupdates.LiveUpdatesFragment.getDefaultIconColorId; -import static net.osmand.plus.myplaces.GPXTabItemType.GPX_TAB_ITEM_SPEED; public class GpxBlockStatisticsBuilder {