Remove unnecessary setters from GpxDataItem

This commit is contained in:
Vitaliy 2020-07-13 12:03:20 +03:00
parent 4eabba3489
commit b7c1fe6ba7
5 changed files with 32 additions and 56 deletions

View file

@ -1,6 +1,8 @@
package net.osmand; package net.osmand;
import com.sun.istack.internal.NotNull;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -1540,8 +1542,8 @@ public class GPXUtilities {
return null; return null;
} }
public void setGradientScaleType(GradientScaleType gradientScaleType) { public void setGradientScaleType(@NotNull GradientScaleType gradientScaleType) {
getExtensionsToWrite().put("gradient_scale_type", gradientScaleType != null ? gradientScaleType.name() : null); getExtensionsToWrite().put("gradient_scale_type", gradientScaleType.name());
} }
public GpxSplitType getSplitType() { public GpxSplitType getSplitType() {
@ -1558,8 +1560,8 @@ public class GPXUtilities {
return null; return null;
} }
public void setSplitType(GpxSplitType gpxSplitType) { public void setSplitType(@NotNull GpxSplitType gpxSplitType) {
getExtensionsToWrite().put("split_type", gpxSplitType != null ? gpxSplitType.name() : null); getExtensionsToWrite().put("split_type", gpxSplitType.name());
} }
public double getSplitInterval() { public double getSplitInterval() {

View file

@ -3,6 +3,7 @@ package net.osmand.plus;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXFile.GradientScaleType;
import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
@ -198,6 +199,22 @@ public class GPXDatabase {
this.color = color; this.color = color;
} }
public GpxDataItem(File file, @NonNull GPXUtilities.GPXFile gpxFile) {
this.file = file;
color = gpxFile.getColor(0);
width = gpxFile.getWidth(null);
showArrows = gpxFile.isShowArrows();
showStartFinish = gpxFile.isShowStartFinish();
gradientScaleType = gpxFile.getGradientScaleType();
gradientSpeedColor = gpxFile.getGradientScaleColor(GradientScaleType.SPEED, 0);
gradientSlopeColor = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE, 0);
gradientAltitudeColor = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE, 0);
if (gpxFile.getSplitType() != null && gpxFile.getSplitInterval() != 0) {
splitType = gpxFile.getSplitType().getType();
splitInterval = gpxFile.getSplitInterval();
}
}
public File getFile() { public File getFile() {
return file; return file;
} }
@ -215,41 +232,22 @@ public class GPXDatabase {
return gradientScaleType; return gradientScaleType;
} }
public void setGradientScaleType(GradientScaleType gradientScaleType) {
this.gradientScaleType = gradientScaleType;
}
public int getGradientSpeedColor() { public int getGradientSpeedColor() {
return gradientSpeedColor; return gradientSpeedColor;
} }
public void setGradientSpeedColor(int gradientSpeedColor) {
this.gradientSpeedColor = gradientSpeedColor;
}
public int getGradientAltitudeColor() { public int getGradientAltitudeColor() {
return gradientAltitudeColor; return gradientAltitudeColor;
} }
public void setGradientAltitudeColor(int gradientAltitudeColor) {
this.gradientAltitudeColor = gradientAltitudeColor;
}
public int getGradientSlopeColor() { public int getGradientSlopeColor() {
return gradientSlopeColor; return gradientSlopeColor;
} }
public void setGradientSlopeColor(int gradientSlopeColor) {
this.gradientSlopeColor = gradientSlopeColor;
}
public String getWidth() { public String getWidth() {
return width; return width;
} }
public void setWidth(String width) {
this.width = width;
}
public long getFileLastModifiedTime() { public long getFileLastModifiedTime() {
return fileLastModifiedTime; return fileLastModifiedTime;
@ -283,26 +281,14 @@ public class GPXDatabase {
return joinSegments; return joinSegments;
} }
public void setJoinSegments(boolean joinSegments) {
this.joinSegments = joinSegments;
}
public boolean isShowArrows() { public boolean isShowArrows() {
return showArrows; return showArrows;
} }
public void setShowArrows(boolean showArrows) {
this.showArrows = showArrows;
}
public boolean isShowStartFinish() { public boolean isShowStartFinish() {
return showStartFinish; return showStartFinish;
} }
public void setShowStartFinish(boolean showStartFinish) {
this.showStartFinish = showStartFinish;
}
@Override @Override
public int hashCode() { public int hashCode() {
return file != null ? file.hashCode() : 0; return file != null ? file.hashCode() : 0;
@ -562,7 +548,7 @@ public class GPXDatabase {
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_ARROWS + " = ? " + db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_ARROWS + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[] {showArrows ? 1 : 0, fileName, fileDir}); new Object[] {showArrows ? 1 : 0, fileName, fileDir});
item.setShowArrows(showArrows); item.showArrows = showArrows;
} finally { } finally {
db.close(); db.close();
} }
@ -580,7 +566,7 @@ public class GPXDatabase {
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_START_FINISH + " = ? " + db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_START_FINISH + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[] {showStartFinish ? 1 : 0, fileName, fileDir}); new Object[] {showStartFinish ? 1 : 0, fileName, fileDir});
item.setShowStartFinish(showStartFinish); item.showStartFinish = showStartFinish;
} finally { } finally {
db.close(); db.close();
} }
@ -636,7 +622,7 @@ public class GPXDatabase {
GPX_COL_JOIN_SEGMENTS + " = ? " + GPX_COL_JOIN_SEGMENTS + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[]{joinSegments ? 1 : 0, fileName, fileDir}); new Object[]{joinSegments ? 1 : 0, fileName, fileDir});
item.setJoinSegments(joinSegments); item.joinSegments = joinSegments;
} finally { } finally {
db.close(); db.close();
} }

