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/java | |
parent | 6d0b16461d5567dae4b3dd6553d53acffb766359 (diff) | |
download | AntennaPod-6817c00491e911988586d6ed7e14942c88ef2435.zip |
Show storage size of downloaded episodes
Diffstat (limited to 'core/src/main/java')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java | 50 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/comparator/CompareCompat.java | 29 |
2 files changed, 47 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; + } + } +} |