summaryrefslogtreecommitdiff
path: root/core/src/main/java/de
diff options
context:
space:
mode:
authorH. Lehmann <ByteHamster@users.noreply.github.com>2020-01-12 09:52:04 +0100
committerGitHub <noreply@github.com>2020-01-12 09:52:04 +0100
commit2f0c627b15af26aace320e1984d6f398a7ee0abe (patch)
tree6c7b98b7de7b83bffd6ecd5220145c60d10aa5ff /core/src/main/java/de
parent9b50cbbe0ee7903f7d4ce23aa9b5a163b6d46e19 (diff)
parent6817c00491e911988586d6ed7e14942c88ef2435 (diff)
downloadAntennaPod-2f0c627b15af26aace320e1984d6f398a7ee0abe.zip
Merge pull request #3523 from wseemann/develop
Show storage size of downloaded episodes
Diffstat (limited to 'core/src/main/java/de')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java50
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/comparator/CompareCompat.java29
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 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 &lt; long2,
- * and greater than 0 if long1 &gt; 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 &lt; long2,
+ * and greater than 0 if long1 &gt; 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;
+ }
+ }
+}