diff options
author | ueen <ueli.sarnighausen@online.de> | 2023-12-31 11:32:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-31 11:32:02 +0100 |
commit | c81157f0e6185d11f6a9e23106c87be846977c49 (patch) | |
tree | b5de05cb203402d0bfa4b516c2e3136ffe8b849f /app/src/main | |
parent | 8c7d567a0cb1e6f52ed1256aff2326da58199fe9 (diff) | |
download | AntennaPod-c81157f0e6185d11f6a9e23106c87be846977c49.zip |
Add reset button to episodes filter (#6825)
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/dialog/ItemFilterDialog.java | 38 | ||||
-rw-r--r-- | app/src/main/res/layout/filter_dialog.xml | 47 |
2 files changed, 63 insertions, 22 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 92c143992..359c513af 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/ItemFilterDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/ItemFilterDialog.java @@ -18,11 +18,13 @@ import com.google.android.material.bottomsheet.BottomSheetDialog; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import com.google.android.material.button.MaterialButtonToggleGroup; +import java.util.Collections; import java.util.HashSet; import java.util.Set; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.FeedItemFilterGroup; +import de.danoeh.antennapod.databinding.FilterDialogBinding; import de.danoeh.antennapod.databinding.FilterDialogRowBinding; import de.danoeh.antennapod.model.feed.FeedItemFilter; @@ -36,24 +38,36 @@ public abstract class ItemFilterDialog extends BottomSheetDialogFragment { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.filter_dialog, null, false); - rows = layout.findViewById(R.id.filter_rows); + FilterDialogBinding binding = FilterDialogBinding.bind(layout); + rows = binding.filterRows; FeedItemFilter filter = (FeedItemFilter) getArguments().getSerializable(ARGUMENT_FILTER); + //add filter rows for (FeedItemFilterGroup item : FeedItemFilterGroup.values()) { - FilterDialogRowBinding binding = FilterDialogRowBinding.inflate(inflater); - binding.getRoot().addOnButtonCheckedListener( + FilterDialogRowBinding rowBinding = FilterDialogRowBinding.inflate(inflater); + rowBinding.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); - binding.filterButton1.setMaxLines(3); - binding.filterButton1.setSingleLine(false); - binding.filterButton2.setMaxLines(3); - binding.filterButton2.setSingleLine(false); - rows.addView(binding.getRoot()); + rowBinding.filterButton1.setText(item.values[0].displayName); + rowBinding.filterButton1.setTag(item.values[0].filterId); + rowBinding.filterButton2.setText(item.values[1].displayName); + rowBinding.filterButton2.setTag(item.values[1].filterId); + rowBinding.filterButton1.setMaxLines(3); + rowBinding.filterButton1.setSingleLine(false); + rowBinding.filterButton2.setMaxLines(3); + rowBinding.filterButton2.setSingleLine(false); + rows.addView(rowBinding.getRoot(), rows.getChildCount() - 1); } + binding.confirmFiltermenu.setOnClickListener(view1 -> dismiss()); + binding.resetFiltermenu.setOnClickListener(view1 -> { + onFilterChanged(Collections.emptySet()); + for (int i = 0; i < rows.getChildCount(); i++) { + if (rows.getChildAt(i) instanceof MaterialButtonToggleGroup) { + ((MaterialButtonToggleGroup) rows.getChildAt(i)).clearChecked(); + } + } + }); + for (String filterId : filter.getValues()) { if (!TextUtils.isEmpty(filterId)) { Button button = layout.findViewWithTag(filterId); diff --git a/app/src/main/res/layout/filter_dialog.xml b/app/src/main/res/layout/filter_dialog.xml index d700f0365..e22ea4ffe 100644 --- a/app/src/main/res/layout/filter_dialog.xml +++ b/app/src/main/res/layout/filter_dialog.xml @@ -1,15 +1,42 @@ <?xml version="1.0" encoding="utf-8"?> -<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent"> +<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: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 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"> + android:layout_height="match_parent" + android:orientation="horizontal"> + + <com.google.android.material.button.MaterialButton + android:id="@+id/resetFiltermenu" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:text="@string/reset" + style="@style/Widget.MaterialComponents.Button.TextButton" /> + + <com.google.android.material.button.MaterialButton + android:id="@+id/confirmFiltermenu" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:text="@string/confirm_label" + style="@style/Widget.MaterialComponents.Button.TextButton" /> + + </LinearLayout> + </LinearLayout> + </ScrollView> |