Save split interval to database and retrieve from it
This commit is contained in:
parent
397d0a757e
commit
7f91b1274e
3 changed files with 102 additions and 33 deletions
|
@ -1,8 +1,9 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
|
||||
import net.osmand.plus.activities.TrackActivity;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -14,7 +15,7 @@ import java.util.List;
|
|||
public class GPXDatabase {
|
||||
|
||||
private static final String DB_NAME = "gpx_database";
|
||||
private static final int DB_VERSION = 3;
|
||||
private static final int DB_VERSION = 4;
|
||||
private static final String GPX_TABLE_NAME = "gpxTable";
|
||||
private static final String GPX_COL_NAME = "fileName";
|
||||
private static final String GPX_COL_DIR = "fileDir";
|
||||
|
@ -41,6 +42,13 @@ public class GPXDatabase {
|
|||
private static final String GPX_COL_COLOR = "color";
|
||||
private static final String GPX_COL_FILE_LAST_MODIFIED_TIME = "fileLastModifiedTime";
|
||||
|
||||
private static final String GPX_COL_SPLIT_TYPE = "splitType";
|
||||
private static final String GPX_COL_SPLIT_INTERVAL = "splitInterval";
|
||||
|
||||
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, " +
|
||||
|
@ -64,7 +72,9 @@ public class GPXDatabase {
|
|||
GPX_COL_POINTS + " int, " +
|
||||
GPX_COL_WPT_POINTS + " int, " +
|
||||
GPX_COL_COLOR + " TEXT, " +
|
||||
GPX_COL_FILE_LAST_MODIFIED_TIME + " long);";
|
||||
GPX_COL_FILE_LAST_MODIFIED_TIME + " long, " +
|
||||
GPX_COL_SPLIT_TYPE + " int, " +
|
||||
GPX_COL_SPLIT_INTERVAL + " double);";
|
||||
|
||||
private static final String GPX_TABLE_SELECT = "SELECT " +
|
||||
GPX_COL_NAME + ", " +
|
||||
|
@ -86,7 +96,9 @@ public class GPXDatabase {
|
|||
GPX_COL_POINTS + ", " +
|
||||
GPX_COL_WPT_POINTS + ", " +
|
||||
GPX_COL_COLOR + ", " +
|
||||
GPX_COL_FILE_LAST_MODIFIED_TIME +
|
||||
GPX_COL_FILE_LAST_MODIFIED_TIME + ", " +
|
||||
GPX_COL_SPLIT_TYPE + ", " +
|
||||
GPX_COL_SPLIT_INTERVAL +
|
||||
" FROM " + GPX_TABLE_NAME;
|
||||
|
||||
private OsmandApplication context;
|
||||
|
@ -96,6 +108,8 @@ public class GPXDatabase {
|
|||
private GPXTrackAnalysis analysis;
|
||||
private int color;
|
||||
private long fileLastModifiedTime;
|
||||
private int splitType;
|
||||
private double splitInterval;
|
||||
|
||||
public GpxDataItem(File file, GPXTrackAnalysis analysis) {
|
||||
this.file = file;
|
||||
|
@ -122,6 +136,14 @@ public class GPXDatabase {
|
|||
public long getFileLastModifiedTime() {
|
||||
return fileLastModifiedTime;
|
||||
}
|
||||
|
||||
public int getSplitType() {
|
||||
return splitType;
|
||||
}
|
||||
|
||||
public double getSplitInterval() {
|
||||
return splitInterval;
|
||||
}
|
||||
}
|
||||
|
||||
public GPXDatabase(OsmandApplication app) {
|
||||
|
@ -162,6 +184,10 @@ public class GPXDatabase {
|
|||
updateLastModifiedTime(item);
|
||||
}
|
||||
}
|
||||
if (oldVersion < 4) {
|
||||
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_TYPE + " int");
|
||||
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_INTERVAL + " double");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean updateLastModifiedTime(GpxDataItem item) {
|
||||
|
@ -224,6 +250,27 @@ public class GPXDatabase {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean updateSplit(GpxDataItem item, int splitType, double splitInterval) {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null){
|
||||
try {
|
||||
String fileName = getFileName(item.file);
|
||||
String fileDir = getFileDir(item.file);
|
||||
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " +
|
||||
GPX_COL_SPLIT_TYPE + " = ?, " +
|
||||
GPX_COL_SPLIT_INTERVAL + " = ? " +
|
||||
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
|
||||
new Object[] { splitType, splitInterval, fileName, fileDir });
|
||||
item.splitType = splitType;
|
||||
item.splitInterval = splitInterval;
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean remove(File file) {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null){
|
||||
|
@ -279,16 +326,16 @@ public class GPXDatabase {
|
|||
}
|
||||
if (a != null) {
|
||||
db.execSQL(
|
||||
"INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
"INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{ fileName, fileDir, a.totalDistance, a.totalTracks, a.startTime, a.endTime,
|
||||
a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown,
|
||||
a.avgElevation, a.minElevation, a.maxElevation, a.maxSpeed, a.avgSpeed, a.points, a.wptPoints,
|
||||
color, item.file.lastModified() });
|
||||
color, item.file.lastModified(), item.splitType, item.splitInterval });
|
||||
} else {
|
||||
db.execSQL(
|
||||
"INSERT INTO " + GPX_TABLE_NAME + "(" + GPX_COL_NAME + ", " + GPX_COL_DIR + ", " +
|
||||
GPX_COL_COLOR + ", " + GPX_COL_FILE_LAST_MODIFIED_TIME + ") VALUES (?, ?, ?, ?)",
|
||||
new Object[]{ fileName, fileDir, color, 0 });
|
||||
GPX_COL_COLOR + ", " + GPX_COL_FILE_LAST_MODIFIED_TIME + ", " + GPX_COL_SPLIT_TYPE + ", " + GPX_COL_SPLIT_INTERVAL + ") VALUES (?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{ fileName, fileDir, color, 0, item.splitType, item.splitInterval });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -351,6 +398,8 @@ public class GPXDatabase {
|
|||
int wptPoints = (int)query.getInt(17);
|
||||
String color = query.getString(18);
|
||||
long fileLastModifiedTime = query.getLong(19);
|
||||
int splitType = (int)query.getInt(20);
|
||||
double splitInterval = query.getDouble(21);
|
||||
|
||||
GPXTrackAnalysis a = new GPXTrackAnalysis();
|
||||
a.totalDistance = totalDistance;
|
||||
|
@ -384,6 +433,8 @@ public class GPXDatabase {
|
|||
item.color = 0;
|
||||
}
|
||||
item.fileLastModifiedTime = fileLastModifiedTime;
|
||||
item.splitType = splitType;
|
||||
item.splitInterval = splitInterval;
|
||||
return item;
|
||||
}
|
||||
|
||||
|
@ -409,13 +460,28 @@ public class GPXDatabase {
|
|||
public void processSplit() {
|
||||
List<GpxDataItem> items = getItems();
|
||||
for (GpxDataItem dataItem : items) {
|
||||
GpxSelectionHelper gpxSelectionHelper = context.getSelectedGpxHelper();
|
||||
GpxSelectionHelper.SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(dataItem.file.getAbsolutePath());
|
||||
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
|
||||
GPXUtilities.GPXFile gpxFile = selectedGpxFile.getGpxFile();
|
||||
List<GpxSelectionHelper.GpxDisplayGroup> groups = context.getSelectedGpxHelper().collectDisplayGroups(gpxFile);
|
||||
for (GpxSelectionHelper.GpxDisplayGroup group : groups) {
|
||||
|
||||
if (dataItem.getSplitType() != 0) {
|
||||
GpxSelectionHelper gpxSelectionHelper = context.getSelectedGpxHelper();
|
||||
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(dataItem.file.getAbsolutePath());
|
||||
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
|
||||
GPXUtilities.GPXFile gpxFile = selectedGpxFile.getGpxFile();
|
||||
List<GpxDisplayGroup> groups = context.getSelectedGpxHelper().collectDisplayGroups(gpxFile);
|
||||
if (dataItem.getSplitType() == GPX_SPLIT_TYPE_NO_SPLIT) {
|
||||
for (GpxDisplayGroup model : groups) {
|
||||
model.noSplit(context);
|
||||
}
|
||||
selectedGpxFile.setDisplayGroups(groups);
|
||||
} else if (dataItem.getSplitType() == GPX_SPLIT_TYPE_DISTANCE) {
|
||||
for (GpxDisplayGroup model : groups) {
|
||||
model.splitByDistance(context, dataItem.getSplitInterval());
|
||||
}
|
||||
selectedGpxFile.setDisplayGroups(groups);
|
||||
} else if (dataItem.getSplitType() == GPX_SPLIT_TYPE_TIME) {
|
||||
for (GpxDisplayGroup model : groups) {
|
||||
model.splitByTime(context, (int) dataItem.getSplitInterval());
|
||||
}
|
||||
selectedGpxFile.setDisplayGroups(groups);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -313,7 +313,7 @@ public class TrackSegmentFragment extends OsmAndListFragment {
|
|||
if (groups.size() > 0) {
|
||||
updateSplit(groups, vis.isChecked() ? sf : null);
|
||||
if (getGpxDataItem() != null) {
|
||||
// updateSplitInDatabase();
|
||||
updateSplitInDatabase();
|
||||
}
|
||||
}
|
||||
updateSplitIntervalView(splitIntervalView);
|
||||
|
@ -450,7 +450,7 @@ public class TrackSegmentFragment extends OsmAndListFragment {
|
|||
if (groups.size() > 0) {
|
||||
updateSplit(groups, vis.isChecked() ? sf : null);
|
||||
if (getGpxDataItem() != null) {
|
||||
// updateSplitInDatabase();
|
||||
updateSplitInDatabase();
|
||||
}
|
||||
}
|
||||
popup.dismiss();
|
||||
|
@ -472,27 +472,30 @@ public class TrackSegmentFragment extends OsmAndListFragment {
|
|||
}
|
||||
}
|
||||
|
||||
// private void updateSplitInDatabase() {
|
||||
// int splitType = -1;
|
||||
// double splitInterval = -1;
|
||||
// if (selectedSplitInterval == 0) {
|
||||
// splitType = GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT;
|
||||
// splitInterval = 0;
|
||||
// } else if (distanceSplit.get(selectedSplitInterval) > 0) {
|
||||
// splitType = GPXDatabase.GPX_SPLIT_TYPE_DISTANCE;
|
||||
// splitInterval = distanceSplit.get(selectedSplitInterval);
|
||||
// } else if (timeSplit.get(selectedSplitInterval) > 0) {
|
||||
// splitType = GPXDatabase.GPX_SPLIT_TYPE_TIME;
|
||||
// splitInterval = timeSplit.get(selectedSplitInterval);
|
||||
// }
|
||||
// app.getGpxDatabase().updateSplit(getGpxDataItem(), splitType, splitInterval);
|
||||
// }
|
||||
private void updateSplitInDatabase() {
|
||||
int splitType = 0;
|
||||
double splitInterval = 0;
|
||||
if (selectedSplitInterval == 0) {
|
||||
splitType = GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT;
|
||||
splitInterval = 0;
|
||||
} else if (distanceSplit.get(selectedSplitInterval) > 0) {
|
||||
splitType = GPXDatabase.GPX_SPLIT_TYPE_DISTANCE;
|
||||
splitInterval = distanceSplit.get(selectedSplitInterval);
|
||||
} else if (timeSplit.get(selectedSplitInterval) > 0) {
|
||||
splitType = GPXDatabase.GPX_SPLIT_TYPE_TIME;
|
||||
splitInterval = timeSplit.get(selectedSplitInterval);
|
||||
}
|
||||
app.getGpxDatabase().updateSplit(getGpxDataItem(), splitType, splitInterval);
|
||||
}
|
||||
|
||||
public void updateSplitView() {
|
||||
SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), ((SwitchCompat)headerView.findViewById(R.id.showOnMapToggle)).isChecked(), false);
|
||||
final List<GpxDisplayGroup> groups = getDisplayGroups();
|
||||
if (groups.size() > 0) {
|
||||
updateSplit(groups, ((SwitchCompat)headerView.findViewById(R.id.showOnMapToggle)).isChecked() ? sf : null);
|
||||
if (getGpxDataItem() != null) {
|
||||
updateSplitInDatabase();
|
||||
}
|
||||
}
|
||||
updateSplitIntervalView(headerView.findViewById(R.id.split_interval_view));
|
||||
}
|
||||
|
|
|
@ -107,7 +107,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
this.view = view;
|
||||
selectedGpxHelper = view.getApplication().getSelectedGpxHelper();
|
||||
osmandRenderer = view.getApplication().getResourceManager().getRenderer().getRenderer();
|
||||
view.getApplication().getGpxDatabase().processSplit();
|
||||
initUI();
|
||||
}
|
||||
|
||||
|
@ -194,6 +193,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
cache.clear();
|
||||
currentTrackColor = view.getSettings().CURRENT_TRACK_COLOR.get();
|
||||
if (!selectedGPXFiles.isEmpty()) {
|
||||
view.getApplication().getGpxDatabase().processSplit();
|
||||
drawSelectedFilesSegments(canvas, tileBox, selectedGPXFiles, settings);
|
||||
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
|
||||
if (trackChartPoints != null) {
|
||||
|
|
Loading…
Reference in a new issue