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;