summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2019-06-14 10:34:55 +0200
committerByteHamster <info@bytehamster.com>2019-06-14 10:34:55 +0200
commit5a7cbdfaca008e9049aaa3a0506e23aabd1a66a7 (patch)
tree48f7ef587d93c56f64753a3e61bd924d610b1020 /app/src
parent8f11f8a27149ce3a25bed7c2f97a0e03301929f1 (diff)
downloadAntennaPod-5a7cbdfaca008e9049aaa3a0506e23aabd1a66a7.zip
Added authentication and episode filter dialogs
Diffstat (limited to 'app/src')
-rw-r--r--app/src/free/java/de/danoeh/antennapod/preferences/PreferenceControllerFlavorHelper.java3
-rw-r--r--app/src/main/java/de/danoeh/antennapod/activity/FeedSettingsActivity.java91
-rw-r--r--app/src/main/java/de/danoeh/antennapod/dialog/EpisodeFilterDialog.java71
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java38
-rw-r--r--app/src/main/res/layout/episode_filter_dialog.xml96
-rw-r--r--app/src/main/res/layout/feedsettings.xml169
-rw-r--r--app/src/main/res/xml/feed_settings.xml2
7 files changed, 207 insertions, 263 deletions
diff --git a/app/src/free/java/de/danoeh/antennapod/preferences/PreferenceControllerFlavorHelper.java b/app/src/free/java/de/danoeh/antennapod/preferences/PreferenceControllerFlavorHelper.java
index ff39ed389..e096f883f 100644
--- a/app/src/free/java/de/danoeh/antennapod/preferences/PreferenceControllerFlavorHelper.java
+++ b/app/src/free/java/de/danoeh/antennapod/preferences/PreferenceControllerFlavorHelper.java
@@ -1,11 +1,12 @@
package de.danoeh.antennapod.preferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
+import de.danoeh.antennapod.fragment.preferences.PlaybackPreferencesFragment;
/**
* Implements functions from PreferenceController that are flavor dependent.
*/
-class PreferenceControllerFlavorHelper {
+public class PreferenceControllerFlavorHelper {
public static void setupFlavoredUI(PlaybackPreferencesFragment ui) {
ui.findPreference(UserPreferences.PREF_CAST_ENABLED).setEnabled(false);
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/FeedSettingsActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/FeedSettingsActivity.java
index 2a7e9d5c4..fd526d1db 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/FeedSettingsActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/FeedSettingsActivity.java
@@ -40,18 +40,6 @@ public class FeedSettingsActivity extends AppCompatActivity {
private ImageView imgvBackground;
private TextView txtvAuthorHeader;
- /*
- private EditText etxtUsername;
- private EditText etxtPassword;
- private EditText etxtFilterText;
- private RadioButton rdoFilterInclude;
- private RadioButton rdoFilterExclude;
- private CheckBox cbxAutoDownload;
- private CheckBox cbxKeepUpdated;
- private Spinner spnAutoDelete;
- private boolean filterInclude = true;
- */
-
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme());
@@ -69,22 +57,6 @@ public class FeedSettingsActivity extends AppCompatActivity {
// https://github.com/bumptech/glide/issues/529
imgvBackground.setColorFilter(new LightingColorFilter(0xff828282, 0x000000));
- /*
- etxtUsername = findViewById(R.id.etxtUsername);
- etxtPassword = findViewById(R.id.etxtPassword);
- etxtFilterText = findViewById(R.id.etxtEpisodeFilterText);
- rdoFilterInclude = findViewById(R.id.radio_filter_include);
- rdoFilterInclude.setOnClickListener(v -> {
- filterInclude = true;
- filterTextChanged = true;
- });
- rdoFilterExclude = findViewById(R.id.radio_filter_exclude);
- rdoFilterExclude.setOnClickListener(v -> {
- filterInclude = false;
- filterTextChanged = true;
- });
- */
-
disposable = Maybe.create((MaybeOnSubscribe<Feed>) emitter -> {
Feed feed = DBReader.getFeed(feedId);
if (feed != null) {
@@ -150,69 +122,6 @@ public class FeedSettingsActivity extends AppCompatActivity {
.into(imgvBackground);
}
- /*
- private void setupPrefs(Feed feed) {
- FeedPreferences prefs = feed.getPreferences();
-
- etxtUsername.setText(prefs.getUsername());
- etxtPassword.setText(prefs.getPassword());
-
- etxtUsername.addTextChangedListener(authTextWatcher);
- etxtPassword.addTextChangedListener(authTextWatcher);
-
- FeedFilter filter = prefs.getFilter();
- if (filter.includeOnly()) {
- etxtFilterText.setText(filter.getIncludeFilter());
- rdoFilterInclude.setChecked(true);
- rdoFilterExclude.setChecked(false);
- filterInclude = true;
- } else if (filter.excludeOnly()) {
- etxtFilterText.setText(filter.getExcludeFilter());
- rdoFilterInclude.setChecked(false);
- rdoFilterExclude.setChecked(true);
- filterInclude = false;
- } else {
- Log.d(TAG, "No filter set");
- rdoFilterInclude.setChecked(false);
- rdoFilterExclude.setChecked(false);
- etxtFilterText.setText("");
- }
- etxtFilterText.addTextChangedListener(filterTextWatcher);
-
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- if (feed != null) {
- FeedPreferences prefs = feed.getPreferences();
- if (authInfoChanged) {
- Log.d(TAG, "Auth info changed, saving credentials");
- prefs.setUsername(etxtUsername.getText().toString());
- prefs.setPassword(etxtPassword.getText().toString());
- }
- 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;
- }
- }
- */
-
@Override
public void onDestroy() {
super.onDestroy();
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/EpisodeFilterDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/EpisodeFilterDialog.java
new file mode 100644
index 000000000..ba778be56
--- /dev/null
+++ b/app/src/main/java/de/danoeh/antennapod/dialog/EpisodeFilterDialog.java
@@ -0,0 +1,71 @@
+package de.danoeh.antennapod.dialog;
+
+import android.app.Dialog;
+import android.content.Context;
+import android.os.Bundle;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.RadioButton;
+import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.core.feed.FeedFilter;
+
+/**
+ * Displays a dialog with a text box for filtering episodes and two radio buttons for exclusion/inclusion
+ */
+public abstract class EpisodeFilterDialog extends Dialog {
+
+ private final FeedFilter initialFilter;
+
+ public EpisodeFilterDialog(Context context, FeedFilter filter) {
+ super(context);
+ this.initialFilter = filter;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.episode_filter_dialog);
+ final EditText etxtEpisodeFilterText = findViewById(R.id.etxtEpisodeFilterText);
+ final RadioButton radioInclude = findViewById(R.id.radio_filter_include);
+ final RadioButton radioExclude = findViewById(R.id.radio_filter_exclude);
+ final Button butConfirm = findViewById(R.id.butConfirm);
+ final Button butCancel = findViewById(R.id.butCancel);
+
+ setTitle(R.string.episode_filters_label);
+ setOnCancelListener(dialog -> onCancelled());
+
+ if (initialFilter.includeOnly()) {
+ radioInclude.setChecked(true);
+ etxtEpisodeFilterText.setText(initialFilter.getIncludeFilter());
+ } else if(initialFilter.excludeOnly()) {
+ radioExclude.setChecked(true);
+ etxtEpisodeFilterText.setText(initialFilter.getExcludeFilter());
+ } else {
+ radioExclude.setChecked(false);
+ radioInclude.setChecked(false);
+ etxtEpisodeFilterText.setText("");
+ }
+
+
+ butCancel.setOnClickListener(v -> cancel());
+ butConfirm.setOnClickListener(v -> {
+
+ String includeString = "";
+ String excludeString = "";
+ if (radioInclude.isChecked()) {
+ includeString = etxtEpisodeFilterText.getText().toString();
+ } else {
+ excludeString = etxtEpisodeFilterText.getText().toString();
+ }
+
+ onConfirmed(new FeedFilter(includeString, excludeString));
+ dismiss();
+ });
+ }
+
+ protected void onCancelled() {
+
+ }
+
+ protected abstract void onConfirmed(FeedFilter filter);
+}
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java
index 02e264eec..6a321658f 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java
@@ -5,16 +5,21 @@ import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.ListPreference;
+import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.FeedSettingsActivity;
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
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.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBWriter;
+import de.danoeh.antennapod.dialog.AuthenticationDialog;
+import de.danoeh.antennapod.dialog.EpisodeFilterDialog;
public class FeedSettingsFragment extends PreferenceFragmentCompat {
+ private static final CharSequence PREF_EPISODE_FILTER = "episodeFilter";
private Feed feed;
private FeedPreferences feedPreferences;
@@ -28,11 +33,42 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
setupAutoDownloadPreference();
setupKeepUpdatedPreference();
setupAutoDeletePreference();
+ setupAuthentificationPreference();
+ setupEpisodeFilterPreference();
updateAutoDeleteSummary();
updateAutoDownloadEnabled();
}
+ private void setupEpisodeFilterPreference() {
+ findPreference(PREF_EPISODE_FILTER).setOnPreferenceClickListener(preference -> {
+ new EpisodeFilterDialog(getContext(), feedPreferences.getFilter()) {
+ @Override
+ protected void onConfirmed(FeedFilter filter) {
+ feedPreferences.setFilter(filter);
+ feed.savePreferences();
+ }
+ }.show();
+ return false;
+ });
+ }
+
+ private void setupAuthentificationPreference() {
+ findPreference("authentication").setOnPreferenceClickListener(preference -> {
+ new AuthenticationDialog(getContext(),
+ R.string.authentication_label, true, false,
+ feedPreferences.getUsername(), feedPreferences.getPassword()) {
+ @Override
+ protected void onConfirmed(String username, String password, boolean saveUsernamePassword) {
+ feedPreferences.setUsername(username);
+ feedPreferences.setPassword(password);
+ feed.savePreferences();
+ }
+ }.show();
+ return false;
+ });
+ }
+
private void setupAutoDeletePreference() {
ListPreference autoDeletePreference = (ListPreference) findPreference("autoDelete");
autoDeletePreference.setOnPreferenceChangeListener((preference, newValue) -> {
@@ -106,7 +142,7 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat {
private void updateAutoDownloadEnabled() {
if (feed != null && feed.getPreferences() != null) {
boolean enabled = feed.getPreferences().getAutoDownload() && UserPreferences.isEnableAutodownload();
- findPreference("filters").setEnabled(enabled);
+ findPreference(PREF_EPISODE_FILTER).setEnabled(enabled);
}
}
diff --git a/app/src/main/res/layout/episode_filter_dialog.xml b/app/src/main/res/layout/episode_filter_dialog.xml
new file mode 100644
index 000000000..7a5c47ee6
--- /dev/null
+++ b/app/src/main/res/layout/episode_filter_dialog.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <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" />
+
+ <RadioButton
+ android:id="@+id/radio_filter_exclude"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/episode_filters_exclude" />
+ </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" />
+ </LinearLayout>
+
+ <RelativeLayout
+ android:id="@+id/footer"
+ android:layout_width="fill_parent"
+ android:layout_height="48dp">
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="1dip"
+ android:layout_alignParentTop="true"
+ android:background="?android:attr/dividerVertical" />
+
+ <View
+ android:id="@+id/horizontal_divider"
+ android:layout_width="1dip"
+ android:layout_height="fill_parent"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="4dp"
+ android:layout_marginTop="4dp"
+ android:background="?android:attr/dividerVertical" />
+
+ <Button
+ android:id="@+id/butCancel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true"
+ android:layout_alignParentTop="true"
+ android:layout_toLeftOf="@id/horizontal_divider"
+ android:layout_toStartOf="@id/horizontal_divider"
+ android:background="?android:attr/selectableItemBackground"
+ android:text="@string/cancel_label" />
+
+ <Button
+ android:id="@+id/butConfirm"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentEnd="true"
+ android:layout_alignParentTop="true"
+ android:layout_toRightOf="@id/horizontal_divider"
+ android:layout_toEndOf="@id/horizontal_divider"
+ android:background="?android:attr/selectableItemBackground"
+ android:text="@string/confirm_label" />
+ </RelativeLayout>
+
+</LinearLayout>
diff --git a/app/src/main/res/layout/feedsettings.xml b/app/src/main/res/layout/feedsettings.xml
index 655fe4add..b40148b00 100644
--- a/app/src/main/res/layout/feedsettings.xml
+++ b/app/src/main/res/layout/feedsettings.xml
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
@@ -14,171 +12,4 @@
android:layout_weight="1"
android:id="@+id/settings_fragment_container" />
-<!--
- <ScrollView
- android:id="@+id/scrollView"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_weight="1"
- android:scrollbarStyle="outsideOverlay"
- android:paddingLeft="16dp"
- android:paddingRight="16dp"
- android:paddingBottom="8dp"
- android:clipToPadding="false">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
-
-
-
- <TextView
- android:id="@+id/txtvAuthentication"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="8dp"
- android:text="@string/authentication_label"
- android:textSize="@dimen/text_size_medium"
- android:textColor="?android:attr/textColorPrimary"/>
-
- <TextView
- android:id="@+id/txtvAuthenticationDescr"
- android:text="@string/authentication_descr"
- 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"/>
-
- <android.support.v7.widget.GridLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="8dp"
- app:columnCount="2"
- app:rowCount="3"
- android:layout_gravity="center_horizontal">
-
- <TextView
- android:id="@+id/txtvUsername"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginRight="8dp"
- android:layout_marginEnd="8dp"
- android:layout_marginBottom="8dp"
- app:layout_row="0"
- app:layout_column="0"
- android:text="@string/username_label"
- android:textColor="?android:attr/textColorPrimary"/>
-
- <EditText
- android:id="@+id/etxtUsername"
- android:layout_width="140sp"
- android:layout_height="wrap_content"
- app:layout_row="0"
- app:layout_column="1"
- android:hint="@string/username_label"
- android:focusable="true"
- android:focusableInTouchMode="true"
- android:cursorVisible="true"/>
-
- <TextView
- android:id="@+id/txtvPassword"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginRight="8dp"
- android:layout_marginEnd="8dp"
- android:layout_marginBottom="8dp"
- app:layout_row="1"
- app:layout_column="0"
- android:text="@string/password_label"
- android:textColor="?android:attr/textColorPrimary" />
-
- <EditText
- android:id="@+id/etxtPassword"
- android:layout_width="140sp"
- android:layout_height="wrap_content"
- app:layout_row="1"
- app:layout_column="1"
- android:hint="@string/password_label"
- android:inputType="textPassword"
- android:focusable="true"
- android:focusableInTouchMode="true"
- android:cursorVisible="true"/>
-
- </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" />
- <RadioButton android:id="@+id/radio_filter_exclude"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/episode_filters_exclude" />
- </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"/>
-
- </LinearLayout>
-
- </ScrollView>
--->
</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/xml/feed_settings.xml b/app/src/main/res/xml/feed_settings.xml
index f798b40d1..5fd6b2038 100644
--- a/app/src/main/res/xml/feed_settings.xml
+++ b/app/src/main/res/xml/feed_settings.xml
@@ -23,7 +23,7 @@
android:key="autoDownload"
android:title="@string/auto_download_label"/>
<Preference
- android:key="filters"
+ android:key="episodeFilter"
android:title="@string/episode_filters_label"
android:summary="@string/episode_filters_description"/>
</PreferenceCategory>