Skip to content

Commit

Permalink
add option to automatically mark filtered episodes as played
Browse files Browse the repository at this point in the history
  • Loading branch information
matejdro committed Dec 27, 2022
1 parent b670cf6 commit 228d670
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 11 deletions.
Expand Up @@ -4,8 +4,11 @@
import android.content.DialogInterface;
import android.text.TextUtils;
import android.view.LayoutInflater;

import androidx.recyclerview.widget.GridLayoutManager;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.SimpleChipAdapter;
import de.danoeh.antennapod.databinding.EpisodeFilterDialogBinding;
Expand Down Expand Up @@ -42,6 +45,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 @@ -95,7 +101,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,20 @@ 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.getNewItemsList(0, Integer.MAX_VALUE);
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);
}
}

// filter items that are not auto downloadable
Expand Down Expand Up @@ -102,6 +105,10 @@ public Runnable autoDownloadUndownloadedItems(final Context context) {
}
DownloadServiceInterface.get().download(context, false, requests.toArray(new DownloadRequest[0]));
}

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 @@ -330,6 +330,10 @@ static void upgrade(final SQLiteDatabase db, final int oldVersion, final int new
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_ITEMS
+ " ADD COLUMN " + PodDBAdapter.KEY_PODCASTINDEX_CHAPTER_URL + " TEXT");
}
if (oldVersion < 2070000) {
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
+ " ADD COLUMN " + PodDBAdapter.KEY_MARK_EXCLUDED_AS_PLAYED + " INTEGER DEFAULT 0;");
}
}

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

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

/**
* Maximum number of arguments for IN-operator.
Expand Down Expand Up @@ -111,6 +111,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 @@ -145,6 +146,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 @@ -303,6 +305,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 @@ -451,6 +454,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 @@ -64,7 +66,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 @@ -695,6 +695,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

0 comments on commit 228d670

Please sign in to comment.