Fix Echo "check out again" recommendation logic (#7803)

This commit is contained in:
HayashiRyota
2025-05-09 05:54:21 +09:00
committed by GitHub
parent b4de4548ae
commit b196f348bf
4 changed files with 22 additions and 7 deletions

View File

@ -612,8 +612,9 @@ public final class DBReader {
adapter.open(); adapter.open();
StatisticsResult result = new StatisticsResult(); StatisticsResult result = new StatisticsResult();
long sixMonthsAgo = System.currentTimeMillis() - (long) (1000L * 3600 * 24 * 30.44 * 6);
try (FeedCursor cursor = new FeedCursor(adapter.getFeedStatisticsCursor( try (FeedCursor cursor = new FeedCursor(adapter.getFeedStatisticsCursor(
includeMarkedAsPlayed, timeFilterFrom, timeFilterTo))) { includeMarkedAsPlayed, timeFilterFrom, timeFilterTo, sixMonthsAgo))) {
int indexOldestDate = cursor.getColumnIndexOrThrow("oldest_date"); int indexOldestDate = cursor.getColumnIndexOrThrow("oldest_date");
int indexNumEpisodes = cursor.getColumnIndexOrThrow("num_episodes"); int indexNumEpisodes = cursor.getColumnIndexOrThrow("num_episodes");
int indexEpisodesStarted = cursor.getColumnIndexOrThrow("episodes_started"); int indexEpisodesStarted = cursor.getColumnIndexOrThrow("episodes_started");
@ -621,6 +622,7 @@ public final class DBReader {
int indexPlayedTime = cursor.getColumnIndexOrThrow("played_time"); int indexPlayedTime = cursor.getColumnIndexOrThrow("played_time");
int indexNumDownloaded = cursor.getColumnIndexOrThrow("num_downloaded"); int indexNumDownloaded = cursor.getColumnIndexOrThrow("num_downloaded");
int indexDownloadSize = cursor.getColumnIndexOrThrow("download_size"); int indexDownloadSize = cursor.getColumnIndexOrThrow("download_size");
int indexNumRecentUnplayed = cursor.getColumnIndexOrThrow("num_recent_unplayed");
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
Feed feed = cursor.getFeed(); Feed feed = cursor.getFeed();
@ -632,13 +634,14 @@ public final class DBReader {
long totalDownloadSize = cursor.getLong(indexDownloadSize); long totalDownloadSize = cursor.getLong(indexDownloadSize);
long episodesDownloadCount = cursor.getLong(indexNumDownloaded); long episodesDownloadCount = cursor.getLong(indexNumDownloaded);
long oldestDate = cursor.getLong(indexOldestDate); long oldestDate = cursor.getLong(indexOldestDate);
boolean hasRecentUnplayed = cursor.getLong(indexNumRecentUnplayed) > 0;
if (episodes > 0 && oldestDate < Long.MAX_VALUE) { if (episodes > 0 && oldestDate < Long.MAX_VALUE) {
result.oldestDate = Math.min(result.oldestDate, oldestDate); result.oldestDate = Math.min(result.oldestDate, oldestDate);
} }
result.feedTime.add(new StatisticsItem(feed, feedTotalTime, feedPlayedTime, episodes, result.feedTime.add(new StatisticsItem(feed, feedTotalTime, feedPlayedTime, episodes,
episodesStarted, totalDownloadSize, episodesDownloadCount)); episodesStarted, totalDownloadSize, episodesDownloadCount, hasRecentUnplayed));
} }
} }
adapter.close(); adapter.close();

View File

@ -1215,7 +1215,8 @@ public class PodDBAdapter {
return db.rawQuery(query, null); return db.rawQuery(query, null);
} }
public final Cursor getFeedStatisticsCursor(boolean includeMarkedAsPlayed, long timeFilterFrom, long timeFilterTo) { public final Cursor getFeedStatisticsCursor(boolean includeMarkedAsPlayed, long timeFilterFrom,
long timeFilterTo, long sixMonthsAgo) {
final String lastPlayedTime = TABLE_NAME_FEED_MEDIA + "." + KEY_LAST_PLAYED_TIME; final String lastPlayedTime = TABLE_NAME_FEED_MEDIA + "." + KEY_LAST_PLAYED_TIME;
String wasStarted = TABLE_NAME_FEED_MEDIA + "." + KEY_PLAYBACK_COMPLETION_DATE + " > 0" String wasStarted = TABLE_NAME_FEED_MEDIA + "." + KEY_PLAYBACK_COMPLETION_DATE + " > 0"
+ " AND " + TABLE_NAME_FEED_MEDIA + "." + KEY_PLAYED_DURATION + " > 0"; + " AND " + TABLE_NAME_FEED_MEDIA + "." + KEY_PLAYED_DURATION + " > 0";
@ -1246,7 +1247,10 @@ public class PodDBAdapter {
+ "SUM(CASE WHEN " + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOAD_DATE + " > 0" + "SUM(CASE WHEN " + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOAD_DATE + " > 0"
+ " THEN 1 ELSE 0 END) AS num_downloaded, " + " THEN 1 ELSE 0 END) AS num_downloaded, "
+ "SUM(CASE WHEN " + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOAD_DATE + " > 0" + "SUM(CASE WHEN " + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOAD_DATE + " > 0"
+ " THEN " + TABLE_NAME_FEED_MEDIA + "." + KEY_SIZE + " ELSE 0 END) AS download_size" + " THEN " + TABLE_NAME_FEED_MEDIA + "." + KEY_SIZE + " ELSE 0 END) AS download_size, "
+ "SUM(CASE WHEN " + TABLE_NAME_FEED_ITEMS + "." + KEY_READ + " != " + FeedItem.PLAYED
+ " AND " + TABLE_NAME_FEED_ITEMS + "." + KEY_PUBDATE + " >= " + sixMonthsAgo
+ " THEN 1 ELSE 0 END) AS num_recent_unplayed "
+ " FROM " + TABLE_NAME_FEED_ITEMS + " FROM " + TABLE_NAME_FEED_ITEMS
+ JOIN_FEED_ITEM_AND_MEDIA + JOIN_FEED_ITEM_AND_MEDIA
+ " INNER JOIN " + TABLE_NAME_FEEDS + " INNER JOIN " + TABLE_NAME_FEEDS

View File

@ -31,9 +31,11 @@ public class StatisticsItem {
*/ */
public final long episodesDownloadCount; public final long episodesDownloadCount;
public final boolean hasRecentUnplayed;
public StatisticsItem(Feed feed, long time, long timePlayed, public StatisticsItem(Feed feed, long time, long timePlayed,
long episodes, long episodesStarted, long episodes, long episodesStarted,
long totalDownloadSize, long episodesDownloadCount) { long totalDownloadSize, long episodesDownloadCount, boolean hasRecentUnplayed) {
this.feed = feed; this.feed = feed;
this.time = time; this.time = time;
this.timePlayed = timePlayed; this.timePlayed = timePlayed;
@ -41,5 +43,6 @@ public class StatisticsItem {
this.episodesStarted = episodesStarted; this.episodesStarted = episodesStarted;
this.totalDownloadSize = totalDownloadSize; this.totalDownloadSize = totalDownloadSize;
this.episodesDownloadCount = episodesDownloadCount; this.episodesDownloadCount = episodesDownloadCount;
this.hasRecentUnplayed = hasRecentUnplayed;
} }
} }

View File

@ -1,6 +1,7 @@
package de.danoeh.antennapod.ui.echo.screen; package de.danoeh.antennapod.ui.echo.screen;
import android.content.Context; import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import de.danoeh.antennapod.storage.database.DBReader; import de.danoeh.antennapod.storage.database.DBReader;
@ -62,8 +63,12 @@ public class HoarderScreen extends EchoScreen {
totalActivePodcasts++; totalActivePodcasts++;
if (item.timePlayed > 0) { if (item.timePlayed > 0) {
playedActivePodcasts++; playedActivePodcasts++;
} else { } else if (item.hasRecentUnplayed) {
unplayedActive.add(item.feed.getTitle()); String title = item.feed.getTitle();
if (TextUtils.isEmpty(title)) {
title = item.feed.getFeedIdentifier();
}
unplayedActive.add(title);
} }
} }
} }