From 6817c00491e911988586d6ed7e14942c88ef2435 Mon Sep 17 00:00:00 2001 From: William Seemann Date: Sun, 12 Jan 2020 09:35:04 +0100 Subject: Show storage size of downloaded episodes --- .../danoeh/antennapod/core/storage/DBReader.java | 50 ++++++++-------------- .../core/util/comparator/CompareCompat.java | 29 +++++++++++++ core/src/main/res/values/strings.xml | 5 +++ 3 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 core/src/main/java/de/danoeh/antennapod/core/util/comparator/CompareCompat.java (limited to 'core') 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 8b87d7c54..e0a7c3f0a 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 @@ -870,12 +870,10 @@ public final class DBReader { /** * Searches the DB for statistics * - * @param sortByCountAll If true, the statistic items will be sorted according to the - * countAll calculation time * @return The StatisticsInfo object */ @NonNull - public static StatisticsData getStatistics(boolean sortByCountAll) { + public static StatisticsData getStatistics() { PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); @@ -891,6 +889,7 @@ public final class DBReader { long episodes = 0; long episodesStarted = 0; long episodesStartedIncludingMarked = 0; + long totalDownloadSize = 0; List items = getFeed(feed.getId()).getItems(); for (FeedItem item : items) { FeedMedia media = item.getMedia(); @@ -915,43 +914,24 @@ public final class DBReader { } feedTotalTime += media.getDuration() / 1000; + + if (media.isDownloaded()) { + totalDownloadSize = totalDownloadSize + media.getSize(); + } + episodes++; } feedTime.add(new StatisticsItem( feed, feedTotalTime, feedPlayedTime, feedPlayedTimeCountAll, episodes, - episodesStarted, episodesStartedIncludingMarked)); + episodesStarted, episodesStartedIncludingMarked, totalDownloadSize)); totalTime += feedPlayedTime; totalTimeCountAll += feedPlayedTimeCountAll; } - if (sortByCountAll) { - Collections.sort(feedTime, (item1, item2) -> - compareLong(item1.timePlayedCountAll, item2.timePlayedCountAll)); - } else { - Collections.sort(feedTime, (item1, item2) -> - compareLong(item1.timePlayed, item2.timePlayed)); - } - adapter.close(); return new StatisticsData(totalTime, totalTimeCountAll, feedTime); } - /** - * Compares two {@code long} values. Long.compare() is not available before API 19 - * - * @return 0 if long1 = long2, less than 0 if long1 < long2, - * and greater than 0 if long1 > long2. - */ - private static int compareLong(long long1, long long2) { - if (long1 > long2) { - return -1; - } else if (long1 < long2) { - return 1; - } else { - return 0; - } - } - public static class StatisticsData { /** * Simply sums up time of podcasts that are marked as played @@ -963,12 +943,12 @@ public final class DBReader { */ public final long totalTime; - public final List feedTime; + public final List feeds; - public StatisticsData(long totalTime, long totalTimeCountAll, List feedTime) { + public StatisticsData(long totalTime, long totalTimeCountAll, List feeds) { this.totalTime = totalTime; this.totalTimeCountAll = totalTimeCountAll; - this.feedTime = feedTime; + this.feeds = feeds; } } @@ -993,9 +973,14 @@ public final class DBReader { * All episodes that are marked as played (or have position != 0) */ public final long episodesStartedIncludingMarked; + /** + * Simply sums up the size of download podcasts + */ + public final long totalDownloadSize; public StatisticsItem(Feed feed, long time, long timePlayed, long timePlayedCountAll, - long episodes, long episodesStarted, long episodesStartedIncludingMarked) { + long episodes, long episodesStarted, long episodesStartedIncludingMarked, + long totalDownloadSize) { this.feed = feed; this.time = time; this.timePlayed = timePlayed; @@ -1003,6 +988,7 @@ public final class DBReader { this.episodes = episodes; this.episodesStarted = episodesStarted; this.episodesStartedIncludingMarked = episodesStartedIncludingMarked; + this.totalDownloadSize = totalDownloadSize; } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/comparator/CompareCompat.java b/core/src/main/java/de/danoeh/antennapod/core/util/comparator/CompareCompat.java new file mode 100644 index 000000000..c189f2389 --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/util/comparator/CompareCompat.java @@ -0,0 +1,29 @@ +package de.danoeh.antennapod.core.util.comparator; + +/** + * Some compare() methods are not available before API 19. + * This class provides fallbacks + */ +public class CompareCompat { + + private CompareCompat() { + // Must not be instantiated + } + + /** + * Compares two {@code long} values. Long.compare() is not available before API 19 + * + * @return 0 if long1 = long2, less than 0 if long1 < long2, + * and greater than 0 if long1 > long2. + */ + public static int compareLong(long long1, long long2) { + //noinspection UseCompareMethod + if (long1 > long2) { + return -1; + } else if (long1 < long2) { + return 1; + } else { + return 0; + } + } +} diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index ce6a0e41d..a4872bfc6 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -29,6 +29,8 @@ gpodder.net Login Episode cache full The episode cache limit has been reached. You can increase the cache size in the Settings. + Playback + Downloads Total time of podcasts played: @@ -40,6 +42,9 @@ Reset statistics data This will erase the history of duration played for all episodes. Are you sure you want to proceed? + + Total size of downloaded podcasts: + Open menu Close menu -- cgit v1.2.3