Do not store appearance in the tags of gpx file

This commit is contained in:
Vitaliy 2020-12-02 16:02:06 +02:00
parent c484375d13
commit b82700c66b
4 changed files with 51 additions and 114 deletions

View file

@ -23,16 +23,15 @@ import net.osmand.PlatformUtil;
import net.osmand.StateChangedListener;
import net.osmand.data.LatLon;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.track.GpxSplitType;
import net.osmand.plus.track.GradientScaleType;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -60,17 +59,13 @@ public class GpxSelectionHelper {
private static final String BACKUP = "backup";
private static final String BACKUPMODIFIEDTIME = "backupTime";
private static final String COLOR = "color";
private static final String WIDTH = "width";
private static final String SELECTED_BY_USER = "selected_by_user";
private static final String SHOW_ARROWS = "show_arrows";
private static final String GRADIENT_SCALE_TYPE = "gradient_scale_type";
private static final String SHOW_START_FINISH = "show_start_finish";
private OsmandApplication app;
private SavingTrackHelper savingTrackHelper;
@NonNull
private List<SelectedGpxFile> selectedGPXFiles = new ArrayList<>();
private Map<GPXFile, Long> selectedGpxFilesBackUp = new HashMap<>();
private SavingTrackHelper savingTrackHelper;
private SelectGpxTask selectGpxTask;
private SelectedGpxFile trackToFollow;
private StateChangedListener<String> followTrackListener;
@ -231,22 +226,20 @@ public class GpxSelectionHelper {
List<GpxDisplayGroup> groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile);
GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(dataItem.getSplitType());
if (splitType != null) {
if (splitType == GpxSplitType.NO_SPLIT) {
for (GpxDisplayGroup model : groups) {
model.noSplit(app);
}
} else if (splitType == GpxSplitType.DISTANCE) {
for (GpxDisplayGroup model : groups) {
model.splitByDistance(app, dataItem.getSplitInterval(), dataItem.isJoinSegments());
}
} else if (splitType == GpxSplitType.TIME) {
for (GpxDisplayGroup model : groups) {
model.splitByTime(app, (int) dataItem.getSplitInterval(), dataItem.isJoinSegments());
}
if (splitType == GpxSplitType.NO_SPLIT) {
for (GpxDisplayGroup model : groups) {
model.noSplit(app);
}
} else if (splitType == GpxSplitType.DISTANCE) {
for (GpxDisplayGroup model : groups) {
model.splitByDistance(app, dataItem.getSplitInterval(), dataItem.isJoinSegments());
}
} else if (splitType == GpxSplitType.TIME) {
for (GpxDisplayGroup model : groups) {
model.splitByTime(app, (int) dataItem.getSplitInterval(), dataItem.isJoinSegments());
}
selectedGpxFile.setDisplayGroups(groups, app);
}
selectedGpxFile.setDisplayGroups(groups, app);
}
}
return true;
@ -579,24 +572,6 @@ public class GpxSelectionHelper {
int clr = parseColor(obj.getString(COLOR));
gpx.setColor(clr);
}
for (GradientScaleType scaleType : GradientScaleType.values()) {
if (obj.has(scaleType.getColorTypeName())) {
int clr = parseColor(obj.getString(scaleType.getColorTypeName()));
gpx.setGradientScaleColor(scaleType.getColorTypeName(), clr);
}
}
if (obj.has(SHOW_ARROWS)) {
gpx.setShowArrows(obj.optBoolean(SHOW_ARROWS, false));
}
if (obj.has(GRADIENT_SCALE_TYPE)) {
gpx.setGradientScaleType(obj.optString(GRADIENT_SCALE_TYPE));
}
if (obj.has(SHOW_START_FINISH)) {
gpx.setShowStartFinish(obj.optBoolean(SHOW_START_FINISH, true));
}
if (obj.has(WIDTH)) {
gpx.setWidth(obj.getString(WIDTH));
}
if (gpx.error != null) {
save = true;
} else if (obj.has(BACKUP)) {
@ -644,20 +619,6 @@ public class GpxSelectionHelper {
if (s.gpxFile.getColor(0) != 0) {
obj.put(COLOR, Algorithms.colorToString(s.gpxFile.getColor(0)));
}
if (s.gpxFile.getWidth(null) != null) {
obj.put(WIDTH, s.gpxFile.getWidth(null));
}
if (s.gpxFile.getGradientScaleType() != null) {
obj.put(GRADIENT_SCALE_TYPE, s.gpxFile.getGradientScaleType());
}
obj.put(SHOW_ARROWS, s.gpxFile.isShowArrows());
obj.put(SHOW_START_FINISH, s.gpxFile.isShowStartFinish());
for (GradientScaleType scaleType : GradientScaleType.values()) {
int gradientScaleColor = s.gpxFile.getGradientScaleColor(scaleType.getColorTypeName(), 0);
if (gradientScaleColor != 0) {
obj.put(scaleType.getColorTypeName(), Algorithms.colorToString(gradientScaleColor));
}
}
}
obj.put(SELECTED_BY_USER, s.selectedByUser);
} catch (JSONException e) {
@ -710,23 +671,6 @@ public class GpxSelectionHelper {
if (dataItem.getColor() != 0) {
gpx.setColor(dataItem.getColor());
}
if (dataItem.getGradientSpeedColor() != 0) {
gpx.setGradientScaleColor(GradientScaleType.SPEED.getColorTypeName(), dataItem.getGradientSpeedColor());
}
if (dataItem.getGradientAltitudeColor() != 0) {
gpx.setGradientScaleColor(GradientScaleType.ALTITUDE.getColorTypeName(), dataItem.getGradientAltitudeColor());
}
if (dataItem.getGradientSlopeColor() != 0) {
gpx.setGradientScaleColor(GradientScaleType.SLOPE.getColorTypeName(), dataItem.getGradientSlopeColor());
}
if (dataItem.getGradientScaleType() != null) {
gpx.setGradientScaleType(dataItem.getGradientScaleType().getTypeName());
}
if (dataItem.getWidth() != null) {
gpx.setWidth(dataItem.getWidth());
}
gpx.setShowArrows(dataItem.isShowArrows());
gpx.setShowStartFinish(dataItem.isShowStartFinish());
sf.setJoinSegments(dataItem.isJoinSegments());
}
sf.setGpxFile(gpx, app);

View file

@ -36,13 +36,14 @@ public enum GpxSplitType {
return ctx.getString(resId);
}
@NonNull
public static GpxSplitType getSplitTypeByName(@NonNull String name) {
for (GpxSplitType splitType : GpxSplitType.values()) {
if (splitType.name().equalsIgnoreCase(name)) {
return splitType;
}
}
return null;
return NO_SPLIT;
}
public static GpxSplitType getSplitTypeByTypeId(int typeId) {
@ -51,6 +52,6 @@ public enum GpxSplitType {
return splitType;
}
}
return null;
return NO_SPLIT;
}
}

