tq: remove stale images
parent
cd131797cc
commit
93350812a3
|
@ -4,12 +4,14 @@ import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.icu.text.SimpleDateFormat;
|
import android.icu.text.SimpleDateFormat;
|
||||||
import androidx.exifinterface.media.ExifInterface;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.collection.ArraySet;
|
||||||
|
import androidx.exifinterface.media.ExifInterface;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -19,6 +21,7 @@ import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class TimelineQuery {
|
public class TimelineQuery {
|
||||||
final static String TAG = "TimelineQuery";
|
final static String TAG = "TimelineQuery";
|
||||||
|
@ -34,7 +37,7 @@ public class TimelineQuery {
|
||||||
|
|
||||||
public JSONArray getByDayId(final long dayId) {
|
public JSONArray getByDayId(final long dayId) {
|
||||||
// Get list of images from DB
|
// Get list of images from DB
|
||||||
final ArrayList<Long> imageIds = new ArrayList();
|
final Set<Long> imageIds = new ArraySet<>();
|
||||||
final Map<Long, Long> datesTaken = new HashMap<>();
|
final Map<Long, Long> datesTaken = new HashMap<>();
|
||||||
try (Cursor cursor = mDb.rawQuery(
|
try (Cursor cursor = mDb.rawQuery(
|
||||||
"SELECT local_id, date_taken FROM images WHERE dayid = ?",
|
"SELECT local_id, date_taken FROM images WHERE dayid = ?",
|
||||||
|
@ -96,6 +99,9 @@ public class TimelineQuery {
|
||||||
long size = cursor.getLong(sizeColumn);
|
long size = cursor.getLong(sizeColumn);
|
||||||
long dateTaken = datesTaken.get(id);
|
long dateTaken = datesTaken.get(id);
|
||||||
|
|
||||||
|
// Remove from list of ids
|
||||||
|
imageIds.remove(id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject file = new JSONObject()
|
JSONObject file = new JSONObject()
|
||||||
.put("fileid", id)
|
.put("fileid", id)
|
||||||
|
@ -113,10 +119,19 @@ public class TimelineQuery {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove files that were not found
|
||||||
|
if (imageIds.size() > 0) {
|
||||||
|
mDb.execSQL("DELETE FROM images WHERE local_id IN (" + TextUtils.join(",", imageIds) + ")");
|
||||||
|
}
|
||||||
|
|
||||||
// Return JSON string of files
|
// Return JSON string of files
|
||||||
return new JSONArray(files);
|
return new JSONArray(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public JSONArray getDays(final long dayId) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
protected void fullSyncDb() {
|
protected void fullSyncDb() {
|
||||||
Uri collection = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
Uri collection = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue