summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorTom Hennen <TomHennen@users.noreply.github.com>2016-01-25 14:29:25 -0500
committerTom Hennen <TomHennen@users.noreply.github.com>2016-01-25 14:29:25 -0500
commitf9afe0d488bdb14798136fa183cb5831329b7cde (patch)
tree55f9b268a1e1eb58dd0f76989a856449c24445a1 /app/src
parent7f02570f88091ac46e447e7231583fe998cf6358 (diff)
parent8b0dac05c93e9e743a22fca3596775c367041855 (diff)
downloadAntennaPod-f9afe0d488bdb14798136fa183cb5831329b7cde.zip
Merge pull request #1612 from TomHennen/episode_filter
Episode autodownload filter
Diffstat (limited to 'app/src')
-rw-r--r--app/src/androidTest/java/de/test/antennapod/feed/FeedFilterTest.java119
-rw-r--r--app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java81
-rw-r--r--app/src/main/res/layout/feedinfo.xml82
3 files changed, 269 insertions, 13 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/feed/FeedFilterTest.java b/app/src/androidTest/java/de/test/antennapod/feed/FeedFilterTest.java
new file mode 100644
index 000000000..23a05ac8c
--- /dev/null
+++ b/app/src/androidTest/java/de/test/antennapod/feed/FeedFilterTest.java
@@ -0,0 +1,119 @@
+package de.test.antennapod.feed;
+
+import android.test.AndroidTestCase;
+
+import de.danoeh.antennapod.core.feed.FeedFilter;
+import de.danoeh.antennapod.core.feed.FeedItem;
+
+public class FeedFilterTest extends AndroidTestCase {
+
+ public void testNullFilter() throws Exception {
+ FeedFilter filter = new FeedFilter();
+ FeedItem item = new FeedItem();
+ item.setTitle("Hello world");
+
+ assertTrue(!filter.excludeOnly());
+ assertTrue(!filter.includeOnly());
+ assertEquals("", filter.getExcludeFilter());
+ assertEquals("", filter.getIncludeFilter());
+ assertTrue(filter.shouldAutoDownload(item));
+ }
+
+ public void testBasicIncludeFilter() throws Exception {
+ String includeFilter = "Hello";
+ FeedFilter filter = new FeedFilter(includeFilter, "");
+ FeedItem item = new FeedItem();
+ item.setTitle("Hello world");
+
+ FeedItem item2 = new FeedItem();
+ item2.setTitle("Don't include me");
+
+ assertTrue(!filter.excludeOnly());
+ assertTrue(filter.includeOnly());
+ assertEquals("", filter.getExcludeFilter());
+ assertEquals(includeFilter, filter.getIncludeFilter());
+ assertTrue(filter.shouldAutoDownload(item));
+ assertTrue(!filter.shouldAutoDownload(item2));
+ }
+
+ public void testBasicExcludeFilter() throws Exception {
+ String excludeFilter = "Hello";
+ FeedFilter filter = new FeedFilter("", excludeFilter);
+ FeedItem item = new FeedItem();
+ item.setTitle("Hello world");
+
+ FeedItem item2 = new FeedItem();
+ item2.setTitle("Item2");
+
+ assertTrue(filter.excludeOnly());
+ assertTrue(!filter.includeOnly());
+ assertEquals(excludeFilter, filter.getExcludeFilter());
+ assertEquals("", filter.getIncludeFilter());
+ assertTrue(!filter.shouldAutoDownload(item));
+ assertTrue(filter.shouldAutoDownload(item2));
+ }
+
+ public void testComplexIncludeFilter() throws Exception {
+ String includeFilter = "Hello \n\"Two words\"";
+ FeedFilter filter = new FeedFilter(includeFilter, "");
+ FeedItem item = new FeedItem();
+ item.setTitle("hello world");
+
+ FeedItem item2 = new FeedItem();
+ item2.setTitle("Two three words");
+
+ FeedItem item3 = new FeedItem();
+ item3.setTitle("One two words");
+
+ assertTrue(!filter.excludeOnly());
+ assertTrue(filter.includeOnly());
+ assertEquals("", filter.getExcludeFilter());
+ assertEquals(includeFilter, filter.getIncludeFilter());
+ assertTrue(filter.shouldAutoDownload(item));
+ assertTrue(!filter.shouldAutoDownload(item2));
+ assertTrue(filter.shouldAutoDownload(item3));
+ }
+
+ public void testComplexExcludeFilter() throws Exception {
+ String excludeFilter = "Hello \"Two words\"";
+ FeedFilter filter = new FeedFilter("", excludeFilter);
+ FeedItem item = new FeedItem();
+ item.setTitle("hello world");
+
+ FeedItem item2 = new FeedItem();
+ item2.setTitle("One three words");
+
+ FeedItem item3 = new FeedItem();
+ item3.setTitle("One two words");
+
+ assertTrue(filter.excludeOnly());
+ assertTrue(!filter.includeOnly());
+ assertEquals(excludeFilter, filter.getExcludeFilter());
+ assertEquals("", filter.getIncludeFilter());
+ assertTrue(!filter.shouldAutoDownload(item));
+ assertTrue(filter.shouldAutoDownload(item2));
+ assertTrue(!filter.shouldAutoDownload(item3));
+ }
+
+ public void testComboFilter() throws Exception {
+ String includeFilter = "Hello world";
+ String excludeFilter = "dislike";
+ FeedFilter filter = new FeedFilter(includeFilter, excludeFilter);
+
+ FeedItem download = new FeedItem();
+ download.setTitle("Hello everyone!");
+ // because, while it has words from the include filter it also has exclude words
+ FeedItem doNotDownload = new FeedItem();
+ doNotDownload.setTitle("I dislike the world");
+ // because it has no words from the include filter
+ FeedItem doNotDownload2 = new FeedItem();
+ doNotDownload2.setTitle("no words to include");
+
+ assertTrue(filter.hasExcludeFilter());
+ assertTrue(filter.hasIncludeFilter());
+ assertTrue(filter.shouldAutoDownload(download));
+ assertTrue(!filter.shouldAutoDownload(doNotDownload));
+ assertTrue(!filter.shouldAutoDownload(doNotDownload2));
+ }
+
+}
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java
index 80883e4ae..dedc3d9fd 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java
@@ -21,6 +21,7 @@ import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
+import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@@ -32,6 +33,7 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.core.feed.Feed;
+import de.danoeh.antennapod.core.feed.FeedFilter;
import de.danoeh.antennapod.core.feed.FeedPreferences;
import de.danoeh.antennapod.core.glide.ApGlideSettings;
import de.danoeh.antennapod.core.preferences.UserPreferences;
@@ -61,8 +63,12 @@ public class FeedInfoActivity extends ActionBarActivity {
private TextView txtvUrl;
private EditText etxtUsername;
private EditText etxtPassword;
+ private EditText etxtFilterText;
+ private RadioButton rdoFilterInclude;
+ private RadioButton rdoFilterExclude;
private CheckBox cbxAutoDownload;
private Spinner spnAutoDelete;
+ private boolean filterInclude = true;
private final View.OnClickListener copyUrlToClipboard = new View.OnClickListener() {
@Override
@@ -103,6 +109,17 @@ public class FeedInfoActivity extends ActionBarActivity {
spnAutoDelete = (Spinner) findViewById(R.id.spnAutoDelete);
etxtUsername = (EditText) findViewById(R.id.etxtUsername);
etxtPassword = (EditText) findViewById(R.id.etxtPassword);
+ etxtFilterText = (EditText) findViewById(R.id.etxtEpisodeFilterText);
+ rdoFilterInclude = (RadioButton) findViewById(R.id.radio_filter_include);
+ rdoFilterInclude.setOnClickListener(v -> {
+ filterInclude = true;
+ filterTextChanged = true;
+ });
+ rdoFilterExclude = (RadioButton) findViewById(R.id.radio_filter_exclude);
+ rdoFilterExclude.setOnClickListener(v -> {
+ filterInclude = false;
+ filterTextChanged = true;
+ });
txtvUrl.setOnClickListener(copyUrlToClipboard);
@@ -156,6 +173,7 @@ public class FeedInfoActivity extends ActionBarActivity {
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
feed.getPreferences().setAutoDownload(checked);
feed.savePreferences(FeedInfoActivity.this);
+ updateAutoDownloadSettings();
ApplyToEpisodesDialog dialog = new ApplyToEpisodesDialog(FeedInfoActivity.this,
feed, checked);
dialog.createNewDialog().show();
@@ -184,6 +202,7 @@ public class FeedInfoActivity extends ActionBarActivity {
feed.getPreferences().setAutoDeleteAction(auto_delete_action);// p
autoDeleteChanged = true;
}
+
@Override
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
@@ -197,8 +216,25 @@ public class FeedInfoActivity extends ActionBarActivity {
etxtUsername.addTextChangedListener(authTextWatcher);
etxtPassword.addTextChangedListener(authTextWatcher);
- supportInvalidateOptionsMenu();
+ FeedFilter filter = prefs.getFilter();
+ if (filter.includeOnly()) {
+ etxtFilterText.setText(filter.getIncludeFilter());
+ rdoFilterInclude.setChecked(true);
+ rdoFilterExclude.setChecked(false);
+ } else if (filter.excludeOnly()) {
+ etxtFilterText.setText(filter.getExcludeFilter());
+ rdoFilterInclude.setChecked(false);
+ rdoFilterExclude.setChecked(true);
+ } else {
+ Log.d(TAG, "No filter set");
+ rdoFilterInclude.setChecked(false);
+ rdoFilterExclude.setChecked(false);
+ etxtFilterText.setText("");
+ }
+ etxtFilterText.addTextChangedListener(filterTextWatcher);
+ supportInvalidateOptionsMenu();
+ updateAutoDownloadSettings();
} else {
Log.e(TAG, "Activity was started with invalid arguments");
}
@@ -227,6 +263,25 @@ public class FeedInfoActivity extends ActionBarActivity {
}
};
+ private boolean filterTextChanged = false;
+
+ private TextWatcher filterTextWatcher = new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ filterTextChanged = true;
+ }
+ };
+
@Override
protected void onPause() {
super.onPause();
@@ -237,11 +292,24 @@ public class FeedInfoActivity extends ActionBarActivity {
prefs.setUsername(etxtUsername.getText().toString());
prefs.setPassword(etxtPassword.getText().toString());
}
- if (authInfoChanged || autoDeleteChanged) {
+ if (filterTextChanged) {
+ Log.d(TAG, "Filter info changed, saving...");
+ String filterText = etxtFilterText.getText().toString();
+ String includeString = "";
+ String excludeString = "";
+ if (filterInclude) {
+ includeString = filterText;
+ } else {
+ excludeString = filterText;
+ }
+ prefs.setFilter(new FeedFilter(includeString, excludeString));
+ }
+ if (authInfoChanged || autoDeleteChanged || filterTextChanged) {
DBWriter.setFeedPreferences(prefs);
}
authInfoChanged = false;
autoDeleteChanged = false;
+ filterTextChanged = false;
}
}
@@ -282,6 +350,15 @@ public class FeedInfoActivity extends ActionBarActivity {
}
}
+ private void updateAutoDownloadSettings() {
+ if (feed != null && feed.getPreferences() != null) {
+ boolean enabled = feed.getPreferences().getAutoDownload() && UserPreferences.isEnableAutodownload();
+ rdoFilterInclude.setEnabled(enabled);
+ rdoFilterExclude.setEnabled(enabled);
+ etxtFilterText.setEnabled(enabled);
+ }
+ }
+
private class ApplyToEpisodesDialog extends ConfirmationDialog {
private final Feed feed;
diff --git a/app/src/main/res/layout/feedinfo.xml b/app/src/main/res/layout/feedinfo.xml
index 2b49b4b35..efc367c8b 100644
--- a/app/src/main/res/layout/feedinfo.xml
+++ b/app/src/main/res/layout/feedinfo.xml
@@ -150,17 +150,6 @@
android:text="@string/podcast_settings_label"
android:layout_marginTop="8dp"/>
- <CheckBox
- android:id="@+id/cbxAutoDownload"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="8dp"
- android:text="@string/auto_download_label"
- android:enabled="false"
- android:textColor="?android:attr/textColorPrimary"
- tools:background="@android:color/holo_red_light"
- android:checked="false" />
-
<android.support.v7.widget.GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -266,6 +255,77 @@
</android.support.v7.widget.GridLayout>
<TextView
+ android:id="@+id/txtvAutoDownloadSettings"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="8dp"
+ android:text="@string/auto_download_settings_label"
+ android:textSize="@dimen/text_size_medium"
+ android:textColor="?android:attr/textColorPrimary"/>
+
+ <CheckBox
+ android:id="@+id/cbxAutoDownload"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="8dp"
+ android:text="@string/auto_download_label"
+ android:enabled="false"
+ android:textColor="?android:attr/textColorPrimary"
+ tools:background="@android:color/holo_red_light"
+ android:checked="false" />
+
+ <TextView
+ android:id="@+id/txtvEpisodeFilters"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="8dp"
+ android:text="@string/episode_filters_label"
+ android:textSize="@dimen/text_size_medium"
+ android:textColor="?android:attr/textColorPrimary"/>
+
+ <TextView
+ android:id="@+id/txtvEpisodeFiltersDescription"
+ android:text="@string/episode_filters_description"
+ android:textSize="@dimen/text_size_small"
+ android:textColor="?android:attr/textColorPrimary"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="8dp"/>
+
+ <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/radio_filter_group"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:orientation="horizontal">
+ <RadioButton android:id="@+id/radio_filter_include"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/episode_filters_include"
+ android:onClick="onRadioButtonClicked"/>
+ <RadioButton android:id="@+id/radio_filter_exclude"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/episode_filters_exclude"
+ android:onClick="onRadioButtonClicked"/>
+ </RadioGroup>
+
+ <EditText
+ android:id="@+id/etxtEpisodeFilterText"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:lines="8"
+ android:minLines="1"
+ android:maxLines="20"
+ android:scrollbars="vertical"
+ android:hint="@string/episode_filters_hint"
+ android:focusable="true"
+ android:focusableInTouchMode="true"
+ android:cursorVisible="true"/>
+
+ <TextView
style="@style/AntennaPod.TextView.Heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"