Merge pull request #4733 from ByteHamster/fix-filter-dialog-api21

Fix filter dialog on old Android versions
This commit is contained in:
ByteHamster 2020-12-08 14:11:46 +01:00 committed by GitHub
commit b42e5e6eb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 96 additions and 29 deletions

View File

@ -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

View File

@ -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

View File

@ -1,11 +1,15 @@
<?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"
android:paddingLeft="24dp"
android:paddingTop="24dp"
android:paddingRight="24dp"
android:paddingBottom="8dp">
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/filter_rows"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingTop="24dp"
android:paddingRight="24dp"
android:paddingBottom="8dp">
</LinearLayout>
</ScrollView>

View File

@ -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" />

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp">
<shape android:shape="oval">
<stroke
android:width="4dp"
android:color="?attr/filter_dialog_clear" />
</shape>
</item>
<!-- x -->
<item
android:bottom="12dp"
android:left="12dp"
android:right="12dp"
android:top="12dp">
<rotate
android:fromDegrees="135"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="135">
<shape android:shape="line">
<stroke
android:width="4dp"
android:color="?attr/filter_dialog_clear" />
</shape>
</rotate>
</item>
<item
android:bottom="12dp"
android:left="12dp"
android:right="12dp"
android:top="12dp">
<rotate
android:fromDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="45">
<shape android:shape="line">
<stroke
android:width="4dp"
android:color="?attr/filter_dialog_clear" />
</shape>
</rotate>
</item>
</layer-list>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Fall-back for old Android devices that do not support attrs as colors -->
<item
android:bottom="5dp"
android:left="5dp"
@ -10,7 +10,7 @@
<shape android:shape="oval">
<stroke
android:width="4dp"
android:color="?attr/filter_dialog_clear" />
android:color="#555" />
</shape>
</item>
@ -28,7 +28,7 @@
<shape android:shape="line">
<stroke
android:width="4dp"
android:color="?attr/filter_dialog_clear" />
android:color="#555" />
</shape>
</rotate>
</item>
@ -46,7 +46,7 @@
<shape android:shape="line">
<stroke
android:width="4dp"
android:color="?attr/filter_dialog_clear" />
android:color="#555" />
</shape>
</rotate>

View File

@ -58,7 +58,7 @@
<attr name="action_icon_color" format="color"/>
<attr name="scrollbar_thumb" format="reference"/>
<attr name="background_elevated" format="color"/>
<attr name="filter_dialog_clear" format="reference"/>
<attr name="filter_dialog_clear" format="color"/>
<attr name="filter_dialog_button_background" format="reference"/>
<attr name="ic_notifications" format="reference"/>

View File

@ -318,4 +318,9 @@
<item name="android:clickable">true</item>
</style>
<style name="NoButtonRadio" parent="Widget.MaterialComponents.CompoundButton.RadioButton">
<item name="buttonCompat">@null</item> <!-- For Android 4.4 -->
<item name="android:button">@null</item>
</style>
</resources>