diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2022-02-21 22:53:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-21 22:53:18 +0100 |
commit | b6d23168707bd55e5bb4060a9cd8e8ecf96a9716 (patch) | |
tree | 044c0195da0168f0c3561fefaae3a6e98f50c33c /core | |
parent | 4655fcfc80fbb2083abbb68b6b07283e462da940 (diff) | |
download | AntennaPod-b6d23168707bd55e5bb4060a9cd8e8ecf96a9716.zip |
Add time-based statistics filter (#5734)
Diffstat (limited to 'core')
4 files changed, 35 insertions, 58 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index 74f89a039..357ea0b61 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -23,7 +23,6 @@ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.ArrayList; import java.util.Arrays; -import java.util.Calendar; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -1071,22 +1070,6 @@ public class UserPreferences { .apply(); } - public static long getUsageCountingDateMillis() { - return prefs.getLong(PREF_USAGE_COUNTING_DATE, -1); - } - - private static void setUsageCountingDateMillis(long value) { - prefs.edit().putLong(PREF_USAGE_COUNTING_DATE, value).apply(); - } - - public static void resetUsageCountingDate() { - setUsageCountingDateMillis(Calendar.getInstance().getTimeInMillis()); - } - - public static void unsetUsageCountingDate() { - setUsageCountingDateMillis(-1); - } - public static boolean shouldShowSubscriptionTitle() { return prefs.getBoolean(PREF_SUBSCRIPTION_TITLE, false); } 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 da6987910..5ea3f1e14 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 @@ -771,26 +771,29 @@ public final class DBReader { } } + public static class StatisticsResult { + public List<StatisticsItem> feedTime = new ArrayList<>(); + public long oldestDate = System.currentTimeMillis(); + } + /** * Searches the DB for statistics. * * @return The list of statistics objects */ @NonNull - public static List<StatisticsItem> getStatistics() { + public static StatisticsResult getStatistics(boolean includeMarkedAsPlayed, + long timeFilterFrom, long timeFilterTo) { PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); - List<StatisticsItem> feedTime = new ArrayList<>(); - + StatisticsResult result = new StatisticsResult(); 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; long totalDownloadSize = 0; long episodesDownloadCount = 0; List<FeedItem> items = getFeed(feed.getId()).getItems(); @@ -800,20 +803,22 @@ public final class DBReader { continue; } - feedPlayedTime += media.getPlayedDuration() / 1000; - - if (item.isPlayed()) { - feedPlayedTimeCountAll += media.getDuration() / 1000; - } else { - feedPlayedTimeCountAll += media.getPosition() / 1000; + if (media.getLastPlayedTime() > 0 && media.getPlayedDuration() != 0) { + result.oldestDate = Math.min(result.oldestDate, media.getLastPlayedTime()); } - - if (media.getPlaybackCompletionDate() != null || media.getPlayedDuration() > 0) { - episodesStarted++; + if (media.getLastPlayedTime() >= timeFilterFrom + && media.getLastPlayedTime() <= timeFilterTo) { + if (media.getPlayedDuration() != 0) { + feedPlayedTime += media.getPlayedDuration() / 1000; + } else if (includeMarkedAsPlayed && item.isPlayed()) { + feedPlayedTime += media.getDuration() / 1000; + } } - if (item.isPlayed() || media.getPosition() != 0) { - episodesStartedIncludingMarked++; + boolean markedAsStarted = item.isPlayed() || media.getPosition() != 0; + boolean hasStatistics = media.getPlaybackCompletionDate() != null || media.getPlayedDuration() > 0; + if (hasStatistics || (includeMarkedAsPlayed && markedAsStarted)) { + episodesStarted++; } feedTotalTime += media.getDuration() / 1000; @@ -825,13 +830,12 @@ public final class DBReader { episodes++; } - feedTime.add(new StatisticsItem( - feed, feedTotalTime, feedPlayedTime, feedPlayedTimeCountAll, episodes, - episodesStarted, episodesStartedIncludingMarked, totalDownloadSize, episodesDownloadCount)); + result.feedTime.add(new StatisticsItem(feed, feedTotalTime, feedPlayedTime, episodes, + episodesStarted, totalDownloadSize, episodesDownloadCount)); } adapter.close(); - return feedTime; + return result; } /** diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/StatisticsItem.java b/core/src/main/java/de/danoeh/antennapod/core/storage/StatisticsItem.java index 90978d6b8..1bc4997dd 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/StatisticsItem.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/StatisticsItem.java @@ -12,11 +12,6 @@ public class StatisticsItem { public final long timePlayed; /** - * Simply sums up time of podcasts that are marked as played. - */ - public final long timePlayedCountAll; - - /** * Number of episodes. */ public final long episodes; @@ -27,11 +22,6 @@ public class StatisticsItem { public final long episodesStarted; /** - * 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; @@ -41,16 +31,14 @@ public class StatisticsItem { */ public final long episodesDownloadCount; - public StatisticsItem(Feed feed, long time, long timePlayed, long timePlayedCountAll, - long episodes, long episodesStarted, long episodesStartedIncludingMarked, + public StatisticsItem(Feed feed, long time, long timePlayed, + long episodes, long episodesStarted, long totalDownloadSize, long episodesDownloadCount) { this.feed = feed; this.time = time; this.timePlayed = timePlayed; - this.timePlayedCountAll = timePlayedCountAll; this.episodes = episodes; this.episodesStarted = episodesStarted; - this.episodesStartedIncludingMarked = episodesStartedIncludingMarked; this.totalDownloadSize = totalDownloadSize; this.episodesDownloadCount = episodesDownloadCount; } diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 1196c0eee..67dd3b3e4 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -44,17 +44,20 @@ <string name="change_setting">Change</string> <!-- Statistics fragment --> - <string name="total_time_listened_to_podcasts">Total time of episodes played:</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 episodes marked as played</string> + <string name="statistics_include_marked">Include duration of episodes that are just marked as played</string> <string name="statistics_speed_not_counted">Notice: Playback speed is never taken into account.</string> + <string name="statistics_from">From</string> + <string name="statistics_to">To</string> + <string name="statistics_today">Today</string> + <string name="statistics_filter_all_time">All time</string> + <string name="statistics_filter_last_year">Last year</string> <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> - <string name="statistics_counting_since">Since %s,\nyou played</string> + <string name="statistics_counting_range">Played between %1$s and %2$s</string> + <string name="statistics_counting_total">Played in total</string> <!-- Download Statistics fragment --> - <string name="total_size_downloaded_podcasts">Total size of episodes on the device:</string> + <string name="total_size_downloaded_podcasts">Total size of episodes on the device</string> <!-- Main activity --> <string name="drawer_open">Open menu</string> @@ -707,7 +710,6 @@ <string name="auto_download_disabled_globally">Auto download is disabled in the main AntennaPod settings</string> <string name="statistics_time_played">Time played:</string> <string name="statistics_total_duration">Total duration (estimate):</string> - <string name="statistics_duration_played_episodes">Duration of played episodes:</string> <string name="statistics_episodes_on_device">Episodes on the device:</string> <string name="statistics_space_used">Space used:</string> <string name="statistics_episodes_started_total">Episodes started/total:</string> |