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.bottomsheet.BottomSheetDialogFragment;
import com.google.android.material.button.MaterialButtonToggleGroup; import com.google.android.material.button.MaterialButtonToggleGroup;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.feed.FeedItemFilterGroup; import de.danoeh.antennapod.core.feed.FeedItemFilterGroup;
import de.danoeh.antennapod.databinding.FilterDialogBinding;
import de.danoeh.antennapod.databinding.FilterDialogRowBinding; import de.danoeh.antennapod.databinding.FilterDialogRowBinding;
import de.danoeh.antennapod.model.feed.FeedItemFilter; 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, public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.filter_dialog, null, false); 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); FeedItemFilter filter = (FeedItemFilter) getArguments().getSerializable(ARGUMENT_FILTER);
//add filter rows
for (FeedItemFilterGroup item : FeedItemFilterGroup.values()) { for (FeedItemFilterGroup item : FeedItemFilterGroup.values()) {
FilterDialogRowBinding binding = FilterDialogRowBinding.inflate(inflater); FilterDialogRowBinding rowBinding = FilterDialogRowBinding.inflate(inflater);
binding.getRoot().addOnButtonCheckedListener( rowBinding.getRoot().addOnButtonCheckedListener(
(group, checkedId, isChecked) -> onFilterChanged(getNewFilterValues())); (group, checkedId, isChecked) -> onFilterChanged(getNewFilterValues()));
binding.filterButton1.setText(item.values[0].displayName); rowBinding.filterButton1.setText(item.values[0].displayName);
binding.filterButton1.setTag(item.values[0].filterId); rowBinding.filterButton1.setTag(item.values[0].filterId);
binding.filterButton2.setText(item.values[1].displayName); rowBinding.filterButton2.setText(item.values[1].displayName);
binding.filterButton2.setTag(item.values[1].filterId); rowBinding.filterButton2.setTag(item.values[1].filterId);
binding.filterButton1.setMaxLines(3); rowBinding.filterButton1.setMaxLines(3);
binding.filterButton1.setSingleLine(false); rowBinding.filterButton1.setSingleLine(false);
binding.filterButton2.setMaxLines(3); rowBinding.filterButton2.setMaxLines(3);
binding.filterButton2.setSingleLine(false); rowBinding.filterButton2.setSingleLine(false);
rows.addView(binding.getRoot()); 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()) { for (String filterId : filter.getValues()) {
if (!TextUtils.isEmpty(filterId)) { if (!TextUtils.isEmpty(filterId)) {
Button button = layout.findViewWithTag(filterId); Button button = layout.findViewWithTag(filterId);

View File

@ -1,15 +1,42 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView
android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"> android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout <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_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="horizontal">
android:paddingLeft="24dp"
android:paddingTop="24dp" <com.google.android.material.button.MaterialButton
android:paddingRight="24dp" android:id="@+id/resetFiltermenu"
android:paddingBottom="8dp"> 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> </LinearLayout>
</ScrollView> </ScrollView>