View file

@ -189,7 +189,7 @@ public class GpxDbHelper {
} }
private void readGpxItem(@NonNull File gpxFile, @Nullable GpxDataItem item, @Nullable GpxDataItemCallback callback) { private void readGpxItem(@NonNull File gpxFile, @Nullable GpxDataItem item, @Nullable GpxDataItemCallback callback) {
readingItemsMap.put(gpxFile, item != null ? item : new GpxDataItem(null, null)); readingItemsMap.put(gpxFile, item != null ? item : new GpxDataItem(null, (GPXTrackAnalysis) null));
if (callback != null) { if (callback != null) {
readingItemsCallbacks.put(gpxFile, callback); readingItemsCallbacks.put(gpxFile, callback);
} }

View file

@ -23,7 +23,6 @@ import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXFile.GradientScaleType;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
@ -33,7 +32,7 @@ import net.osmand.data.FavouritePoint.BackgroundType;
import net.osmand.plus.AppInitializer; import net.osmand.plus.AppInitializer;
import net.osmand.plus.CustomOsmandPlugin; import net.osmand.plus.CustomOsmandPlugin;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXDatabase; import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -1018,21 +1017,10 @@ public class ImportHelper {
gpxFile.path = toWrite.getAbsolutePath(); gpxFile.path = toWrite.getAbsolutePath();
File file = new File(gpxFile.path); File file = new File(gpxFile.path);
if (!destinationExists) { if (!destinationExists) {
GPXDatabase.GpxDataItem item = new GPXDatabase.GpxDataItem(file, gpxFile.getColor(0)); GpxDataItem item = new GpxDataItem(file, gpxFile);
item.setWidth(gpxFile.getWidth(null));
item.setShowArrows(gpxFile.isShowArrows());
item.setShowStartFinish(gpxFile.isShowStartFinish());
item.setGradientScaleType(gpxFile.getGradientScaleType());
item.setGradientSpeedColor(gpxFile.getGradientScaleColor(GradientScaleType.SPEED, 0));
item.setGradientSlopeColor(gpxFile.getGradientScaleColor(GradientScaleType.SLOPE, 0));
item.setGradientAltitudeColor(gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE, 0));
app.getGpxDbHelper().add(item); app.getGpxDbHelper().add(item);
if (gpxFile.getSplitType() != null && gpxFile.getSplitInterval() != 0) {
app.getGpxDbHelper().updateSplit(item, gpxFile.getSplitType(), gpxFile.getSplitInterval());
}
} else { } else {
GPXDatabase.GpxDataItem item = app.getGpxDbHelper().getItem(file); GpxDataItem item = app.getGpxDbHelper().getItem(file);
if (item != null) { if (item != null) {
app.getGpxDbHelper().clearAnalysis(item); app.getGpxDbHelper().clearAnalysis(item);
} }

View file

@ -266,7 +266,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
shadowPaint.setStrokeWidth(paint.getStrokeWidth() + 2 * shadowRadius); shadowPaint.setStrokeWidth(paint.getStrokeWidth() + 2 * shadowRadius);
} }
for (String key : cachedTrackWidth.keySet()) { for (String key : cachedTrackWidth.keySet()) {
searchTrackWidth(key, rrs, req, rc); acquireTrackWidth(key, rrs, req, rc);
} }
} else { } else {
log.error("Rendering attribute gpx is not found !"); log.error("Rendering attribute gpx is not found !");
@ -284,7 +284,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
return cachedColor; return cachedColor;
} }
private void searchTrackWidth(String widthKey, RenderingRulesStorage rrs, RenderingRuleSearchRequest req, RenderingContext rc) { private void acquireTrackWidth(String widthKey, RenderingRulesStorage rrs, RenderingRuleSearchRequest req, RenderingContext rc) {
if (!Algorithms.isEmpty(widthKey) && Algorithms.isInt(widthKey)) { if (!Algorithms.isEmpty(widthKey) && Algorithms.isInt(widthKey)) {
try { try {
int widthDp = Integer.parseInt(widthKey); int widthDp = Integer.parseInt(widthKey);