From f243bcd4cce1f3af9449c74fa38f6c90f2ea9d22 Mon Sep 17 00:00:00 2001 From: bws9000 Date: Sun, 21 Jun 2020 12:52:15 +0200 Subject: [PATCH] Redesign filter dialog --- .../antennapod/dialog/FilterDialog.java | 121 ++++++++++++++---- .../main/res/layout/filter_dialog_layout.xml | 11 ++ .../filter_dialog_relative_cardview.xml | 55 ++++++++ .../core/feed/FeedItemFilterGroup.java | 84 ++++++++++++ .../main/res/drawable-hdpi/x_custom_off.png | Bin 0 -> 1062 bytes .../main/res/drawable-hdpi/x_custom_on.png | Bin 0 -> 1093 bytes .../main/res/drawable/filter_dialog_x_off.xml | 56 ++++++++ .../main/res/drawable/filter_dialog_x_on.xml | 56 ++++++++ core/src/main/res/values/arrays.xml | 12 -- core/src/main/res/values/strings.xml | 21 +-- 10 files changed, 371 insertions(+), 45 deletions(-) create mode 100644 app/src/main/res/layout/filter_dialog_layout.xml create mode 100644 app/src/main/res/layout/filter_dialog_relative_cardview.xml create mode 100644 core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilterGroup.java create mode 100644 core/src/main/res/drawable-hdpi/x_custom_off.png create mode 100644 core/src/main/res/drawable-hdpi/x_custom_on.png create mode 100644 core/src/main/res/drawable/filter_dialog_x_off.xml create mode 100644 core/src/main/res/drawable/filter_dialog_x_on.xml diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java index d2912f90f..ece286eb4 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java @@ -1,15 +1,22 @@ package de.danoeh.antennapod.dialog; import android.content.Context; +import android.graphics.Color; +import android.view.LayoutInflater; +import android.widget.LinearLayout; +import android.widget.RadioButton; +import android.widget.RelativeLayout; + import androidx.appcompat.app.AlertDialog; -import android.text.TextUtils; import java.util.Arrays; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.FeedItemFilter; +import de.danoeh.antennapod.core.feed.FeedItemFilterGroup; public abstract class FilterDialog { @@ -22,38 +29,102 @@ public abstract class FilterDialog { } public void openDialog() { - final String[] items = context.getResources().getStringArray(R.array.episode_filter_options); - final String[] values = context.getResources().getStringArray(R.array.episode_filter_values); - final boolean[] checkedItems = new boolean[items.length]; final Set filterValues = new HashSet<>(Arrays.asList(filter.getValues())); - - // make sure we have no empty strings in the filter list - for (String filterValue : filterValues) { - if (TextUtils.isEmpty(filterValue)) { - filterValues.remove(filterValue); - } - } - - for (int i = 0; i < values.length; i++) { - String value = values[i]; - if (filterValues.contains(value)) { - checkedItems[i] = true; - } - } - AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.filter); - builder.setMultiChoiceItems(items, checkedItems, (dialog, which, isChecked) -> { - if (isChecked) { - filterValues.add(values[which]); - } else { - filterValues.remove(values[which]); + + LayoutInflater inflater = LayoutInflater.from(this.context); + LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.filter_dialog_layout, null, false); + builder.setView(layout); + + for (FeedItemFilterGroup.FeedItemEnum item : FeedItemFilterGroup.FeedItemEnum.values()) { + + RelativeLayout row = (RelativeLayout) inflater.inflate(R.layout.filter_dialog_relative_cardview, null); + RadioButton radioButton1 = row.findViewById(R.id.filter_dialog_radioButton1); + RadioButton radioButton2 = row.findViewById(R.id.filter_dialog_radioButton2); + RadioButton radioButton3 = row.findViewById(R.id.filter_dialog_radioButton3); + radioButton1.setText(item.values[1].displayName); + radioButton1.setTextColor(Color.BLACK); + radioButton2.setText(item.values[0].displayName); + radioButton2.setTextColor(Color.BLACK); + + Iterator filterIterator = filterValues.iterator(); + while (filterIterator.hasNext()) { + String nextItem = filterIterator.next(); + if (item.values[1].filterId.equals(nextItem)) { + item.values[1].setSelected(true); + item.values[0].setSelected(false); + radioButton1.setBackgroundResource(R.color.accent_light); + radioButton2.setBackgroundResource(R.color.master_switch_background_light); + radioButton3.setBackgroundResource(R.drawable.filter_dialog_x_on); + radioButton1.setSelected(true); + radioButton2.setSelected(false); + radioButton1.setTextColor(Color.WHITE); + radioButton2.setTextColor(Color.BLACK); + } + if (item.values[0].filterId.equals(nextItem)) { + item.values[0].setSelected(true); + item.values[1].setSelected(false); + radioButton2.setBackgroundResource(R.color.accent_light); + radioButton1.setBackgroundResource(R.color.master_switch_background_light); + radioButton3.setBackgroundResource(R.drawable.filter_dialog_x_on); + radioButton2.setSelected(true); + radioButton1.setSelected(false); + radioButton2.setTextColor(Color.WHITE); + radioButton1.setTextColor(Color.BLACK); + } } - }); + + radioButton1.setOnClickListener(arg0 -> { + item.values[1].setSelected(true); + item.values[0].setSelected(false); + radioButton1.setBackgroundResource(R.color.accent_light); + radioButton2.setBackgroundResource(R.color.master_switch_background_light); + radioButton3.setBackgroundResource(R.drawable.filter_dialog_x_on); + radioButton2.setSelected(false); + radioButton2.setTextColor(Color.BLACK); + radioButton1.setSelected(true); + radioButton1.setTextColor(Color.WHITE); + }); + radioButton2.setOnClickListener(arg0 -> { + item.values[0].setSelected(true); + item.values[1].setSelected(false); + radioButton2.setBackgroundResource(R.color.accent_light); + radioButton1.setBackgroundResource(R.color.master_switch_background_light); + radioButton3.setBackgroundResource(R.drawable.filter_dialog_x_on); + radioButton1.setSelected(false); + radioButton1.setTextColor(Color.BLACK); + radioButton2.setSelected(true); + radioButton2.setTextColor(Color.WHITE); + }); + radioButton3.setOnClickListener(arg0 -> { + item.values[0].setSelected(false); + item.values[1].setSelected(false); + radioButton1.setBackgroundResource(R.color.master_switch_background_light); + radioButton2.setBackgroundResource(R.color.master_switch_background_light); + radioButton3.setBackgroundResource(R.drawable.filter_dialog_x_off); + radioButton2.setTextColor(Color.BLACK); + radioButton2.setSelected(false); + radioButton1.setTextColor(Color.BLACK); + radioButton1.setSelected(false); + }); + layout.addView(row); + } + + builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> { + filterValues.clear(); + for (FeedItemFilterGroup.FeedItemEnum item : FeedItemFilterGroup.FeedItemEnum.values()) { + for (int i = 0; i < item.values.length; i++) { + if (item.values[i].getSelected()) { + filterValues.add(item.values[i].filterId); + } + } + } updateFilter(filterValues); }); + builder.setNegativeButton(R.string.cancel_label, null); builder.create().show(); } diff --git a/app/src/main/res/layout/filter_dialog_layout.xml b/app/src/main/res/layout/filter_dialog_layout.xml new file mode 100644 index 000000000..c50e08814 --- /dev/null +++ b/app/src/main/res/layout/filter_dialog_layout.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/filter_dialog_relative_cardview.xml b/app/src/main/res/layout/filter_dialog_relative_cardview.xml new file mode 100644 index 000000000..e3dc94f64 --- /dev/null +++ b/app/src/main/res/layout/filter_dialog_relative_cardview.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilterGroup.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilterGroup.java new file mode 100644 index 000000000..18c1c186d --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilterGroup.java @@ -0,0 +1,84 @@ +package de.danoeh.antennapod.core.feed; + +import de.danoeh.antennapod.core.R; + +public class FeedItemFilterGroup { + + private static boolean DEFAULT_SELECTED_STATE = false; + + private static final String NO_FILTERID = ""; + private static final int HASMEDIA_LABEL = R.string.has_media; + private static final int NOTPAUSED_LABEL = R.string.not_paused; + private static final int NOTFAVORITE_LABEL = R.string.not_favorite; + + private static final int UNPLAYED_LABEL = R.string.not_played; + private static final String UNPLAYED_FILTERID = "unplayed"; + + private static final int PLAYED_LABEL = R.string.hide_played_episodes_label; + private static final String PLAYED_FILTERID = "played"; + + private static final int PAUSED_LABEL = R.string.hide_paused_episodes_label; + private static final String PAUSED_FILTERID = "paused"; + + private static final int ISFAVORITE_LABEL = R.string.hide_is_favorite_label; + private static final String ISFAVORITE_FILTERID = "is_favorite"; + + private static final int NOMEDIA_LABEL = R.string.no_media; + private static final String NOMEDIA_FILTERID = "no_media"; + + private static final int QUEUED_LABEL = R.string.queue_label; + private static final String QUEUED_FILTERID = "queued"; + + private static final int NOTQUEUED_LABEL = R.string.not_queued_label; + private static final String NOTQUEUED_FILTERID = "not_queued"; + + private static final int NOTDOWNLOADED_LABEL = R.string.hide_downloaded_episodes_label; + private static final String NOTDOWNLOADED_FILTERID = "not_downloaded"; + + private static final int DOWNLOADED_LABEL = R.string.hide_downloaded_episodes_label; + private static final String DOWNLOADED_FILTERID = "downloaded"; + + public enum FeedItemEnum { + + PLAYED(new ItemProperties(DEFAULT_SELECTED_STATE, UNPLAYED_LABEL, UNPLAYED_FILTERID), + new ItemProperties(DEFAULT_SELECTED_STATE, PLAYED_LABEL, PLAYED_FILTERID)), + PAUSED(new ItemProperties(DEFAULT_SELECTED_STATE, NOTPAUSED_LABEL, NO_FILTERID), + new ItemProperties(DEFAULT_SELECTED_STATE, PAUSED_LABEL, PAUSED_FILTERID)), + FAVORITE(new ItemProperties(DEFAULT_SELECTED_STATE, NOTFAVORITE_LABEL, NO_FILTERID), + new ItemProperties(DEFAULT_SELECTED_STATE, ISFAVORITE_LABEL, ISFAVORITE_FILTERID)), + MEDIA(new ItemProperties(DEFAULT_SELECTED_STATE, NOMEDIA_LABEL, NOMEDIA_FILTERID), + new ItemProperties(DEFAULT_SELECTED_STATE, HASMEDIA_LABEL, NO_FILTERID)), + QUEUED(new ItemProperties(DEFAULT_SELECTED_STATE, NOTQUEUED_LABEL, NOTQUEUED_FILTERID), + new ItemProperties(DEFAULT_SELECTED_STATE, QUEUED_LABEL, QUEUED_FILTERID)), + DOWNLOADED(new ItemProperties(DEFAULT_SELECTED_STATE, NOTDOWNLOADED_LABEL, NOTDOWNLOADED_FILTERID), + new ItemProperties(DEFAULT_SELECTED_STATE, DOWNLOADED_LABEL, DOWNLOADED_FILTERID)); + + public final ItemProperties[] values; + + FeedItemEnum(ItemProperties... values) { + this.values = values; + } + + public static class ItemProperties { + + public final int displayName; + public boolean selected; + public final String filterId; + + public void setSelected(boolean value) { + this.selected = value; + } + + public boolean getSelected() { + return this.selected; + } + + public ItemProperties(boolean selected, int displayName, String filterId) { + this.selected = selected; + this.displayName = displayName; + this.filterId = filterId; + } + + } + } +} diff --git a/core/src/main/res/drawable-hdpi/x_custom_off.png b/core/src/main/res/drawable-hdpi/x_custom_off.png new file mode 100644 index 0000000000000000000000000000000000000000..2450d2e89eed9bd7de795a75e99dc1f24412b23c GIT binary patch literal 1062 zcmV+>1ljwEP)-z3xW^Qq$na*P<&`q@P-u|#1qkIwNa-08y1^$*|SelBb^U6?7h#LHS?b{vu4dY z1OkCTAP@)y0)apv5D4@FN_>XU*w~oFtPGf<>vLc@P@&IW0FQxNz%^ZO3puQ>ulM?< z%Dk-e;|5*}R0D%@Sbm~wB2WW#0B3-c65K6xm#8XWnFj2`KwuH@HP8&S^afF-zzY33 zmcM{sf$P8nAOrLP1_MKZN?;Z+Ol{nk;pW&RU=Pssp+q@B-vcvZV)g^SWf|BT;GwSH zfrG$IUt^))oFs6uc#^J zS9%hgE{;pUA=zvK`e*SmTkG*pU~86)qE)_;AJ?ZBX+%ZjigL&F*%)AbEEW3#SgGv6 z1&8NZ+IPh^;i;Zu^cFSV+~3Gy66Ugqb&7~_ zs^l9*L3j4*QBiI%r_J-XCLu*Roy!3JP;#1$=(E0N?~3RrpAl!16lUV2Ir*M6#T9pA zty6|jt}LNRIpCW-J}xLC4$}I|Xxi18Q*b8Xp4Kg*UZ{@Hpl3G)pXoew&cn|ob6=v9 zw4Kg-(^i<$ZoaK5ZAH{*DwU`3)n9FE%)2wiRF;a#DBL%B(L8?%?AAh0QY0;vZIjwY zT$JzB6jM#=Qq{+n$cAX6U1CaP_f0P6*3c+z%(g@parQ%($WZ6M05_FAM3Kyio3ASg z8T~rFqL>-cqT|FoRe}a2Z1-I2=R|KTJEK7z29B6N2qxtCgP_gl4}$+afj}S-2m}Iw gKp+qZ1U^21_c&zC|81?Z!2kdN07*qoM6N<$g0kH8y#N3J literal 0 HcmV?d00001 diff --git a/core/src/main/res/drawable-hdpi/x_custom_on.png b/core/src/main/res/drawable-hdpi/x_custom_on.png new file mode 100644 index 0000000000000000000000000000000000000000..07525f9253edfb493b78f3059ac61597bdb319de GIT binary patch literal 1093 zcmV-L1iJf)P)5 z_FfV%5Nlzze`rz(QcI-i-s-fqvi|a2B{* zOkrDFo7XQj%}cs4ZsM&#Gq4~*vQF32Knrja=mz%4;Ic5aOnRDtA>iEt2IZqheTJlC zQW#YQ^ZURoL>8mw#wO4!ulHZpNvLnDbVYQTP~b%tquk)NYX1Uk0`BX6 zIq;;MLm{dq=dPKOyDwcMy06t(6*p?S;!s4pmQTb|1=axt-6TE*E&(3{6Gq1A+F|aS zHD*PPYBX`^=h$*_90PVr=D6H=oK4z~Kgr8Y#NPKxH`3$AthiAThZDTqhw^I96Yh_t zV$TAf1Gj;ffm?a{=cGHr#X2v1jaq5i=M!Yy-q;9yFR%8#p1XZ^RPoJa4_6C}V|Cjx zQ{fwYA2aR20&@QVYk>>ETfjBoO)aPGz?mZBSlvrJ=ji>V=9u=)BC@~Auz!KCfhT~k z6ts&mmM~^2%9YS2;g(>Z-rduFt2n+!-8Su-6!M#aSAoB^)Ll;aP>Oyw)3;-$!q=!_ z({3mt`@C{E7ki$OM|8pVn-s;V)osVDh*1Nk{agXL#ri7F(`^8Llt=7WY}#359IN{W z&pCP<)o0pG3AK;g*e8Mcz&mOqkLWV+-+=ezM3UxY3r0I;DzX?A15S<3lw zodiYsnOlOtD^vKwL(ehOc0cZCvE|&7^@J&F@a@&nmYu)}V0H#wv(&f6JnN1nwO*8x zQEXF!8nFtv47`?7Zg(bZ4d%qjHKl`^+=99}epHt3##A!>V+v)o#?gVae8; z{`*QjNumrVv^iC$-zj^DJXyV};`Wq!M)h?vFF8xO657Km<##0%eo5R?pQYt8h%%q0 zkLw8e1I4OF^9R8^$^2pdAn4QO9ftyeKp+qZ1OkCTAP@)yCOyFaN72cooI-*O00000 LNkvXXu0mjf4#5+W literal 0 HcmV?d00001 diff --git a/core/src/main/res/drawable/filter_dialog_x_off.xml b/core/src/main/res/drawable/filter_dialog_x_off.xml new file mode 100644 index 000000000..8368ffa51 --- /dev/null +++ b/core/src/main/res/drawable/filter_dialog_x_off.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/main/res/drawable/filter_dialog_x_on.xml b/core/src/main/res/drawable/filter_dialog_x_on.xml new file mode 100644 index 000000000..b25b42df3 --- /dev/null +++ b/core/src/main/res/drawable/filter_dialog_x_on.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index dc79905cd..8e8d70525 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -257,18 +257,6 @@ @string/hide_is_favorite_label - - unplayed - paused - played - queued - not_queued - downloaded - not_downloaded - has_media - is_favorite - - @string/sort_date_new_old diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 93a21ef13..e46004664 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -151,14 +151,9 @@ Select all above Select all below Unplayed - Paused - Played Queued Not queued - Downloaded - Not downloaded Has media - Is favorite Filtered {fa-exclamation-circle} Last Refresh failed Open Podcast @@ -736,13 +731,23 @@ Selected downloaded Episodes Not downloaded Selected not downloaded Episodes - Queued Selected queued Episodes - Not queued Selected not queued Episodes - Has media Selected episodes with media + Is favorite + Not favorite + Downloaded + Not downloaded + Queued + Not queued + Has media + No media + Paused + Not paused + Played + Not played + Title (A \u2192 Z) Title (Z \u2192 A)