Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to automatically mark filtered episodes as played #6252

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -46,6 +46,9 @@ public EpisodeFilterDialog(Context context, FeedFilter filter) {
termList = filter.getIncludeFilter();
viewBinding.includeRadio.setChecked(true);
}

viewBinding.markAsPlayedCheckBox.setChecked(filter.isMarkExcludedAsPlayed());

setupWordsList();

setNegativeButton(R.string.cancel_label, null);
Expand Down Expand Up @@ -99,7 +102,10 @@ private void onConfirmClick(DialogInterface dialog, int which) {
} else {
excludeFilter = toFilterString(termList);
}
onConfirmed(new FeedFilter(includeFilter, excludeFilter, minimalDuration));
boolean markExcludedAsRead = viewBinding.markAsPlayedCheckBox.isChecked();
onConfirmed(
new FeedFilter(includeFilter, excludeFilter, minimalDuration, markExcludedAsRead)
);
}

private String toFilterString(List<String> words) {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/episode_filter_dialog.xml
Expand Up @@ -94,6 +94,12 @@

</LinearLayout>

<CheckBox
android:id="@+id/markAsPlayedCheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mark_excluded_as_played" />

</LinearLayout>

</ScrollView>
Expand Up @@ -51,17 +51,21 @@ public Runnable autoDownloadUndownloadedItems(final Context context) {
Log.d(TAG, "Performing auto-dl of undownloaded episodes");

List<FeedItem> candidates;
List<FeedItem> markAsPlayedCandidates;
final List<FeedItem> queue = DBReader.getQueue();
final List<FeedItem> newItems = DBReader.getEpisodes(0, Integer.MAX_VALUE,
new FeedItemFilter(FeedItemFilter.NEW), SortOrder.DATE_NEW_OLD);
candidates = new ArrayList<>(queue.size() + newItems.size());
markAsPlayedCandidates = new ArrayList<>(queue.size() + newItems.size());
candidates.addAll(queue);
for (FeedItem newItem : newItems) {
FeedPreferences feedPrefs = newItem.getFeed().getPreferences();
if (feedPrefs.getAutoDownload()
&& !candidates.contains(newItem)
&& feedPrefs.getFilter().shouldAutoDownload(newItem)) {
candidates.add(newItem);
if (feedPrefs.getAutoDownload() && !candidates.contains(newItem)) {
if (feedPrefs.getFilter().shouldAutoDownload(newItem)) {
candidates.add(newItem);
} else if (feedPrefs.getFilter().isMarkExcludedAsPlayed()) {
markAsPlayedCandidates.add(newItem);
}
}
}

Expand Down Expand Up @@ -99,6 +103,10 @@ public Runnable autoDownloadUndownloadedItems(final Context context) {
DownloadServiceInterface.get().download(context, episode);
}
}

for (FeedItem itemToMarkAsPlayed: markAsPlayedCandidates) {
DBWriter.markItemPlayed(itemToMarkAsPlayed, FeedItem.PLAYED, true);
}
}
};
}
Expand Down
Expand Up @@ -12,22 +12,34 @@ public class FeedFilter implements Serializable {
private final String excludeFilter;
private final int minimalDuration;

private final boolean markExcludedAsPlayed;

public FeedFilter() {
this("", "", -1);
this("", "", -1, false);
}

public FeedFilter(String includeFilter, String excludeFilter, int minimalDuration) {
public FeedFilter(
String includeFilter,
String excludeFilter,
int minimalDuration,
boolean markExcludedAsPlayed
) {
// We're storing the strings and not the parsed terms because
// 1. It's easier to show the user exactly what they typed in this way
// (we don't have to recreate it)
// 2. We don't know if we'll actually be asked to parse anything anyways.
this.includeFilter = includeFilter;
this.excludeFilter = excludeFilter;
this.minimalDuration = minimalDuration;
this.markExcludedAsPlayed = markExcludedAsPlayed;
}

public FeedFilter(String includeFilter, String excludeFilter, int minimalDuration) {
this(includeFilter, excludeFilter, minimalDuration, false);
}

public FeedFilter(String includeFilter, String excludeFilter) {
this(includeFilter, excludeFilter, -1);
this(includeFilter, excludeFilter, -1, false);
}

/**
Expand Down Expand Up @@ -147,4 +159,8 @@ public boolean hasExcludeFilter() {
public boolean hasMinimalDurationFilter() {
return minimalDuration > -1;
}

public boolean isMarkExcludedAsPlayed() {
return markExcludedAsPlayed;
}
}
Expand Up @@ -334,6 +334,10 @@ static void upgrade(final SQLiteDatabase db, final int oldVersion, final int new
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
+ " ADD COLUMN " + PodDBAdapter.KEY_NEW_EPISODES_ACTION + " INTEGER DEFAULT 0");
}
if (oldVersion < 3020000) {
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
+ " ADD COLUMN " + PodDBAdapter.KEY_MARK_EXCLUDED_AS_PLAYED + " INTEGER DEFAULT 0;");
}
}

}
Expand Up @@ -52,7 +52,7 @@ public class PodDBAdapter {

private static final String TAG = "PodDBAdapter";
public static final String DATABASE_NAME = "Antennapod.db";
public static final int VERSION = 3010000;
public static final int VERSION = 3020000;

/**
* Maximum number of arguments for IN-operator.
Expand Down Expand Up @@ -113,6 +113,7 @@ public class PodDBAdapter {
public static final String KEY_INCLUDE_FILTER = "include_filter";
public static final String KEY_EXCLUDE_FILTER = "exclude_filter";
public static final String KEY_MINIMAL_DURATION_FILTER = "minimal_duration_filter";
public static final String KEY_MARK_EXCLUDED_AS_PLAYED = "mark_excluded_as_played";
public static final String KEY_FEED_PLAYBACK_SPEED = "feed_playback_speed";
public static final String KEY_FEED_SKIP_INTRO = "feed_skip_intro";
public static final String KEY_FEED_SKIP_ENDING = "feed_skip_ending";
Expand Down Expand Up @@ -148,6 +149,7 @@ public class PodDBAdapter {
+ KEY_INCLUDE_FILTER + " TEXT DEFAULT '',"
+ KEY_EXCLUDE_FILTER + " TEXT DEFAULT '',"
+ KEY_MINIMAL_DURATION_FILTER + " INTEGER DEFAULT -1,"
+ KEY_MARK_EXCLUDED_AS_PLAYED + " INTEGER DEFAULT -1,"
+ KEY_KEEP_UPDATED + " INTEGER DEFAULT 1,"
+ KEY_IS_PAGED + " INTEGER DEFAULT 0,"
+ KEY_NEXT_PAGE_LINK + " TEXT,"
Expand Down Expand Up @@ -307,6 +309,7 @@ public class PodDBAdapter {
+ TABLE_NAME_FEEDS + "." + KEY_INCLUDE_FILTER + ", "
+ TABLE_NAME_FEEDS + "." + KEY_EXCLUDE_FILTER + ", "
+ TABLE_NAME_FEEDS + "." + KEY_MINIMAL_DURATION_FILTER + ", "
+ TABLE_NAME_FEEDS + "." + KEY_MARK_EXCLUDED_AS_PLAYED + ", "
+ TABLE_NAME_FEEDS + "." + KEY_FEED_PLAYBACK_SPEED + ", "
+ TABLE_NAME_FEEDS + "." + KEY_FEED_TAGS + ", "
+ TABLE_NAME_FEEDS + "." + KEY_FEED_SKIP_INTRO + ", "
Expand Down Expand Up @@ -456,6 +459,7 @@ public void setFeedPreferences(FeedPreferences prefs) {
values.put(KEY_INCLUDE_FILTER, prefs.getFilter().getIncludeFilterRaw());
values.put(KEY_EXCLUDE_FILTER, prefs.getFilter().getExcludeFilterRaw());
values.put(KEY_MINIMAL_DURATION_FILTER, prefs.getFilter().getMinimalDurationFilter());
values.put(KEY_MARK_EXCLUDED_AS_PLAYED, prefs.getFilter().isMarkExcludedAsPlayed());
values.put(KEY_FEED_PLAYBACK_SPEED, prefs.getFeedPlaybackSpeed());
values.put(KEY_FEED_TAGS, prefs.getTagsAsString());
values.put(KEY_FEED_SKIP_INTRO, prefs.getFeedSkipIntro());
Expand Down
Expand Up @@ -30,6 +30,7 @@ public static FeedPreferences convert(@NonNull Cursor cursor) {
int indexIncludeFilter = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_INCLUDE_FILTER);
int indexExcludeFilter = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_EXCLUDE_FILTER);
int indexMinimalDurationFilter = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_MINIMAL_DURATION_FILTER);
int indexMarkExcludedAsPlayed = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_MARK_EXCLUDED_AS_PLAYED);
int indexFeedPlaybackSpeed = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_PLAYBACK_SPEED);
int indexAutoSkipIntro = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_SKIP_INTRO);
int indexAutoSkipEnding = cursor.getColumnIndexOrThrow(PodDBAdapter.KEY_FEED_SKIP_ENDING);
Expand All @@ -49,6 +50,7 @@ public static FeedPreferences convert(@NonNull Cursor cursor) {
String includeFilter = cursor.getString(indexIncludeFilter);
String excludeFilter = cursor.getString(indexExcludeFilter);
int minimalDurationFilter = cursor.getInt(indexMinimalDurationFilter);
boolean markExcludedAsPlayed = cursor.getInt(indexMarkExcludedAsPlayed) > 0;
float feedPlaybackSpeed = cursor.getFloat(indexFeedPlaybackSpeed);
int feedAutoSkipIntro = cursor.getInt(indexAutoSkipIntro);
int feedAutoSkipEnding = cursor.getInt(indexAutoSkipEnding);
Expand All @@ -66,7 +68,7 @@ public static FeedPreferences convert(@NonNull Cursor cursor) {
volumeAdaptionSetting,
username,
password,
new FeedFilter(includeFilter, excludeFilter, minimalDurationFilter),
new FeedFilter(includeFilter, excludeFilter, minimalDurationFilter, markExcludedAsPlayed),
feedPlaybackSpeed,
feedAutoSkipIntro,
feedAutoSkipEnding,
Expand Down
1 change: 1 addition & 0 deletions ui/i18n/src/main/res/values/strings.xml
Expand Up @@ -696,6 +696,7 @@
<string name="exclude_terms">Exclude episodes containing any of the terms below</string>
<string name="include_terms">Include only episodes containing any of the terms below</string>
<string name="exclude_episodes_shorter_than">Exclude episodes shorter than</string>
<string name="mark_excluded_as_played">Mark excluded episodes as played</string>
<string name="keep_updated">Keep updated</string>
<string name="keep_updated_summary">Include this podcast when (auto-)refreshing all podcasts</string>
<string name="auto_download_disabled_globally">Auto download is disabled in the main AntennaPod settings</string>
Expand Down