Delete only gpx added with API
This commit is contained in:
parent
60354edc72
commit
4cb0a98e9b
2 changed files with 49 additions and 17 deletions
|
@ -944,6 +944,7 @@ public class OsmandAidlApi {
|
||||||
app.getRendererRegistry().getCurrentSelectedRenderer(), color);
|
app.getRendererRegistry().getCurrentSelectedRenderer(), color);
|
||||||
if (!destinationExists) {
|
if (!destinationExists) {
|
||||||
GpxDataItem gpxDataItem = new GpxDataItem(destination, col);
|
GpxDataItem gpxDataItem = new GpxDataItem(destination, col);
|
||||||
|
gpxDataItem.setApiImported(true);
|
||||||
app.getGpxDatabase().add(gpxDataItem);
|
app.getGpxDatabase().add(gpxDataItem);
|
||||||
} else {
|
} else {
|
||||||
GpxDataItem item = app.getGpxDatabase().getItem(destination);
|
GpxDataItem item = app.getGpxDatabase().getItem(destination);
|
||||||
|
@ -1139,15 +1140,18 @@ public class OsmandAidlApi {
|
||||||
if (!Algorithms.isEmpty(fileName)) {
|
if (!Algorithms.isEmpty(fileName)) {
|
||||||
final File f = app.getAppPath(IndexConstants.GPX_INDEX_DIR + fileName);
|
final File f = app.getAppPath(IndexConstants.GPX_INDEX_DIR + fileName);
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
new AsyncTask<File, Void, Void>() {
|
GpxDataItem item = app.getGpxDatabase().getItem(f);
|
||||||
|
if (item != null && item.isApiImported()) {
|
||||||
|
new AsyncTask<File, Void, Void>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(File... files) {
|
protected Void doInBackground(File... files) {
|
||||||
Algorithms.removeAllFiles(f);
|
Algorithms.removeAllFiles(f);
|
||||||
app.getGpxDatabase().remove(f);
|
app.getGpxDatabase().remove(f);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, f);
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.util.List;
|
||||||
public class GPXDatabase {
|
public class GPXDatabase {
|
||||||
|
|
||||||
private static final String DB_NAME = "gpx_database";
|
private static final String DB_NAME = "gpx_database";
|
||||||
private static final int DB_VERSION = 5;
|
private static final int DB_VERSION = 6;
|
||||||
private static final String GPX_TABLE_NAME = "gpxTable";
|
private static final String GPX_TABLE_NAME = "gpxTable";
|
||||||
private static final String GPX_COL_NAME = "fileName";
|
private static final String GPX_COL_NAME = "fileName";
|
||||||
private static final String GPX_COL_DIR = "fileDir";
|
private static final String GPX_COL_DIR = "fileDir";
|
||||||
|
@ -45,6 +45,8 @@ public class GPXDatabase {
|
||||||
private static final String GPX_COL_SPLIT_TYPE = "splitType";
|
private static final String GPX_COL_SPLIT_TYPE = "splitType";
|
||||||
private static final String GPX_COL_SPLIT_INTERVAL = "splitInterval";
|
private static final String GPX_COL_SPLIT_INTERVAL = "splitInterval";
|
||||||
|
|
||||||
|
private static final String GPX_COL_API_IMPORTED = "apiImported";
|
||||||
|
|
||||||
public static final int GPX_SPLIT_TYPE_NO_SPLIT = -1;
|
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_DISTANCE = 1;
|
||||||
public static final int GPX_SPLIT_TYPE_TIME = 2;
|
public static final int GPX_SPLIT_TYPE_TIME = 2;
|
||||||
|
@ -74,7 +76,8 @@ public class GPXDatabase {
|
||||||
GPX_COL_COLOR + " TEXT, " +
|
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_TYPE + " int, " +
|
||||||
GPX_COL_SPLIT_INTERVAL + " double);";
|
GPX_COL_SPLIT_INTERVAL + " double, " +
|
||||||
|
GPX_COL_API_IMPORTED + " int);"; // 1 = true, 0 = false
|
||||||
|
|
||||||
private static final String GPX_TABLE_SELECT = "SELECT " +
|
private static final String GPX_TABLE_SELECT = "SELECT " +
|
||||||
GPX_COL_NAME + ", " +
|
GPX_COL_NAME + ", " +
|
||||||
|
@ -98,7 +101,8 @@ public class GPXDatabase {
|
||||||
GPX_COL_COLOR + ", " +
|
GPX_COL_COLOR + ", " +
|
||||||
GPX_COL_FILE_LAST_MODIFIED_TIME + ", " +
|
GPX_COL_FILE_LAST_MODIFIED_TIME + ", " +
|
||||||
GPX_COL_SPLIT_TYPE + ", " +
|
GPX_COL_SPLIT_TYPE + ", " +
|
||||||
GPX_COL_SPLIT_INTERVAL +
|
GPX_COL_SPLIT_INTERVAL + ", " +
|
||||||
|
GPX_COL_API_IMPORTED +
|
||||||
" FROM " + GPX_TABLE_NAME;
|
" FROM " + GPX_TABLE_NAME;
|
||||||
|
|
||||||
private OsmandApplication context;
|
private OsmandApplication context;
|
||||||
|
@ -110,6 +114,7 @@ public class GPXDatabase {
|
||||||
private long fileLastModifiedTime;
|
private long fileLastModifiedTime;
|
||||||
private int splitType;
|
private int splitType;
|
||||||
private double splitInterval;
|
private double splitInterval;
|
||||||
|
private boolean apiImported;
|
||||||
|
|
||||||
public GpxDataItem(File file, GPXTrackAnalysis analysis) {
|
public GpxDataItem(File file, GPXTrackAnalysis analysis) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
@ -144,6 +149,14 @@ public class GPXDatabase {
|
||||||
public double getSplitInterval() {
|
public double getSplitInterval() {
|
||||||
return splitInterval;
|
return splitInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isApiImported() {
|
||||||
|
return apiImported;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApiImported(boolean apiImported) {
|
||||||
|
this.apiImported = apiImported;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GPXDatabase(OsmandApplication app) {
|
public GPXDatabase(OsmandApplication app) {
|
||||||
|
@ -224,6 +237,13 @@ public class GPXDatabase {
|
||||||
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_INTERVAL + " double");
|
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_INTERVAL + " double");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldVersion < 6) {
|
||||||
|
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_API_IMPORTED + " int");
|
||||||
|
db.execSQL("UPDATE " + GPX_TABLE_NAME +
|
||||||
|
" SET " + GPX_COL_API_IMPORTED + " = ? " +
|
||||||
|
"WHERE " + GPX_COL_API_IMPORTED + " IS NULL", new Object[]{0});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean updateLastModifiedTime(GpxDataItem item) {
|
private boolean updateLastModifiedTime(GpxDataItem item) {
|
||||||
|
@ -362,16 +382,22 @@ public class GPXDatabase {
|
||||||
}
|
}
|
||||||
if (a != null) {
|
if (a != null) {
|
||||||
db.execSQL(
|
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,
|
new Object[]{ fileName, fileDir, a.totalDistance, a.totalTracks, a.startTime, a.endTime,
|
||||||
a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown,
|
a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown,
|
||||||
a.avgElevation, a.minElevation, a.maxElevation, a.maxSpeed, a.avgSpeed, a.points, a.wptPoints,
|
a.avgElevation, a.minElevation, a.maxElevation, a.maxSpeed, a.avgSpeed, a.points, a.wptPoints,
|
||||||
color, item.file.lastModified(), item.splitType, item.splitInterval });
|
color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0});
|
||||||
} else {
|
} else {
|
||||||
db.execSQL(
|
db.execSQL("INSERT INTO " + GPX_TABLE_NAME + "(" +
|
||||||
"INSERT INTO " + GPX_TABLE_NAME + "(" + GPX_COL_NAME + ", " + GPX_COL_DIR + ", " +
|
GPX_COL_NAME + ", " +
|
||||||
GPX_COL_COLOR + ", " + GPX_COL_FILE_LAST_MODIFIED_TIME + ", " + GPX_COL_SPLIT_TYPE + ", " + GPX_COL_SPLIT_INTERVAL + ") VALUES (?, ?, ?, ?, ?, ?)",
|
GPX_COL_DIR + ", " +
|
||||||
new Object[]{ fileName, fileDir, color, 0, item.splitType, item.splitInterval });
|
GPX_COL_COLOR + ", " +
|
||||||
|
GPX_COL_FILE_LAST_MODIFIED_TIME + ", " +
|
||||||
|
GPX_COL_SPLIT_TYPE + ", " +
|
||||||
|
GPX_COL_SPLIT_INTERVAL + ", " +
|
||||||
|
GPX_COL_API_IMPORTED +
|
||||||
|
") VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||||
|
new Object[]{fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,6 +462,7 @@ public class GPXDatabase {
|
||||||
long fileLastModifiedTime = query.getLong(19);
|
long fileLastModifiedTime = query.getLong(19);
|
||||||
int splitType = (int)query.getInt(20);
|
int splitType = (int)query.getInt(20);
|
||||||
double splitInterval = query.getDouble(21);
|
double splitInterval = query.getDouble(21);
|
||||||
|
boolean apiImported = query.getInt(22) == 1;
|
||||||
|
|
||||||
GPXTrackAnalysis a = new GPXTrackAnalysis();
|
GPXTrackAnalysis a = new GPXTrackAnalysis();
|
||||||
a.totalDistance = totalDistance;
|
a.totalDistance = totalDistance;
|
||||||
|
@ -471,6 +498,7 @@ public class GPXDatabase {
|
||||||
item.fileLastModifiedTime = fileLastModifiedTime;
|
item.fileLastModifiedTime = fileLastModifiedTime;
|
||||||
item.splitType = splitType;
|
item.splitType = splitType;
|
||||||
item.splitInterval = splitInterval;
|
item.splitInterval = splitInterval;
|
||||||
|
item.apiImported = apiImported;
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue