summaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java17
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java71
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java11
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/StatisticsItem.java16
-rw-r--r--core/src/main/res/values/strings.xml19
6 files changed, 75 insertions, 61 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 527d1f373..82ad27dcd 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;
@@ -1057,22 +1056,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/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
index e46e8d72c..d6d11bc8a 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
@@ -1091,7 +1091,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|| autoSkipped
|| (skipped && !UserPreferences.shouldSkipKeepEpisode())) {
// only mark the item as played if we're not keeping it anyways
- DBWriter.markItemPlayed(item, FeedItem.PLAYED, ended);
+ DBWriter.markItemPlayed(item, FeedItem.PLAYED, ended || (skipped && smartMarkAsPlayed));
// don't know if it actually matters to not autodownload when smart mark as played is triggered
DBWriter.removeQueueItem(PlaybackService.this, ended, item);
// Delete episode if enabled
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..11ff813a9 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,56 @@ public final class DBReader {
}
}
+ public static class MonthlyStatisticsItem {
+ public int year = 0;
+ public int month = 0;
+ public long timePlayed = 0;
+ }
+
+ @NonNull
+ public static List<MonthlyStatisticsItem> getMonthlyTimeStatistics() {
+ List<MonthlyStatisticsItem> months = new ArrayList<>();
+ PodDBAdapter adapter = PodDBAdapter.getInstance();
+ adapter.open();
+ try (Cursor cursor = adapter.getMonthlyStatisticsCursor()) {
+ int indexMonth = cursor.getColumnIndexOrThrow("month");
+ int indexYear = cursor.getColumnIndexOrThrow("year");
+ int indexTotalDuration = cursor.getColumnIndexOrThrow("total_duration");
+ while (cursor.moveToNext()) {
+ MonthlyStatisticsItem item = new MonthlyStatisticsItem();
+ item.month = Integer.parseInt(cursor.getString(indexMonth));
+ item.year = Integer.parseInt(cursor.getString(indexYear));
+ item.timePlayed = cursor.getLong(indexTotalDuration);
+ months.add(item);
+ }
+ }
+ adapter.close();
+ return months;
+ }
+
+ 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 +830,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 +857,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/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
index 43d9c7f11..ea4617f16 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
@@ -1133,6 +1133,17 @@ public class PodDBAdapter {
return db.rawQuery(query, null);
}
+ public final Cursor getMonthlyStatisticsCursor() {
+ final String query = "SELECT SUM(" + KEY_PLAYED_DURATION + ") AS total_duration"
+ + ", strftime('%m', datetime(" + KEY_LAST_PLAYED_TIME + "/1000, 'unixepoch')) AS month"
+ + ", strftime('%Y', datetime(" + KEY_LAST_PLAYED_TIME + "/1000, 'unixepoch')) AS year"
+ + " FROM " + TABLE_NAME_FEED_MEDIA
+ + " WHERE " + KEY_LAST_PLAYED_TIME + " > 0 AND " + KEY_PLAYED_DURATION + " > 0"
+ + " GROUP BY year, month"
+ + " ORDER BY year, month";
+ return db.rawQuery(query, null);
+ }
+
public int getQueueSize() {
final String query = String.format("SELECT COUNT(%s) FROM %s", KEY_ID, TABLE_NAME_QUEUE);
Cursor c = db.rawQuery(query, null);
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 ed2bd8d54..197d0c636 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -28,8 +28,7 @@
<string name="gpodnet_main_label">gpodder.net</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>
+ <string name="years_statistics_label">Years</string>
<string name="notification_pref_fragment">Notifications</string>
<!-- Google Assistant -->
@@ -44,17 +43,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>
@@ -702,7 +704,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>