diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2020-01-12 09:52:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-12 09:52:04 +0100 |
commit | 2f0c627b15af26aace320e1984d6f398a7ee0abe (patch) | |
tree | 6c7b98b7de7b83bffd6ecd5220145c60d10aa5ff /core/src/main | |
parent | 9b50cbbe0ee7903f7d4ce23aa9b5a163b6d46e19 (diff) | |
parent | 6817c00491e911988586d6ed7e14942c88ef2435 (diff) | |
download | AntennaPod-2f0c627b15af26aace320e1984d6f398a7ee0abe.zip |
Merge pull request #3523 from wseemann/develop
Show storage size of downloaded episodes
Diffstat (limited to 'core/src/main')
3 files changed, 52 insertions, 32 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 148d3f852..e6d21794c 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 @@ -868,12 +868,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(); @@ -889,6 +887,7 @@ public final class DBReader { long episodes = 0; long episodesStarted = 0; long episodesStartedIncludingMarked = 0; + long totalDownloadSize = 0; List<FeedItem> items = getFeed(feed.getId()).getItems(); for (FeedItem item : items) { FeedMedia media = item.getMedia(); @@ -913,43 +912,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 @@ -961,12 +941,12 @@ public final class DBReader { */ public final long totalTime; - public final List<StatisticsItem> feedTime; + public final List<StatisticsItem> feeds; - public StatisticsData(long totalTime, long totalTimeCountAll, List<StatisticsItem> feedTime) { + public StatisticsData(long totalTime, long totalTimeCountAll, List<StatisticsItem> feeds) { this.totalTime = totalTime; this.totalTimeCountAll = totalTimeCountAll; - this.feedTime = feedTime; + this.feeds = feeds; } } @@ -991,9 +971,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; @@ -1001,6 +986,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 af4ea5750..2b48cb5ee 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -29,6 +29,8 @@ <string name="gpodnet_auth_label">gpodder.net Login</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> <!-- Statistics fragment --> <string name="total_time_listened_to_podcasts">Total time of podcasts played:</string> @@ -40,6 +42,9 @@ <string name="statistics_reset_data">Reset statistics data</string> <string name="statistics_reset_data_msg">This will erase the history of duration played for all episodes. Are you sure you want to proceed?</string> + <!-- Download Statistics fragment --> + <string name="total_size_downloaded_podcasts">Total size of downloaded podcasts:</string> + <!-- Main activity --> <string name="drawer_open">Open menu</string> <string name="drawer_close">Close menu</string> |