Add reset button to episodes filter (#6825)

This commit is contained in:
ueen 2023-12-31 11:32:02 +01:00 committed by GitHub
parent 8c7d567a0c
commit c81157f0e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 22 deletions

View File

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

View File

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<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"
@ -11,5 +13,30 @@
android:paddingTop="24dp"
android:paddingRight="24dp"
android:paddingBottom="8dp">
<LinearLayout
android:layout_width="match_parent"
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>