Introduce typeName for GpxSplitType and add getters for GpxSplitType and GradientScaleType

This commit is contained in:
Vitaliy 2020-07-21 11:52:43 +03:00
parent de5e161095
commit 3cab3ffa91
7 changed files with 90 additions and 62 deletions

View file

@ -210,26 +210,19 @@ public class GPXDatabase {
width = gpxFile.getWidth(null); width = gpxFile.getWidth(null);
showArrows = gpxFile.isShowArrows(); showArrows = gpxFile.isShowArrows();
showStartFinish = gpxFile.isShowStartFinish(); showStartFinish = gpxFile.isShowStartFinish();
gradientSpeedColor = gpxFile.getGradientScaleColor(GradientScaleType.SPEED.getTypeName(), 0); gradientSpeedColor = gpxFile.getGradientScaleColor(GradientScaleType.SPEED.getColorTypeName(), 0);
gradientSlopeColor = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE.getTypeName(), 0); gradientSlopeColor = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE.getColorTypeName(), 0);
gradientAltitudeColor = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE.getTypeName(), 0); gradientAltitudeColor = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE.getColorTypeName(), 0);
if (!Algorithms.isEmpty(gpxFile.getSplitType()) && gpxFile.getSplitInterval() != 0) { if (!Algorithms.isEmpty(gpxFile.getSplitType()) && gpxFile.getSplitInterval() > 0) {
for (GpxSplitType gpxSplitType : GpxSplitType.values()) { GpxSplitType gpxSplitType = GpxSplitType.getSplitTypeByName(gpxFile.getSplitType());
if (gpxSplitType.name().equalsIgnoreCase(gpxFile.getSplitType())) { if (gpxSplitType != null) {
splitType = gpxSplitType.getType(); splitType = gpxSplitType.getType();
splitInterval = gpxFile.getSplitInterval(); splitInterval = gpxFile.getSplitInterval();
break;
}
} }
} }
if (!Algorithms.isEmpty(gpxFile.getGradientScaleType())) { if (!Algorithms.isEmpty(gpxFile.getGradientScaleType())) {
for (GradientScaleType scaleType : GradientScaleType.values()) { gradientScaleType = GradientScaleType.getGradientTypeByName(gpxFile.getGradientScaleType());
if (scaleType.name().equalsIgnoreCase(gpxFile.getGradientScaleType())) {
gradientScaleType = scaleType;
break;
}
}
} }
} }
@ -547,7 +540,7 @@ public class GPXDatabase {
String fileDir = getFileDir(item.file); String fileDir = getFileDir(item.file);
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_GRADIENT_SCALE_TYPE + " = ? " + db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_GRADIENT_SCALE_TYPE + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[] {(gradientScaleType == null ? "" : gradientScaleType.name()), fileName, fileDir}); new Object[] {(gradientScaleType == null ? "" : gradientScaleType.getTypeName()), fileName, fileDir});
item.gradientScaleType = gradientScaleType; item.gradientScaleType = gradientScaleType;
} finally { } finally {
db.close(); db.close();
@ -723,7 +716,7 @@ public class GPXDatabase {
} else { } else {
color = Algorithms.colorToString(item.color); color = Algorithms.colorToString(item.color);
} }
String gradientScaleType = item.gradientScaleType != null ? item.gradientScaleType.name() : null; String gradientScaleType = item.gradientScaleType != null ? item.gradientScaleType.getTypeName() : null;
if (a != null) { if (a != null) {
db.execSQL( db.execSQL(
"INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", "INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",

View file

@ -173,20 +173,22 @@ public class GpxSelectionHelper {
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) { if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
GPXFile gpxFile = selectedGpxFile.getGpxFile(); GPXFile gpxFile = selectedGpxFile.getGpxFile();
List<GpxDisplayGroup> groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile); List<GpxDisplayGroup> groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile);
if (dataItem.getSplitType() == GpxSplitType.NO_SPLIT.getType()) {
GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(dataItem.getSplitType());
if (splitType != null) {
if (splitType == GpxSplitType.NO_SPLIT) {
for (GpxDisplayGroup model : groups) { for (GpxDisplayGroup model : groups) {
model.noSplit(app); model.noSplit(app);
} }
selectedGpxFile.setDisplayGroups(groups, app); } else if (splitType == GpxSplitType.DISTANCE) {
} else if (dataItem.getSplitType() == GpxSplitType.DISTANCE.getType()) {
for (GpxDisplayGroup model : groups) { for (GpxDisplayGroup model : groups) {
model.splitByDistance(app, dataItem.getSplitInterval(), dataItem.isJoinSegments()); model.splitByDistance(app, dataItem.getSplitInterval(), dataItem.isJoinSegments());
} }
selectedGpxFile.setDisplayGroups(groups, app); } else if (splitType == GpxSplitType.TIME) {
} else if (dataItem.getSplitType() == GpxSplitType.TIME.getType()) {
for (GpxDisplayGroup model : groups) { for (GpxDisplayGroup model : groups) {
model.splitByTime(app, (int) dataItem.getSplitInterval(), dataItem.isJoinSegments()); model.splitByTime(app, (int) dataItem.getSplitInterval(), dataItem.isJoinSegments());
} }
}
selectedGpxFile.setDisplayGroups(groups, app); selectedGpxFile.setDisplayGroups(groups, app);
} }
} }
@ -522,9 +524,9 @@ public class GpxSelectionHelper {
gpx.setColor(clr); gpx.setColor(clr);
} }
for (GradientScaleType scaleType : GradientScaleType.values()) { for (GradientScaleType scaleType : GradientScaleType.values()) {
if (obj.has(scaleType.getTypeName())) { if (obj.has(scaleType.getColorTypeName())) {
int clr = Algorithms.parseColor(obj.getString(scaleType.getTypeName())); int clr = Algorithms.parseColor(obj.getString(scaleType.getColorTypeName()));
gpx.setGradientScaleColor(scaleType.getTypeName(), clr); gpx.setGradientScaleColor(scaleType.getColorTypeName(), clr);
} }
} }
if (obj.has(SHOW_ARROWS)) { if (obj.has(SHOW_ARROWS)) {
@ -587,9 +589,9 @@ public class GpxSelectionHelper {
obj.put(SHOW_ARROWS, s.gpxFile.isShowArrows()); obj.put(SHOW_ARROWS, s.gpxFile.isShowArrows());
obj.put(SHOW_START_FINISH, s.gpxFile.isShowStartFinish()); obj.put(SHOW_START_FINISH, s.gpxFile.isShowStartFinish());
for (GradientScaleType scaleType : GradientScaleType.values()) { for (GradientScaleType scaleType : GradientScaleType.values()) {
int gradientScaleColor = s.gpxFile.getGradientScaleColor(scaleType.getTypeName(), 0); int gradientScaleColor = s.gpxFile.getGradientScaleColor(scaleType.getColorTypeName(), 0);
if (gradientScaleColor != 0) { if (gradientScaleColor != 0) {
obj.put(scaleType.getTypeName(), Algorithms.colorToString(gradientScaleColor)); obj.put(scaleType.getColorTypeName(), Algorithms.colorToString(gradientScaleColor));
} }
} }
} }
@ -645,16 +647,16 @@ public class GpxSelectionHelper {
gpx.setColor(dataItem.getColor()); gpx.setColor(dataItem.getColor());
} }
if (dataItem.getGradientSpeedColor() != 0) { if (dataItem.getGradientSpeedColor() != 0) {
gpx.setGradientScaleColor(GradientScaleType.SPEED.getTypeName(), dataItem.getGradientSpeedColor()); gpx.setGradientScaleColor(GradientScaleType.SPEED.getColorTypeName(), dataItem.getGradientSpeedColor());
} }
if (dataItem.getGradientAltitudeColor() != 0) { if (dataItem.getGradientAltitudeColor() != 0) {
gpx.setGradientScaleColor(GradientScaleType.ALTITUDE.getTypeName(), dataItem.getGradientAltitudeColor()); gpx.setGradientScaleColor(GradientScaleType.ALTITUDE.getColorTypeName(), dataItem.getGradientAltitudeColor());
} }
if (dataItem.getGradientSlopeColor() != 0) { if (dataItem.getGradientSlopeColor() != 0) {
gpx.setGradientScaleColor(GradientScaleType.SLOPE.getTypeName(), dataItem.getGradientSlopeColor()); gpx.setGradientScaleColor(GradientScaleType.SLOPE.getColorTypeName(), dataItem.getGradientSlopeColor());
} }
if (dataItem.getGradientScaleType() != null) { if (dataItem.getGradientScaleType() != null) {
gpx.setGradientScaleType(dataItem.getGradientScaleType().name()); gpx.setGradientScaleType(dataItem.getGradientScaleType().getTypeName());
} }
if (dataItem.getWidth() != null) { if (dataItem.getWidth() != null) {
gpx.setWidth(dataItem.getWidth()); gpx.setWidth(dataItem.getWidth());

View file

@ -9,15 +9,17 @@ import net.osmand.plus.R;
public enum GpxSplitType { public enum GpxSplitType {
NO_SPLIT(-1, R.string.shared_string_none), NO_SPLIT("no_split", -1, R.string.shared_string_none),
DISTANCE(1, R.string.distance), DISTANCE("distance", 1, R.string.distance),
TIME(2, R.string.shared_string_time); TIME("time", 2, R.string.shared_string_time);
private String typeName;
private int type; private int type;
@StringRes @StringRes
private int resId; private int resId;
GpxSplitType(int type, @StringRes int resId) { GpxSplitType(@NonNull String typeName, int type, @StringRes int resId) {
this.typeName = typeName;
this.type = type; this.type = type;
this.resId = resId; this.resId = resId;
} }
@ -26,7 +28,29 @@ public enum GpxSplitType {
return type; return type;
} }
public String getTypeName() {
return typeName;
}
public String getHumanString(@NonNull Context ctx) { public String getHumanString(@NonNull Context ctx) {
return ctx.getString(resId); return ctx.getString(resId);
} }
public static GpxSplitType getSplitTypeByName(@NonNull String name) {
for (GpxSplitType splitType : GpxSplitType.values()) {
if (splitType.name().equalsIgnoreCase(name)) {
return splitType;
}
}
return null;
}
public static GpxSplitType getSplitTypeByTypeId(int typeId) {
for (GpxSplitType splitType : GpxSplitType.values()) {
if (splitType.getType() == typeId) {
return splitType;
}
}
return null;
}
} }

View file

@ -10,18 +10,20 @@ import net.osmand.plus.R;
public enum GradientScaleType { public enum GradientScaleType {
SPEED("gradient_speed_color", R.string.map_widget_speed, R.drawable.ic_action_speed), SPEED("speed", "gradient_speed_color", R.string.map_widget_speed, R.drawable.ic_action_speed),
ALTITUDE("gradient_altitude_color", R.string.altitude, R.drawable.ic_action_altitude_average), ALTITUDE("altitude", "gradient_altitude_color", R.string.altitude, R.drawable.ic_action_altitude_average),
SLOPE("gradient_slope_color", R.string.shared_string_slope, R.drawable.ic_action_altitude_ascent); SLOPE("slope", "gradient_slope_color", R.string.shared_string_slope, R.drawable.ic_action_altitude_ascent);
private String typeName; private String typeName;
private String colorTypeName;
@StringRes @StringRes
private int resId; private int resId;
@DrawableRes @DrawableRes
private int iconId; private int iconId;
GradientScaleType(@NonNull String typeName, @StringRes int resId, @DrawableRes int iconId) { GradientScaleType(@NonNull String typeName, @NonNull String colorTypeName, @StringRes int resId, @DrawableRes int iconId) {
this.typeName = typeName; this.typeName = typeName;
this.colorTypeName = colorTypeName;
this.resId = resId; this.resId = resId;
this.iconId = iconId; this.iconId = iconId;
} }
@ -30,6 +32,10 @@ public enum GradientScaleType {
return typeName; return typeName;
} }
public String getColorTypeName() {
return colorTypeName;
}
public int getIconId() { public int getIconId() {
return iconId; return iconId;
} }
@ -37,4 +43,13 @@ public enum GradientScaleType {
public String getHumanString(@NonNull Context ctx) { public String getHumanString(@NonNull Context ctx) {
return ctx.getString(resId); return ctx.getString(resId);
} }
public static GradientScaleType getGradientTypeByName(@NonNull String name) {
for (GradientScaleType scaleType : GradientScaleType.values()) {
if (scaleType.name().equalsIgnoreCase(name)) {
return scaleType;
}
}
return null;
}
} }

View file

@ -311,11 +311,9 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
} }
gpxFile.setColor(trackDrawInfo.getColor()); gpxFile.setColor(trackDrawInfo.getColor());
for (GpxSplitType gpxSplitType : GpxSplitType.values()) { GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(trackDrawInfo.getSplitType());
if (gpxSplitType.getType() == trackDrawInfo.getSplitType()) { if (splitType != null) {
gpxFile.setSplitType(gpxSplitType.name()); gpxFile.setSplitType(splitType.getTypeName());
break;
}
} }
gpxFile.setSplitInterval(trackDrawInfo.getSplitInterval()); gpxFile.setSplitInterval(trackDrawInfo.getSplitInterval());
@ -334,12 +332,8 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
int timeSplit = (int) gpxDataItem.getSplitInterval(); int timeSplit = (int) gpxDataItem.getSplitInterval();
double distanceSplit = gpxDataItem.getSplitInterval(); double distanceSplit = gpxDataItem.getSplitInterval();
GpxSplitType splitType; GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(gpxDataItem.getSplitType());
if (gpxDataItem.getSplitType() == GpxSplitType.DISTANCE.getType()) { if (splitType == null) {
splitType = GpxSplitType.DISTANCE;
} else if (gpxDataItem.getSplitType() == GpxSplitType.TIME.getType()) {
splitType = GpxSplitType.TIME;
} else {
splitType = GpxSplitType.NO_SPLIT; splitType = GpxSplitType.NO_SPLIT;
} }
SplitTrackAsyncTask.SplitTrackListener splitTrackListener = new SplitTrackAsyncTask.SplitTrackListener() { SplitTrackAsyncTask.SplitTrackListener splitTrackListener = new SplitTrackAsyncTask.SplitTrackListener() {

View file

@ -72,7 +72,7 @@ public class TrackColoringCard extends BaseCard {
items.add(new TrackAppearanceItem(SOLID_COLOR, app.getString(R.string.track_coloring_solid), R.drawable.ic_action_circle)); items.add(new TrackAppearanceItem(SOLID_COLOR, app.getString(R.string.track_coloring_solid), R.drawable.ic_action_circle));
// for (GradientScaleType scaleType : GradientScaleType.values()) { // for (GradientScaleType scaleType : GradientScaleType.values()) {
// items.add(new TrackAppearanceItem(scaleType.name(), scaleType.getHumanString(app), scaleType.getIconId())); // items.add(new TrackAppearanceItem(scaleType.getTypeName(), scaleType.getHumanString(app), scaleType.getIconId()));
// } // }
return items; return items;
@ -139,7 +139,7 @@ public class TrackColoringCard extends BaseCard {
GradientScaleType scaleType = trackDrawInfo.getGradientScaleType(); GradientScaleType scaleType = trackDrawInfo.getGradientScaleType();
for (TrackAppearanceItem item : appearanceItems) { for (TrackAppearanceItem item : appearanceItems) {
if (scaleType == null && item.getAttrName().equals(SOLID_COLOR) if (scaleType == null && item.getAttrName().equals(SOLID_COLOR)
|| scaleType != null && scaleType.name().equals(item.getAttrName())) { || scaleType != null && scaleType.getTypeName().equals(item.getAttrName())) {
selectedAppearanceItem = item; selectedAppearanceItem = item;
break; break;
} }

View file

@ -123,7 +123,7 @@ public class TrackDrawInfo {
protected void saveToBundle(@NonNull Bundle bundle) { protected void saveToBundle(@NonNull Bundle bundle) {
bundle.putString(TRACK_FILE_PATH, filePath); bundle.putString(TRACK_FILE_PATH, filePath);
bundle.putString(TRACK_WIDTH, width); bundle.putString(TRACK_WIDTH, width);
bundle.putString(TRACK_GRADIENT_SCALE_TYPE, gradientScaleType != null ? gradientScaleType.name() : ""); bundle.putString(TRACK_GRADIENT_SCALE_TYPE, gradientScaleType != null ? gradientScaleType.getTypeName() : "");
bundle.putInt(TRACK_COLOR, color); bundle.putInt(TRACK_COLOR, color);
bundle.putInt(TRACK_SPLIT_TYPE, splitType); bundle.putInt(TRACK_SPLIT_TYPE, splitType);
bundle.putDouble(TRACK_SPLIT_INTERVAL, splitInterval); bundle.putDouble(TRACK_SPLIT_INTERVAL, splitInterval);