diff options
author | ByteHamster <info@bytehamster.com> | 2022-02-20 12:07:21 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2022-02-21 22:54:40 +0100 |
commit | 7ab6d08ea589aae7db2f7bdf1b28833f45ba9943 (patch) | |
tree | 3cb1943e5640e65f8876e4053d131f88a3df66fe /core/src | |
parent | b6d23168707bd55e5bb4060a9cd8e8ecf96a9716 (diff) | |
download | AntennaPod-7ab6d08ea589aae7db2f7bdf1b28833f45ba9943.zip |
Add line graph to statistics screen
Diffstat (limited to 'core/src')
3 files changed, 39 insertions, 2 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index 5ea3f1e14..11ff813a9 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -771,6 +771,33 @@ public final class DBReader { } } + public static class MonthlyStatisticsItem { + public int year = 0; + public int month = 0; + public long timePlayed = 0; + } + + @NonNull + public static List<MonthlyStatisticsItem> getMonthlyTimeStatistics() { + List<MonthlyStatisticsItem> months = new ArrayList<>(); + PodDBAdapter adapter = PodDBAdapter.getInstance(); + adapter.open(); + try (Cursor cursor = adapter.getMonthlyStatisticsCursor()) { + int indexMonth = cursor.getColumnIndexOrThrow("month"); + int indexYear = cursor.getColumnIndexOrThrow("year"); + int indexTotalDuration = cursor.getColumnIndexOrThrow("total_duration"); + while (cursor.moveToNext()) { + MonthlyStatisticsItem item = new MonthlyStatisticsItem(); + item.month = Integer.parseInt(cursor.getString(indexMonth)); + item.year = Integer.parseInt(cursor.getString(indexYear)); + item.timePlayed = cursor.getLong(indexTotalDuration); + months.add(item); + } + } + adapter.close(); + return months; + } + public static class StatisticsResult { public List<StatisticsItem> feedTime = new ArrayList<>(); public long oldestDate = System.currentTimeMillis(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index 43d9c7f11..ea4617f16 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -1133,6 +1133,17 @@ public class PodDBAdapter { return db.rawQuery(query, null); } + public final Cursor getMonthlyStatisticsCursor() { + final String query = "SELECT SUM(" + KEY_PLAYED_DURATION + ") AS total_duration" + + ", strftime('%m', datetime(" + KEY_LAST_PLAYED_TIME + "/1000, 'unixepoch')) AS month" + + ", strftime('%Y', datetime(" + KEY_LAST_PLAYED_TIME + "/1000, 'unixepoch')) AS year" + + " FROM " + TABLE_NAME_FEED_MEDIA + + " WHERE " + KEY_LAST_PLAYED_TIME + " > 0 AND " + KEY_PLAYED_DURATION + " > 0" + + " GROUP BY year, month" + + " ORDER BY year, month"; + return db.rawQuery(query, null); + } + public int getQueueSize() { final String query = String.format("SELECT COUNT(%s) FROM %s", KEY_ID, TABLE_NAME_QUEUE); Cursor c = db.rawQuery(query, null); diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 67dd3b3e4..783065178 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -28,8 +28,7 @@ <string name="gpodnet_main_label">gpodder.net</string> <string name="episode_cache_full_title">Episode cache full</string> <string name="episode_cache_full_message">The episode cache limit has been reached. You can increase the cache size in the Settings.</string> - <string name="playback_statistics_label">Playback</string> - <string name="download_statistics_label">Downloads</string> + <string name="years_statistics_label">Years</string> <string name="notification_pref_fragment">Notifications</string> <!-- Google Assistant --> |