diff options
author | ByteHamster <info@bytehamster.com> | 2022-08-07 21:36:15 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2022-09-18 19:12:41 +0200 |
commit | 37b49b1e386be9449f8c093ab0b23c83d4b57ac1 (patch) | |
tree | b69f969940220b925a7f0ac46eb5dba25bf6a444 /app | |
parent | 2740816bb85041d4d67fe242bcf0dddb5ad06116 (diff) | |
download | AntennaPod-37b49b1e386be9449f8c093ab0b23c83d4b57ac1.zip |
Use segmented buttons for filter
Diffstat (limited to 'app')
3 files changed, 59 insertions, 95 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/ItemFilterDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/ItemFilterDialog.java index ae938a6ec..0118eb74e 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/ItemFilterDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/ItemFilterDialog.java @@ -5,15 +5,16 @@ import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.LinearLayout; -import android.widget.RadioButton; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; +import com.google.android.material.button.MaterialButtonToggleGroup; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.FeedItemFilterGroup; +import de.danoeh.antennapod.databinding.FilterDialogRowBinding; import de.danoeh.antennapod.model.feed.FeedItemFilter; -import de.danoeh.antennapod.ui.common.RecursiveRadioGroup; import java.util.HashSet; import java.util.Set; @@ -32,22 +33,21 @@ public abstract class ItemFilterDialog extends BottomSheetDialogFragment { FeedItemFilter filter = (FeedItemFilter) getArguments().getSerializable(ARGUMENT_FILTER); for (FeedItemFilterGroup item : FeedItemFilterGroup.values()) { - RecursiveRadioGroup row = (RecursiveRadioGroup) inflater.inflate(R.layout.filter_dialog_row, null, false); - row.setOnCheckedChangeListener((group, checkedId) -> onFilterChanged(getNewFilterValues())); - 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); - rows.addView(row); + FilterDialogRowBinding binding = FilterDialogRowBinding.inflate(inflater); + binding.getRoot().addOnButtonCheckedListener( + (group, checkedId, isChecked) -> onFilterChanged(getNewFilterValues())); + binding.filterButton1.setText(item.values[0].displayName); + binding.filterButton1.setTag(item.values[0].filterId); + binding.filterButton2.setText(item.values[1].displayName); + binding.filterButton2.setTag(item.values[1].filterId); + rows.addView(binding.getRoot()); } for (String filterId : filter.getValues()) { if (!TextUtils.isEmpty(filterId)) { - RadioButton button = layout.findViewWithTag(filterId); + Button button = layout.findViewWithTag(filterId); if (button != null) { - button.setChecked(true); + ((MaterialButtonToggleGroup) button.getParent()).check(button.getId()); } } } @@ -57,16 +57,18 @@ public abstract class ItemFilterDialog extends BottomSheetDialogFragment { protected Set<String> getNewFilterValues() { final Set<String> newFilterValues = new HashSet<>(); for (int i = 0; i < rows.getChildCount(); i++) { - if (!(rows.getChildAt(i) instanceof RecursiveRadioGroup)) { + if (!(rows.getChildAt(i) instanceof MaterialButtonToggleGroup)) { continue; } - RecursiveRadioGroup group = (RecursiveRadioGroup) rows.getChildAt(i); - if (group.getCheckedButton() != null) { - String tag = (String) group.getCheckedButton().getTag(); - if (tag != null) { // Clear buttons use no tag - newFilterValues.add((String) group.getCheckedButton().getTag()); - } + MaterialButtonToggleGroup group = (MaterialButtonToggleGroup) rows.getChildAt(i); + if (group.getCheckedButtonId() == View.NO_ID) { + continue; + } + String tag = (String) group.findViewById(group.getCheckedButtonId()).getTag(); + if (tag == null) { // Clear buttons use no tag + continue; } + newFilterValues.add(tag); } return newFilterValues; } 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 dd51a4b31..f9d17f37b 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/SubscriptionsFilterDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SubscriptionsFilterDialog.java @@ -4,11 +4,13 @@ import android.content.Context; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; +import android.widget.Button; import android.widget.LinearLayout; -import android.widget.RadioButton; +import com.google.android.material.button.MaterialButtonToggleGroup; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import de.danoeh.antennapod.databinding.FilterDialogRowBinding; import org.greenrobot.eventbus.EventBus; import java.util.Arrays; @@ -20,7 +22,6 @@ import de.danoeh.antennapod.event.UnreadItemsUpdateEvent; import de.danoeh.antennapod.model.feed.SubscriptionsFilter; import de.danoeh.antennapod.core.feed.SubscriptionsFilterGroup; import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.ui.common.RecursiveRadioGroup; public class SubscriptionsFilterDialog { public static void showDialog(Context context) { @@ -35,39 +36,42 @@ public class SubscriptionsFilterDialog { builder.setView(layout); for (SubscriptionsFilterGroup item : SubscriptionsFilterGroup.values()) { - RecursiveRadioGroup row = (RecursiveRadioGroup) inflater.inflate(R.layout.filter_dialog_row, null); - 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); + FilterDialogRowBinding binding = FilterDialogRowBinding.inflate(inflater); + binding.filterButton1.setText(item.values[0].displayName); + binding.filterButton1.setTag(item.values[0].filterId); if (item.values.length == 2) { - filter2.setText(item.values[1].displayName); - filter2.setTag(item.values[1].filterId); + binding.filterButton2.setText(item.values[1].displayName); + binding.filterButton2.setTag(item.values[1].filterId); } else { - filter2.setVisibility(View.GONE); + binding.filterButton2.setVisibility(View.GONE); } - rows.addView(row); + rows.addView(binding.getRoot()); } for (String filterId : filterValues) { if (!TextUtils.isEmpty(filterId)) { - ((RadioButton) layout.findViewWithTag(filterId)).setChecked(true); + Button button = layout.findViewWithTag(filterId); + if (button != null) { + ((MaterialButtonToggleGroup) button.getParent()).check(button.getId()); + } } } builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> { filterValues.clear(); for (int i = 0; i < rows.getChildCount(); i++) { - if (!(rows.getChildAt(i) instanceof RecursiveRadioGroup)) { + if (!(rows.getChildAt(i) instanceof MaterialButtonToggleGroup)) { + continue; + } + MaterialButtonToggleGroup group = (MaterialButtonToggleGroup) rows.getChildAt(i); + if (group.getCheckedButtonId() == View.NO_ID) { continue; } - RecursiveRadioGroup group = (RecursiveRadioGroup) rows.getChildAt(i); - if (group.getCheckedButton() != null) { - String tag = (String) group.getCheckedButton().getTag(); - if (tag != null) { // Clear buttons use no tag - filterValues.add((String) group.getCheckedButton().getTag()); - } + String tag = (String) group.findViewById(group.getCheckedButtonId()).getTag(); + if (tag == null) { // Clear buttons use no tag + continue; } + filterValues.add(tag); } updateFilter(filterValues); }); diff --git a/app/src/main/res/layout/filter_dialog_row.xml b/app/src/main/res/layout/filter_dialog_row.xml index 7ecfc8223..a551b5db9 100644 --- a/app/src/main/res/layout/filter_dialog_row.xml +++ b/app/src/main/res/layout/filter_dialog_row.xml @@ -1,66 +1,24 @@ <?xml version="1.0" encoding="utf-8"?> -<de.danoeh.antennapod.ui.common.RecursiveRadioGroup +<com.google.android.material.button.MaterialButtonToggleGroup xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" - android:layout_height="match_parent" - android:paddingBottom="8dp" - android:orientation="horizontal"> + android:layout_height="wrap_content" + android:weightSum="2" + app:singleSelection="true"> - <androidx.cardview.widget.CardView + <Button + android:id="@+id/filterButton1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" - android:clipChildren="true" - android:layout_gravity="center_vertical" - app:cardCornerRadius="32dp" - app:cardElevation="0dp"> + style="?attr/materialButtonOutlinedStyle" /> - <LinearLayout - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="horizontal"> - - <RadioButton - android:id="@+id/filter_dialog_radioButton1" - android:layout_width="0dp" - android:layout_height="match_parent" - android:layout_marginEnd="2dp" - android:layout_marginRight="2dp" - android:layout_weight="1" - android:background="?attr/filter_dialog_button_background" - android:minHeight="40dp" - android:foreground="?android:attr/selectableItemBackground" - android:checked="false" - android:gravity="center" - android:textColor="@color/filter_dialog_button_text" - style="@style/NoButtonRadio" /> - - <RadioButton - android:id="@+id/filter_dialog_radioButton2" - android:layout_width="0dp" - android:layout_height="match_parent" - android:minHeight="40dp" - android:layout_weight="1" - android:background="?attr/filter_dialog_button_background" - android:foreground="?android:attr/selectableItemBackground" - android:checked="false" - android:gravity="center" - android:textColor="@color/filter_dialog_button_text" - style="@style/NoButtonRadio" /> - - </LinearLayout> - - </androidx.cardview.widget.CardView> - - <RadioButton - android:id="@+id/filter_dialog_clear" - android:layout_width="40dp" - android:layout_height="40dp" - android:background="@drawable/ic_filter_close" - android:foreground="?android:attr/selectableItemBackground" - android:layout_gravity="center_vertical" - android:checked="true" - style="@style/NoButtonRadio" /> + <Button + android:id="@+id/filterButton2" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + style="?attr/materialButtonOutlinedStyle" /> -</de.danoeh.antennapod.ui.common.RecursiveRadioGroup> +</com.google.android.material.button.MaterialButtonToggleGroup> |