diff options
author | William Seemann <wseemann@gmail.com> | 2020-01-12 09:35:04 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-01-12 09:35:21 +0100 |
commit | 6817c00491e911988586d6ed7e14942c88ef2435 (patch) | |
tree | d6864d680eaaf519dd57f973e5bd881f25410719 /core/src/main | |
parent | 6d0b16461d5567dae4b3dd6553d53acffb766359 (diff) | |
download | AntennaPod-6817c00491e911988586d6ed7e14942c88ef2435.zip |
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 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<FeedItem> 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<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; } } @@ -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 @@ <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> |