View file

@ -28,6 +28,7 @@ import net.osmand.PlatformUtil;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxDbHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
@ -70,6 +71,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
private static final String SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY = "showStartFinishIconsInitialValueKey";
private OsmandApplication app;
private GpxDbHelper gpxDbHelper;
@Nullable
private GpxDataItem gpxDataItem;
@ -128,6 +130,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = requireMyApplication();
gpxDbHelper = app.getGpxDbHelper();
Bundle arguments = getArguments();
if (savedInstanceState != null) {
@ -138,7 +141,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(trackDrawInfo.getFilePath());
}
if (!selectedGpxFile.isShowCurrentTrack()) {
gpxDataItem = app.getGpxDbHelper().getItem(new File(trackDrawInfo.getFilePath()));
gpxDataItem = gpxDbHelper.getItem(new File(trackDrawInfo.getFilePath()));
}
showStartFinishIconsInitialValue = savedInstanceState.getBoolean(SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY,
app.getSettings().SHOW_START_FINISH_ICONS.get());
@ -160,7 +163,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
trackDrawInfo.setShowStartFinish(app.getSettings().CURRENT_TRACK_SHOW_START_FINISH.get());
selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
} else {
gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFilePath));
gpxDataItem = gpxDbHelper.getItem(new File(gpxFilePath));
trackDrawInfo = new TrackDrawInfo(app, gpxDataItem, false);
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath);
}
@ -527,10 +530,10 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
}
private void saveCustomColorsToTracks(int prevColor, int newColor) {
List<GpxDataItem> gpxDataItems = app.getGpxDbHelper().getItems();
List<GpxDataItem> gpxDataItems = gpxDbHelper.getItems();
for (GpxDataItem dataItem : gpxDataItems) {
if (prevColor == dataItem.getColor()) {
app.getGpxDbHelper().updateColor(dataItem, newColor);
gpxDbHelper.updateColor(dataItem, newColor);
}
}
List<SelectedGpxFile> files = app.getSelectedGpxHelper().getSelectedGPXFiles();
@ -554,36 +557,19 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
private void saveTrackInfo() {
GPXFile gpxFile = selectedGpxFile.getGpxFile();
gpxFile.setWidth(trackDrawInfo.getWidth());
if (trackDrawInfo.getGradientScaleType() != null) {
gpxFile.setGradientScaleType(trackDrawInfo.getGradientScaleType().name());
} else {
gpxFile.removeGradientScaleType();
}
gpxFile.setColor(trackDrawInfo.getColor());
GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(trackDrawInfo.getSplitType());
if (splitType != null) {
gpxFile.setSplitType(splitType.getTypeName());
}
gpxFile.setSplitInterval(trackDrawInfo.getSplitInterval());
gpxFile.setShowArrows(trackDrawInfo.isShowArrows());
//gpxFile.setShowStartFinish(trackDrawInfo.isShowStartFinish());
if (gpxFile.showCurrentTrack) {
app.getSettings().CURRENT_TRACK_COLOR.set(trackDrawInfo.getColor());
app.getSettings().CURRENT_TRACK_WIDTH.set(trackDrawInfo.getWidth());
app.getSettings().CURRENT_TRACK_SHOW_ARROWS.set(trackDrawInfo.isShowArrows());
app.getSettings().CURRENT_TRACK_SHOW_START_FINISH.set(trackDrawInfo.isShowStartFinish());
} else {
if (gpxDataItem != null) {
gpxDataItem = new GpxDataItem(new File(gpxFile.path), gpxFile);
app.getGpxDbHelper().add(gpxDataItem);
}
app.getSelectedGpxHelper().updateSelectedGpxFile(selectedGpxFile);
saveGpx(gpxFile);
} else if (gpxDataItem != null) {
GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(trackDrawInfo.getSplitType());
gpxDbHelper.updateColor(gpxDataItem, trackDrawInfo.getColor());
gpxDbHelper.updateWidth(gpxDataItem, trackDrawInfo.getWidth());
gpxDbHelper.updateShowArrows(gpxDataItem, trackDrawInfo.isShowArrows());
// gpxDbHelper.updateShowStartFinish(gpxDataItem, trackDrawInfo.isShowStartFinish());
gpxDbHelper.updateSplit(gpxDataItem, splitType, trackDrawInfo.getSplitInterval());
gpxDbHelper.updateGradientScaleType(gpxDataItem, trackDrawInfo.getGradientScaleType());
}
}
@ -594,9 +580,6 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
double distanceSplit = gpxDataItem.getSplitInterval();
GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(gpxDataItem.getSplitType());
if (splitType == null) {
splitType = GpxSplitType.NO_SPLIT;
}
applySplit(splitType, timeSplit, distanceSplit);
}
}
@ -633,10 +616,6 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
timeSplit, distanceSplit).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private void saveGpx(final GPXFile gpxFile) {
new SaveGpxAsyncTask(gpxFile, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private void setupCards() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {

View file

@ -33,6 +33,8 @@ import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxDbHelper;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
@ -69,6 +71,7 @@ import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -106,8 +109,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
private TrackDrawInfo trackDrawInfo;
private TrackChartPoints trackChartPoints;
private GpxSelectionHelper selectedGpxHelper;
private GpxDbHelper gpxDbHelper;
private MapMarkersHelper mapMarkersHelper;
private GpxSelectionHelper selectedGpxHelper;
private List<WptPt> cache = new ArrayList<>();
private Map<WptPt, SelectedGpxFile> pointFileMap = new HashMap<>();
private MapTextLayer textLayer;
@ -144,6 +149,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
gpxDbHelper = view.getApplication().getGpxDbHelper();
selectedGpxHelper = view.getApplication().getSelectedGpxHelper();
mapMarkersHelper = view.getApplication().getMapMarkersHelper();
osmandRenderer = view.getApplication().getResourceManager().getRenderer().getRenderer();
@ -694,13 +700,16 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
private String getTrackWidthName(GPXFile gpxFile, String defaultWidth) {
String width;
String width = null;
if (hasTrackDrawInfoForTrack(gpxFile)) {
width = trackDrawInfo.getWidth();
} else if (gpxFile.showCurrentTrack) {
width = currentTrackWidthPref.get();
} else {
width = gpxFile.getWidth(defaultWidth);
GpxDataItem dataItem = gpxDbHelper.getItem(new File(gpxFile.path));
if (dataItem != null) {
width = dataItem.getWidth();
}
}
return width != null ? width : defaultWidth;
}
@ -711,7 +720,11 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
} else if (gpxFile.showCurrentTrack) {
return currentTrackShowArrowsPref.get();
} else {
return gpxFile.isShowArrows();
GpxDataItem dataItem = gpxDbHelper.getItem(new File(gpxFile.path));
if (dataItem != null) {
return dataItem.isShowArrows();
}
return false;
}
}