Merge pull request #11480 from osmandapp/fix_11337

Fix_11337
This commit is contained in:
Vitaliy 2021-04-20 18:14:49 +03:00 committed by GitHub
commit f1756768ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 36 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,18 +2229,19 @@ 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) {
OsmandApplication app = (OsmandApplication) context.getApplicationContext(); OsmandApplication app = (OsmandApplication) context.getApplicationContext();

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,28 +93,15 @@ 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) {
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 items.get(0);
} }
}
return null; return null;
} }

View file

@ -83,7 +83,7 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
public static final String UPDATE_DYNAMIC_ITEMS = "update_dynamic_items"; public static final String UPDATE_DYNAMIC_ITEMS = "update_dynamic_items";
private static final int GPS_UPDATE_INTERVAL = 1000; private static final int GPS_UPDATE_INTERVAL = 1000;
public static final GPXTabItemType[] INIT_TAB_ITEMS = public static final GPXTabItemType[] INIT_TAB_ITEMS =
new GPXTabItemType[]{GPX_TAB_ITEM_GENERAL, GPX_TAB_ITEM_ALTITUDE, GPX_TAB_ITEM_SPEED}; new GPXTabItemType[] {GPX_TAB_ITEM_GENERAL, GPX_TAB_ITEM_ALTITUDE, GPX_TAB_ITEM_SPEED};
private OsmandApplication app; private OsmandApplication app;
private OsmandSettings settings; private OsmandSettings settings;
@ -651,7 +651,7 @@ public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment impl
} }
@Override @Override
public void openAnalyzeOnMap(GpxDisplayItem gpxItem) { public void openAnalyzeOnMap(@NonNull GpxDisplayItem gpxItem) {
} }
public interface DismissTargetFragment { public interface DismissTargetFragment {

View file

@ -2,6 +2,8 @@ package net.osmand.plus.myplaces;
import android.view.View; import android.view.View;
import androidx.annotation.NonNull;
import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
@ -19,5 +21,5 @@ public interface SegmentActionsListener {
void showOptionsPopupMenu(View view, TrkSegment trkSegment, boolean confirmDeletion, GpxDisplayItem gpxItem); void showOptionsPopupMenu(View view, TrkSegment trkSegment, boolean confirmDeletion, GpxDisplayItem gpxItem);
void openAnalyzeOnMap(GpxDisplayItem gpxItem); void openAnalyzeOnMap(@NonNull GpxDisplayItem gpxItem);
} }

View file

@ -292,7 +292,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
} }
@Override @Override
public void openAnalyzeOnMap(GpxDisplayItem gpxItem) { public void openAnalyzeOnMap(@NonNull GpxDisplayItem gpxItem) {
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
settings.setMapLocationToShow(gpxItem.locationOnMap.lat, gpxItem.locationOnMap.lon, settings.setMapLocationToShow(gpxItem.locationOnMap.lat, gpxItem.locationOnMap.lon,
settings.getLastKnownMapZoom(), settings.getLastKnownMapZoom(),

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 {

View file

@ -1131,7 +1131,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
} }
@Override @Override
public void openAnalyzeOnMap(GpxDisplayItem gpxItem) { public void openAnalyzeOnMap(@NonNull GpxDisplayItem gpxItem) {
if (gpxPoint != null) {
gpxItem.locationOnMap = gpxPoint.getSelectedPoint();
}
TrackDetailsMenu trackDetailsMenu = getMapActivity().getTrackDetailsMenu(); TrackDetailsMenu trackDetailsMenu = getMapActivity().getTrackDetailsMenu();
trackDetailsMenu.setGpxItem(gpxItem); trackDetailsMenu.setGpxItem(gpxItem);
trackDetailsMenu.setSelectedGpxFile(selectedGpxFile); trackDetailsMenu.setSelectedGpxFile(selectedGpxFile);