Update tq
parent
535daadc51
commit
cd131797cc
|
@ -4,12 +4,12 @@ plugins {
|
|||
|
||||
android {
|
||||
namespace 'gallery.memories'
|
||||
compileSdk 32
|
||||
compileSdk 33
|
||||
|
||||
defaultConfig {
|
||||
applicationId "gallery.memories"
|
||||
minSdk 27
|
||||
targetSdk 32
|
||||
targetSdk 33
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
|
@ -32,13 +32,13 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
implementation 'androidx.navigation:navigation-fragment:2.4.1'
|
||||
implementation 'androidx.navigation:navigation-ui:2.4.1'
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'com.google.android.material:material:1.8.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.navigation:navigation-fragment:2.5.3'
|
||||
implementation 'androidx.navigation:navigation-ui:2.5.3'
|
||||
implementation 'androidx.exifinterface:exifinterface:1.3.6'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
}
|
|
@ -4,9 +4,10 @@ import android.content.Context;
|
|||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.icu.text.SimpleDateFormat;
|
||||
import android.media.ExifInterface;
|
||||
import androidx.exifinterface.media.ExifInterface;
|
||||
import android.net.Uri;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
@ -16,7 +17,8 @@ import org.json.JSONObject;
|
|||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.TimeZone;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TimelineQuery {
|
||||
final static String TAG = "TimelineQuery";
|
||||
|
@ -31,32 +33,42 @@ public class TimelineQuery {
|
|||
}
|
||||
|
||||
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
|
||||
long utcOffset = TimeZone.getDefault().getOffset(System.currentTimeMillis());
|
||||
// Nothing to do
|
||||
if (imageIds.size() == 0) {
|
||||
return new JSONArray();
|
||||
}
|
||||
|
||||
// All external storage images
|
||||
Uri collection = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||
|
||||
// Same fields as server response
|
||||
String[] projection = new String[] {
|
||||
MediaStore.Images.Media._ID,
|
||||
MediaStore.Images.Media.DISPLAY_NAME,
|
||||
MediaStore.Images.Media.MIME_TYPE,
|
||||
MediaStore.Images.Media.DATE_TAKEN,
|
||||
MediaStore.Images.Media.HEIGHT,
|
||||
MediaStore.Images.Media.WIDTH,
|
||||
MediaStore.Images.Media.SIZE,
|
||||
};
|
||||
|
||||
// Filter for given day
|
||||
String selection = MediaStore.Images.Media.DATE_TAKEN + " >= ? AND "
|
||||
+ MediaStore.Images.Media.DATE_TAKEN + " <= ?";
|
||||
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";
|
||||
String selection = MediaStore.Images.Media._ID
|
||||
+ " IN (" + TextUtils.join(",", imageIds) + ")";
|
||||
|
||||
// Make list of files
|
||||
ArrayList<JSONObject> files = new ArrayList<>();
|
||||
|
@ -65,13 +77,12 @@ public class TimelineQuery {
|
|||
collection,
|
||||
projection,
|
||||
selection,
|
||||
selectionArgs,
|
||||
sortOrder
|
||||
null,
|
||||
null
|
||||
)) {
|
||||
int idColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
|
||||
int nameColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME);
|
||||
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 widthColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.WIDTH);
|
||||
int sizeColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE);
|
||||
|
@ -80,17 +91,18 @@ public class TimelineQuery {
|
|||
long id = cursor.getLong(idColumn);
|
||||
String name = cursor.getString(nameColumn);
|
||||
String mime = cursor.getString(mimeColumn);
|
||||
long dateTaken = cursor.getLong(dateColumn);
|
||||
long height = cursor.getLong(heightColumn);
|
||||
long width = cursor.getLong(widthColumn);
|
||||
long size = cursor.getLong(sizeColumn);
|
||||
long dateTaken = datesTaken.get(id);
|
||||
|
||||
try {
|
||||
JSONObject file = new JSONObject()
|
||||
.put("fileid", id)
|
||||
.put("basename", name)
|
||||
.put("mimetype", mime)
|
||||
.put("dayid", (dateTaken / 86400000))
|
||||
.put("dayid", dayId)
|
||||
.put("datetaken", dateTaken)
|
||||
.put("h", height)
|
||||
.put("w", width)
|
||||
.put("size", size);
|
||||
|
|
Loading…
Reference in New Issue