diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 916e279160..762ed0deb8 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -1514,26 +1514,6 @@ public class GPXUtilities { return new QuadRect(left, top, right, bottom); } - public enum GradientScaleType { - SPEED("gradient_speed_color"), - ALTITUDE("gradient_altitude_color"), - SLOPE("gradient_slope_color"); - - private String typeName; - - GradientScaleType(String typeName) { - this.typeName = typeName; - } - - public String getTypeName() { - return typeName; - } - } - - public void setGradientScaleColor(GradientScaleType gradientScaleType, int gradientScaleSpeedColor) { - getExtensionsToWrite().put(gradientScaleType.getTypeName(), Algorithms.colorToString(gradientScaleSpeedColor)); - } - public int getGradientScaleColor(GradientScaleType gradientScaleType, int defColor) { String clrValue = null; if (extensions != null) { @@ -1542,8 +1522,8 @@ public class GPXUtilities { return parseColor(clrValue, defColor); } - public void setGradientScaleType(GradientScaleType gradientScaleType) { - getExtensionsToWrite().put("gradient_scale_type", gradientScaleType != null ? gradientScaleType.name() : null); + public void setGradientScaleColor(GradientScaleType gradientScaleType, int gradientScaleColor) { + getExtensionsToWrite().put(gradientScaleType.getTypeName(), Algorithms.colorToString(gradientScaleColor)); } public GradientScaleType getGradientScaleType() { @@ -1560,6 +1540,46 @@ public class GPXUtilities { return null; } + public void setGradientScaleType(GradientScaleType gradientScaleType) { + getExtensionsToWrite().put("gradient_scale_type", gradientScaleType != null ? gradientScaleType.name() : null); + } + + public GpxSplitType getSplitType() { + if (extensions != null) { + String gradientScaleTypeName = extensions.get("split_type"); + if (!Algorithms.isEmpty(gradientScaleTypeName)) { + try { + return GpxSplitType.valueOf(gradientScaleTypeName); + } catch (IllegalArgumentException e) { + log.error("Error reading GpxSplitType", e); + } + } + } + return null; + } + + public void setSplitType(GpxSplitType gpxSplitType) { + getExtensionsToWrite().put("split_type", gpxSplitType != null ? gpxSplitType.name() : null); + } + + public double getSplitInterval() { + if (extensions != null) { + String splitIntervalStr = extensions.get("split_interval"); + if (!Algorithms.isEmpty(splitIntervalStr)) { + try { + return Double.parseDouble(splitIntervalStr); + } catch (NumberFormatException e) { + log.error("Error reading split_interval", e); + } + } + } + return 0; + } + + public void setSplitInterval(double splitInterval) { + getExtensionsToWrite().put("split_interval", String.valueOf(splitInterval)); + } + public String getWidth(String defWidth) { String widthValue = null; if (extensions != null) { @@ -1595,6 +1615,38 @@ public class GPXUtilities { public void setShowStartFinish(boolean showStartFinish) { getExtensionsToWrite().put("show_start_finish", String.valueOf(showStartFinish)); } + + public enum GradientScaleType { + SPEED("gradient_speed_color"), + ALTITUDE("gradient_altitude_color"), + SLOPE("gradient_slope_color"); + + private String typeName; + + GradientScaleType(String typeName) { + this.typeName = typeName; + } + + public String getTypeName() { + return typeName; + } + } + + public enum GpxSplitType { + NO_SPLIT(-1), + DISTANCE(1), + TIME(2); + + private int type; + + GpxSplitType(int type) { + this.type = type; + } + + public int getType() { + return type; + } + } } public static String asString(GPXFile file) { diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index 58f8cdf27f..dd573eba54 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -72,10 +72,6 @@ public class GPXDatabase { private static final String GPX_COL_GRADIENT_SCALE_TYPE = "gradientScaleType"; - public static final int GPX_SPLIT_TYPE_NO_SPLIT = -1; - public static final int GPX_SPLIT_TYPE_DISTANCE = 1; - public static final int GPX_SPLIT_TYPE_TIME = 2; - private static final String GPX_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + GPX_TABLE_NAME + " (" + GPX_COL_NAME + " TEXT, " + GPX_COL_DIR + " TEXT, " + diff --git a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java index 0762982a33..4f4c12c9a4 100644 --- a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java @@ -8,6 +8,7 @@ import androidx.annotation.Nullable; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.GPXFile.GpxSplitType; import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.plus.GPXDatabase.GpxDataItem; @@ -114,8 +115,8 @@ public class GpxDbHelper { return res; } - public boolean updateSplit(@NonNull GpxDataItem item, int splitType, double splitInterval) { - boolean res = db.updateSplit(item, splitType, splitInterval); + public boolean updateSplit(@NonNull GpxDataItem item, @NonNull GpxSplitType splitType, double splitInterval) { + boolean res = db.updateSplit(item, splitType.getType(), splitInterval); putToCache(item); return res; } diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 07a183712d..6f239e2286 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -11,6 +11,7 @@ import androidx.core.content.ContextCompat; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.GPXFile.GpxSplitType; import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.Route; @@ -172,17 +173,17 @@ public class GpxSelectionHelper { if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) { GPXFile gpxFile = selectedGpxFile.getGpxFile(); List groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile); - if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT) { + if (dataItem.getSplitType() == GpxSplitType.NO_SPLIT.getType()) { for (GpxDisplayGroup model : groups) { model.noSplit(app); } selectedGpxFile.setDisplayGroups(groups, app); - } else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) { + } else if (dataItem.getSplitType() == GpxSplitType.DISTANCE.getType()) { for (GpxDisplayGroup model : groups) { model.splitByDistance(app, dataItem.getSplitInterval(), dataItem.isJoinSegments()); } selectedGpxFile.setDisplayGroups(groups, app); - } else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_TIME) { + } else if (dataItem.getSplitType() == GpxSplitType.TIME.getType()) { for (GpxDisplayGroup model : groups) { model.splitByTime(app, (int) dataItem.getSplitInterval(), dataItem.isJoinSegments()); } diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index b5a9ee75e9..7bf86aff9e 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -1027,6 +1027,10 @@ public class ImportHelper { item.setGradientSlopeColor(gpxFile.getGradientScaleColor(GradientScaleType.SLOPE, 0)); item.setGradientAltitudeColor(gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE, 0)); app.getGpxDbHelper().add(item); + + if (gpxFile.getSplitType() != null && gpxFile.getSplitInterval() != 0) { + app.getGpxDbHelper().updateSplit(item, gpxFile.getSplitType(), gpxFile.getSplitInterval()); + } } else { GPXDatabase.GpxDataItem item = app.getGpxDbHelper().getItem(file); if (item != null) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index 0304618a7c..260d7fccda 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -39,12 +39,12 @@ import com.squareup.picasso.RequestCreator; import net.osmand.AndroidUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.GPXFile.GpxSplitType; import net.osmand.GPXUtilities.WptPt; import net.osmand.PicassoUtils; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; -import net.osmand.plus.GPXDatabase; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; @@ -764,9 +764,9 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { double splitInterval = getGpxDataItem().getSplitInterval(); int position = 0; - if (splitType == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) { + if (splitType == GpxSplitType.DISTANCE.getType()) { position = distanceSplit.indexOf(splitInterval); - } else if (splitType == GPXDatabase.GPX_SPLIT_TYPE_TIME) { + } else if (splitType == GpxSplitType.TIME.getType()) { position = timeSplit.indexOf((int) splitInterval); } @@ -877,20 +877,20 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } private void updateSplitInDatabase() { - int splitType = 0; double splitInterval = 0; + GpxSplitType splitType = null; if (selectedSplitInterval == 0) { - splitType = GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT; + splitType = GpxSplitType.NO_SPLIT; splitInterval = 0; } else if (distanceSplit.get(selectedSplitInterval) > 0) { - splitType = GPXDatabase.GPX_SPLIT_TYPE_DISTANCE; + splitType = GpxSplitType.DISTANCE; splitInterval = distanceSplit.get(selectedSplitInterval); } else if (timeSplit.get(selectedSplitInterval) > 0) { - splitType = GPXDatabase.GPX_SPLIT_TYPE_TIME; + splitType = GpxSplitType.TIME; splitInterval = timeSplit.get(selectedSplitInterval); } GpxDataItem item = getGpxDataItem(); - if (item != null) { + if (item != null && splitType != null) { app.getGpxDbHelper().updateSplit(item, splitType, splitInterval); } }