From a510cb00fdcd2fdc4c5a62a1d12ef3d27886e1a4 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Thu, 3 Dec 2020 22:20:11 +0100 Subject: [PATCH] Fix filter dialog on old Android versions --- .../antennapod/dialog/FilterDialog.java | 14 +++-- .../dialog/SubscriptionsFilterDialog.java | 11 ++-- app/src/main/res/layout/filter_dialog.xml | 24 ++++---- app/src/main/res/layout/filter_dialog_row.xml | 6 +- .../main/res/drawable-v21/ic_filter_close.xml | 55 +++++++++++++++++++ .../src/main/res/drawable/ic_filter_close.xml | 8 +-- core/src/main/res/values/attrs.xml | 2 +- core/src/main/res/values/styles.xml | 5 ++ 8 files changed, 96 insertions(+), 29 deletions(-) create mode 100644 core/src/main/res/drawable-v21/ic_filter_close.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 82010637f..80df87891 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.dialog; import android.content.Context; import android.text.TextUtils; import android.view.LayoutInflater; +import android.view.View; import android.widget.LinearLayout; import android.widget.RadioButton; @@ -34,18 +35,19 @@ public abstract class FilterDialog { builder.setTitle(R.string.filter); LayoutInflater inflater = LayoutInflater.from(this.context); - LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.filter_dialog, null, false); + View layout = inflater.inflate(R.layout.filter_dialog, null, false); + LinearLayout rows = layout.findViewById(R.id.filter_rows); builder.setView(layout); for (FeedItemFilterGroup item : FeedItemFilterGroup.values()) { - RecursiveRadioGroup row = (RecursiveRadioGroup) inflater.inflate(R.layout.filter_dialog_row, null); + RecursiveRadioGroup row = (RecursiveRadioGroup) inflater.inflate(R.layout.filter_dialog_row, null, false); RadioButton filter1 = row.findViewById(R.id.filter_dialog_radioButton1); RadioButton filter2 = row.findViewById(R.id.filter_dialog_radioButton2); filter1.setText(item.values[0].displayName); filter1.setTag(item.values[0].filterId); filter2.setText(item.values[1].displayName); filter2.setTag(item.values[1].filterId); - layout.addView(row); + rows.addView(row); } for (String filterId : filterValues) { @@ -56,11 +58,11 @@ public abstract class FilterDialog { builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> { filterValues.clear(); - for (int i = 0; i < layout.getChildCount(); i++) { - if (!(layout.getChildAt(i) instanceof RecursiveRadioGroup)) { + for (int i = 0; i < rows.getChildCount(); i++) { + if (!(rows.getChildAt(i) instanceof RecursiveRadioGroup)) { continue; } - RecursiveRadioGroup group = (RecursiveRadioGroup) layout.getChildAt(i); + RecursiveRadioGroup group = (RecursiveRadioGroup) rows.getChildAt(i); if (group.getCheckedButton() != null) { String tag = (String) group.getCheckedButton().getTag(); if (tag != null) { // Clear buttons use no tag diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/SubscriptionsFilterDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SubscriptionsFilterDialog.java index a8915480c..8a87fef25 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/SubscriptionsFilterDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SubscriptionsFilterDialog.java @@ -30,7 +30,8 @@ public class SubscriptionsFilterDialog { builder.setTitle(context.getString(R.string.pref_filter_feed_title)); LayoutInflater inflater = LayoutInflater.from(context); - LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.filter_dialog, null, false); + View layout = inflater.inflate(R.layout.filter_dialog, null, false); + LinearLayout rows = layout.findViewById(R.id.filter_rows); builder.setView(layout); for (SubscriptionsFilterGroup item : SubscriptionsFilterGroup.values()) { @@ -45,7 +46,7 @@ public class SubscriptionsFilterDialog { } else { filter2.setVisibility(View.GONE); } - layout.addView(row); + rows.addView(row); } for (String filterId : filterValues) { @@ -56,11 +57,11 @@ public class SubscriptionsFilterDialog { builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> { filterValues.clear(); - for (int i = 0; i < layout.getChildCount(); i++) { - if (!(layout.getChildAt(i) instanceof RecursiveRadioGroup)) { + for (int i = 0; i < rows.getChildCount(); i++) { + if (!(rows.getChildAt(i) instanceof RecursiveRadioGroup)) { continue; } - RecursiveRadioGroup group = (RecursiveRadioGroup) layout.getChildAt(i); + RecursiveRadioGroup group = (RecursiveRadioGroup) rows.getChildAt(i); if (group.getCheckedButton() != null) { String tag = (String) group.getCheckedButton().getTag(); if (tag != null) { // Clear buttons use no tag diff --git a/app/src/main/res/layout/filter_dialog.xml b/app/src/main/res/layout/filter_dialog.xml index 39e9258d9..d700f0365 100644 --- a/app/src/main/res/layout/filter_dialog.xml +++ b/app/src/main/res/layout/filter_dialog.xml @@ -1,11 +1,15 @@ - - - \ No newline at end of file + + + + diff --git a/app/src/main/res/layout/filter_dialog_row.xml b/app/src/main/res/layout/filter_dialog_row.xml index 0863997b3..5011812d9 100644 --- a/app/src/main/res/layout/filter_dialog_row.xml +++ b/app/src/main/res/layout/filter_dialog_row.xml @@ -28,7 +28,7 @@ android:layout_marginRight="2dp" android:layout_weight="1" android:background="?attr/filter_dialog_button_background" - android:button="@android:color/transparent" + style="@style/NoButtonRadio" android:foreground="?android:attr/selectableItemBackground" android:checked="false" android:gravity="center" @@ -40,7 +40,7 @@ android:layout_height="match_parent" android:layout_weight="1" android:background="?attr/filter_dialog_button_background" - android:button="@android:color/transparent" + style="@style/NoButtonRadio" android:foreground="?android:attr/selectableItemBackground" android:checked="false" android:gravity="center" @@ -53,7 +53,7 @@ android:layout_width="48dp" android:layout_height="48dp" android:background="@drawable/ic_filter_close" - android:button="@android:color/transparent" + style="@style/NoButtonRadio" android:foreground="?android:attr/selectableItemBackground" android:layout_gravity="center_vertical" android:checked="true" /> diff --git a/core/src/main/res/drawable-v21/ic_filter_close.xml b/core/src/main/res/drawable-v21/ic_filter_close.xml new file mode 100644 index 000000000..9e0a26905 --- /dev/null +++ b/core/src/main/res/drawable-v21/ic_filter_close.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/main/res/drawable/ic_filter_close.xml b/core/src/main/res/drawable/ic_filter_close.xml index 9e0a26905..4d7eedb30 100644 --- a/core/src/main/res/drawable/ic_filter_close.xml +++ b/core/src/main/res/drawable/ic_filter_close.xml @@ -1,6 +1,6 @@ - + + android:color="#555" /> @@ -28,7 +28,7 @@ + android:color="#555" /> @@ -46,7 +46,7 @@ + android:color="#555" /> diff --git a/core/src/main/res/values/attrs.xml b/core/src/main/res/values/attrs.xml index a78f837bf..3a5ec310b 100644 --- a/core/src/main/res/values/attrs.xml +++ b/core/src/main/res/values/attrs.xml @@ -58,7 +58,7 @@ - + diff --git a/core/src/main/res/values/styles.xml b/core/src/main/res/values/styles.xml index 9ec82215a..b5c10ae0e 100644 --- a/core/src/main/res/values/styles.xml +++ b/core/src/main/res/values/styles.xml @@ -318,4 +318,9 @@ true + +