summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorMartin Fietz <Martin.Fietz@gmail.com>2017-04-16 20:10:16 +0200
committerGitHub <noreply@github.com>2017-04-16 20:10:16 +0200
commit4a37d16e433843ac18c53b5bc27676f2073d7b4c (patch)
tree0004e1a1dec3aaff70b427daeae27ab3e8aa99eb /core
parent9542ef156989cefe9534f414f034195f8b717b8f (diff)
parent8f226803cbfeaee628ca5b745bab03a7293c84d1 (diff)
downloadAntennaPod-4a37d16e433843ac18c53b5bc27676f2073d7b4c.zip
Merge pull request #2294 from ByteHamster/stats-duration
Allow choosing between getDuration and getPlayedDuration
Diffstat (limited to 'core')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java96
-rw-r--r--core/src/main/res/values/strings.xml4
2 files changed, 82 insertions, 18 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 7bda08b7a..8ed6718c0 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
@@ -927,64 +927,107 @@ 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
*/
- public static StatisticsData getStatistics() {
+ public static StatisticsData getStatistics(boolean sortByCountAll) {
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
+ long totalTimeCountAll = 0;
long totalTime = 0;
List<StatisticsItem> feedTime = new ArrayList<>();
List<Feed> feeds = getFeedList();
for (Feed feed : feeds) {
+ long feedPlayedTimeCountAll = 0;
long feedPlayedTime = 0;
long feedTotalTime = 0;
long episodes = 0;
long episodesStarted = 0;
+ long episodesStartedIncludingMarked = 0;
List<FeedItem> items = getFeed(feed.getId()).getItems();
- for(FeedItem item : items) {
+ for (FeedItem item : items) {
FeedMedia media = item.getMedia();
- if(media == null) {
+ if (media == null) {
continue;
}
// played duration used to be reset when the item is added to the playback history
- if(media.getPlaybackCompletionDate() != null) {
+ if (media.getPlaybackCompletionDate() != null) {
feedPlayedTime += media.getDuration() / 1000;
}
feedPlayedTime += media.getPlayedDuration() / 1000;
+
+ if (item.isPlayed()) {
+ feedPlayedTimeCountAll += media.getDuration() / 1000;
+ } else {
+ feedPlayedTimeCountAll += media.getPosition() / 1000;
+ }
+
if (media.getPlaybackCompletionDate() != null || media.getPlayedDuration() > 0) {
episodesStarted++;
}
+
+ if (item.isPlayed() || media.getPosition() != 0) {
+ episodesStartedIncludingMarked++;
+ }
+
feedTotalTime += media.getDuration() / 1000;
episodes++;
}
feedTime.add(new StatisticsItem(
- feed, feedTotalTime, feedPlayedTime, episodes, episodesStarted));
+ feed, feedTotalTime, feedPlayedTime, feedPlayedTimeCountAll, episodes,
+ episodesStarted, episodesStartedIncludingMarked));
totalTime += feedPlayedTime;
+ totalTimeCountAll += feedPlayedTimeCountAll;
}
- Collections.sort(feedTime, (item1, item2) -> {
- if(item1.timePlayed > item2.timePlayed) {
- return -1;
- } else if(item1.timePlayed < item2.timePlayed) {
- return 1;
- } else {
- return 0;
- }
- });
+ 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, feedTime);
+ 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
+ */
+ public long totalTimeCountAll;
+
+ /**
+ * Respects speed, listening twice, ...
+ */
public long totalTime;
+
public List<StatisticsItem> feedTime;
- public StatisticsData(long totalTime, List<StatisticsItem> feedTime) {
+ public StatisticsData(long totalTime, long totalTimeCountAll, List<StatisticsItem> feedTime) {
this.totalTime = totalTime;
+ this.totalTimeCountAll = totalTimeCountAll;
this.feedTime = feedTime;
}
}
@@ -992,17 +1035,34 @@ public final class DBReader {
public static class StatisticsItem {
public Feed feed;
public long time;
+
+ /**
+ * Respects speed, listening twice, ...
+ */
public long timePlayed;
+ /**
+ * Simply sums up time of podcasts that are marked as played
+ */
+ public long timePlayedCountAll;
public long episodes;
+ /**
+ * Episodes that are actually played
+ */
public long episodesStarted;
+ /**
+ * All episodes that are marked as played (or have position != 0)
+ */
+ public long episodesStartedIncludingMarked;
- public StatisticsItem(Feed feed, long time, long timePlayed,
- long episodes, long episodesStarted) {
+ public StatisticsItem(Feed feed, long time, long timePlayed, long timePlayedCountAll,
+ long episodes, long episodesStarted, long episodesStartedIncludingMarked) {
this.feed = feed;
this.time = time;
this.timePlayed = timePlayed;
+ this.timePlayedCountAll = timePlayedCountAll;
this.episodes = episodes;
this.episodesStarted = episodesStarted;
+ this.episodesStartedIncludingMarked = episodesStartedIncludingMarked;
}
}
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index 974c5a7f8..b82a03801 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -31,6 +31,10 @@
<!-- Statistics fragment -->
<string name="total_time_listened_to_podcasts">Total time of podcasts played:</string>
<string name="statistics_details_dialog">%1$d out of %2$d episodes started.\n\nPlayed %3$s out of %4$s.</string>
+ <string name="statistics_mode">Statistics mode</string>
+ <string name="statistics_mode_normal">Calculate duration that was actually played. Playing twice is counted twice, while marking as played is not counted</string>
+ <string name="statistics_mode_count_all">Sum up all podcasts marked as played</string>
+ <string name="statistics_speed_not_counted">Notice: Playback speed is never taken into account.</string>
<!-- Main activity -->
<string name="drawer_open">Open menu</string>