This commit is contained in:
Vitaliy 2021-04-20 17:54:22 +03:00
parent 658b157bb2
commit 7525c925ca
4 changed files with 21 additions and 31 deletions

View file

@ -291,10 +291,12 @@ public class GpxSelectionHelper {
return group; return group;
} }
private String getGroupName(GPXFile g) { public String getGroupName(GPXFile g) {
String name = g.path; String name = g.path;
if (g.showCurrentTrack) { if (g.showCurrentTrack) {
name = getString(R.string.shared_string_currently_recording_track); name = getString(R.string.shared_string_currently_recording_track);
} else if (Algorithms.isEmpty(name)) {
name = getString(R.string.current_route);
} else { } else {
int i = name.lastIndexOf('/'); int i = name.lastIndexOf('/');
if (i >= 0) { if (i >= 0) {

View file

@ -79,6 +79,7 @@ import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxDbHelper; import net.osmand.plus.GpxDbHelper;
import net.osmand.plus.GpxDbHelper.GpxDataItemCallback; import net.osmand.plus.GpxDbHelper.GpxDataItemCallback;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
@ -2228,17 +2229,18 @@ public class GpxUiHelper {
return dataSet; return dataSet;
} }
public static GpxDisplayItem makeGpxDisplayItem(OsmandApplication app, GPXUtilities.GPXFile gpx) { public static GpxDisplayItem makeGpxDisplayItem(OsmandApplication app, GPXFile gpxFile) {
GpxDisplayItem gpxItem = null; GpxSelectionHelper helper = app.getSelectedGpxHelper();
String groupName = app.getString(R.string.current_route); String groupName = helper.getGroupName(gpxFile);
GpxDisplayGroup group = app.getSelectedGpxHelper().buildGpxDisplayGroup(gpx, 0, groupName); GpxDisplayGroup group = helper.buildGpxDisplayGroup(gpxFile, 0, groupName);
if (group != null && group.getModifiableList().size() > 0) { if (group != null && group.getModifiableList().size() > 0) {
gpxItem = group.getModifiableList().get(0); GpxDisplayItem gpxItem = group.getModifiableList().get(0);
if (gpxItem != null) { if (gpxItem != null) {
gpxItem.route = true; gpxItem.route = true;
} }
return gpxItem;
} }
return gpxItem; return null;
} }
public static void saveAndShareGpx(@NonNull final Context context, @NonNull final GPXFile gpxFile) { public static void saveAndShareGpx(@NonNull final Context context, @NonNull final GPXFile gpxFile) {

View file

@ -7,12 +7,13 @@ import android.os.AsyncTask;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.GpxSelectionHelper; 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.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; 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.plus.track.TrackMenuFragment;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.io.File;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -93,27 +93,14 @@ public class SelectedGpxMenuController extends MenuController {
@Override @Override
protected GpxSelectionHelper.GpxDisplayItem doInBackground(Void... voids) { protected GpxSelectionHelper.GpxDisplayItem doInBackground(Void... voids) {
GpxSelectionHelper.GpxDisplayGroup gpxDisplayGroup = null; GPXFile gpxFile = selectedGpxFile.getGpxFile();
GPXUtilities.GPXFile gpxFile = null; if (gpxFile.tracks.size() > 0) {
GPXUtilities.Track generalTrack = null; GpxDisplayGroup gpxDisplayGroup = app.getSelectedGpxHelper().buildGeneralGpxDisplayGroup(gpxFile, gpxFile.tracks.get(0));
if (selectedGpxFile.getGpxFile().path != null) {
gpxFile = GPXUtilities.loadGPXFile(new File(selectedGpxFile.getGpxFile().path)); List<GpxDisplayItem> items = gpxDisplayGroup.getModifiableList();
} if (!Algorithms.isEmpty(items)) {
if (gpxFile != null) { return items.get(0);
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<GpxSelectionHelper.GpxDisplayItem> items = null;
if (gpxDisplayGroup != null) {
items = gpxDisplayGroup.getModifiableList();
}
if (items != null && items.size() > 0) {
return items.get(0);
} }
return null; return null;
} }

View file

@ -45,7 +45,6 @@ import java.util.Date;
import java.util.List; import java.util.List;
import static net.osmand.plus.liveupdates.LiveUpdatesFragment.getDefaultIconColorId; import static net.osmand.plus.liveupdates.LiveUpdatesFragment.getDefaultIconColorId;
import static net.osmand.plus.myplaces.GPXTabItemType.GPX_TAB_ITEM_SPEED;
public class GpxBlockStatisticsBuilder { public class GpxBlockStatisticsBuilder {