From 01d4bd8489ce93d8fb2bfe90a193765e61c2b046 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sun, 7 May 2023 20:02:37 -0700 Subject: [PATCH] Add days API --- .../main/java/gallery/memories/NativeX.java | 5 ++++ .../memories/service/TimelineQuery.java | 24 ++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/gallery/memories/NativeX.java b/app/src/main/java/gallery/memories/NativeX.java index ba3b7b20..a81bfd55 100644 --- a/app/src/main/java/gallery/memories/NativeX.java +++ b/app/src/main/java/gallery/memories/NativeX.java @@ -27,6 +27,11 @@ public class NativeX { return true; } + @JavascriptInterface + public void getLocalDays(final String call, final long _ignore) { + mJsService.runAsync(call, () -> mQuery.getDays().toString().getBytes()); + } + @JavascriptInterface public void getLocalByDayId(final String call, final long dayId) { mJsService.runAsync(call, () -> mQuery.getByDayId(dayId).toString().getBytes()); diff --git a/app/src/main/java/gallery/memories/service/TimelineQuery.java b/app/src/main/java/gallery/memories/service/TimelineQuery.java index 9706b294..683ef991 100644 --- a/app/src/main/java/gallery/memories/service/TimelineQuery.java +++ b/app/src/main/java/gallery/memories/service/TimelineQuery.java @@ -128,9 +128,27 @@ public class TimelineQuery { return new JSONArray(files); } -// public JSONArray getDays(final long dayId) { -// -// } + public JSONArray getDays() { + try (Cursor cursor = mDb.rawQuery( + "SELECT dayid, COUNT(local_id) FROM images GROUP BY dayid", + null + )) { + JSONArray days = new JSONArray(); + while (cursor.moveToNext()) { + long id = cursor.getLong(0); + long count = cursor.getLong(1); + days.put(new JSONObject() + .put("dayid", id) + .put("count", count) + ); + } + + return days; + } catch (JSONException e) { + Log.e(TAG, "JSON error"); + return new JSONArray(); + } + } protected void fullSyncDb() { Uri collection = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;