Update tq

pull/653/merge
Varun Patil 2023-05-07 18:57:29 -07:00
parent 535daadc51
commit cd131797cc
2 changed files with 67 additions and 55 deletions

View File

@ -4,12 +4,12 @@ plugins {
android { android {
namespace 'gallery.memories' namespace 'gallery.memories'
compileSdk 32 compileSdk 33
defaultConfig { defaultConfig {
applicationId "gallery.memories" applicationId "gallery.memories"
minSdk 27 minSdk 27
targetSdk 32 targetSdk 33
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
@ -32,13 +32,13 @@ android {
} }
dependencies { dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'com.google.android.material:material:1.8.0'
implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3' implementation 'androidx.navigation:navigation-fragment:2.5.3'
implementation 'androidx.navigation:navigation-fragment:2.4.1' implementation 'androidx.navigation:navigation-ui:2.5.3'
implementation 'androidx.navigation:navigation-ui:2.4.1' implementation 'androidx.exifinterface:exifinterface:1.3.6'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
} }

View File

@ -4,9 +4,10 @@ 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 android.media.ExifInterface; 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.util.Log; import android.util.Log;
import org.json.JSONArray; import org.json.JSONArray;
@ -16,7 +17,8 @@ import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.TimeZone; import java.util.HashMap;
import java.util.Map;
public class TimelineQuery { public class TimelineQuery {
final static String TAG = "TimelineQuery"; final static String TAG = "TimelineQuery";
@ -31,32 +33,42 @@ public class TimelineQuery {
} }
public JSONArray getByDayId(final long dayId) { public JSONArray getByDayId(final long dayId) {
Uri collection = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Get list of images from DB
final ArrayList<Long> imageIds = new ArrayList();
final Map<Long, Long> datesTaken = new HashMap<>();
try (Cursor cursor = mDb.rawQuery(
"SELECT local_id, date_taken FROM images WHERE dayid = ?",
new String[] { Long.toString(dayId) }
)) {
while (cursor.moveToNext()) {
final long localId = cursor.getLong(0);
final long dateTaken = cursor.getLong(1);
imageIds.add(localId);
datesTaken.put(localId, dateTaken);
}
}
// Offset of current timezone from UTC // Nothing to do
long utcOffset = TimeZone.getDefault().getOffset(System.currentTimeMillis()); if (imageIds.size() == 0) {
return new JSONArray();
}
// All external storage images
Uri collection = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
// Same fields as server response // Same fields as server response
String[] projection = new String[] { String[] projection = new String[] {
MediaStore.Images.Media._ID, MediaStore.Images.Media._ID,
MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DISPLAY_NAME,
MediaStore.Images.Media.MIME_TYPE, MediaStore.Images.Media.MIME_TYPE,
MediaStore.Images.Media.DATE_TAKEN,
MediaStore.Images.Media.HEIGHT, MediaStore.Images.Media.HEIGHT,
MediaStore.Images.Media.WIDTH, MediaStore.Images.Media.WIDTH,
MediaStore.Images.Media.SIZE, MediaStore.Images.Media.SIZE,
}; };
// Filter for given day // Filter for given day
String selection = MediaStore.Images.Media.DATE_TAKEN + " >= ? AND " String selection = MediaStore.Images.Media._ID
+ MediaStore.Images.Media.DATE_TAKEN + " <= ?"; + " IN (" + TextUtils.join(",", imageIds) + ")";
String[] selectionArgs = new String[] {
Long.toString(dayId * 86400000L - utcOffset),
Long.toString(((dayId+1) * 86400000L - utcOffset)),
};
// Sort by name? TODO: fix this
String sortOrder = MediaStore.Images.Media.DISPLAY_NAME + " ASC";
// Make list of files // Make list of files
ArrayList<JSONObject> files = new ArrayList<>(); ArrayList<JSONObject> files = new ArrayList<>();
@ -65,13 +77,12 @@ public class TimelineQuery {
collection, collection,
projection, projection,
selection, selection,
selectionArgs, null,
sortOrder null
)) { )) {
int idColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID); int idColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
int nameColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME); int nameColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME);
int mimeColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.MIME_TYPE); int mimeColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.MIME_TYPE);
int dateColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_TAKEN);
int heightColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.HEIGHT); int heightColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.HEIGHT);
int widthColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.WIDTH); int widthColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.WIDTH);
int sizeColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE); int sizeColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE);
@ -80,17 +91,18 @@ public class TimelineQuery {
long id = cursor.getLong(idColumn); long id = cursor.getLong(idColumn);
String name = cursor.getString(nameColumn); String name = cursor.getString(nameColumn);
String mime = cursor.getString(mimeColumn); String mime = cursor.getString(mimeColumn);
long dateTaken = cursor.getLong(dateColumn);
long height = cursor.getLong(heightColumn); long height = cursor.getLong(heightColumn);
long width = cursor.getLong(widthColumn); long width = cursor.getLong(widthColumn);
long size = cursor.getLong(sizeColumn); long size = cursor.getLong(sizeColumn);
long dateTaken = datesTaken.get(id);
try { try {
JSONObject file = new JSONObject() JSONObject file = new JSONObject()
.put("fileid", id) .put("fileid", id)
.put("basename", name) .put("basename", name)
.put("mimetype", mime) .put("mimetype", mime)
.put("dayid", (dateTaken / 86400000)) .put("dayid", dayId)
.put("datetaken", dateTaken)
.put("h", height) .put("h", height)
.put("w", width) .put("w", width)
.put("size", size); .put("size", size);