Make updating wpt category names lazy

This commit is contained in:
Alexander Sytnyk 2018-03-14 13:27:37 +02:00
parent c2489ff440
commit 7f31a6861b
2 changed files with 4 additions and 30 deletions

View file

@ -1,7 +1,5 @@
package net.osmand.plus; package net.osmand.plus;
import android.annotation.SuppressLint;
import android.os.AsyncTask;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
@ -253,36 +251,9 @@ public class GPXDatabase {
if (oldVersion < 7) { if (oldVersion < 7) {
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_WPT_CATEGORY_NAMES + " TEXT"); db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_WPT_CATEGORY_NAMES + " TEXT");
updateWptCategoryNames();
} }
} }
@SuppressLint("StaticFieldLeak")
private void updateWptCategoryNames() {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
for (GpxDataItem item : getItems()) {
GPXUtilities.GPXFile gpxFile = GPXUtilities.loadGPXFile(context, item.file);
String fileName = getFileName(item.file);
String fileDir = getFileDir(item.file);
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " +
GPX_COL_WPT_CATEGORY_NAMES + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[] { Algorithms.encodeStringSet(gpxFile.getWaypointCategories(true)), fileName, fileDir });
}
} finally {
db.close();
}
}
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private boolean updateLastModifiedTime(GpxDataItem item) { private boolean updateLastModifiedTime(GpxDataItem item) {
SQLiteConnection db = openConnection(false); SQLiteConnection db = openConnection(false);
if (db != null) { if (db != null) {

View file

@ -124,7 +124,10 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
processGPXFolder(gpxFile, sub); processGPXFolder(gpxFile, sub);
} else if (gpxFile.isFile() && gpxFile.getName().toLowerCase().endsWith(".gpx")) { } else if (gpxFile.isFile() && gpxFile.getName().toLowerCase().endsWith(".gpx")) {
GpxDataItem item = processedDataFiles.get(gpxFile); GpxDataItem item = processedDataFiles.get(gpxFile);
if (item == null || item.getFileLastModifiedTime() != gpxFile.lastModified()) { if (item == null
|| item.getFileLastModifiedTime() != gpxFile.lastModified()
|| item.getAnalysis().wptCategoryNames == null
|| (item.getAnalysis().wptPoints > 0 && item.getAnalysis().wptCategoryNames.isEmpty())) {
GPXFile f = GPXUtilities.loadGPXFile(app, gpxFile); GPXFile f = GPXUtilities.loadGPXFile(app, gpxFile);
GPXTrackAnalysis analysis = f.getAnalysis(gpxFile.lastModified()); GPXTrackAnalysis analysis = f.getAnalysis(gpxFile.lastModified());
if (item == null) { if (item == null) {