Search in sources :

Example 1 with FeedItemFilterGroup

use of de.danoeh.antennapod.core.feed.FeedItemFilterGroup in project AntennaPod by AntennaPod.

the class FilterDialog method openDialog.

public void openDialog() {
    final Set<String> filterValues = new HashSet<>(Arrays.asList(filter.getValues()));
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.filter);
    LayoutInflater inflater = LayoutInflater.from(this.context);
    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, 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);
        rows.addView(row);
    }
    for (String filterId : filterValues) {
        if (!TextUtils.isEmpty(filterId)) {
            RadioButton button = layout.findViewWithTag(filterId);
            if (button != null) {
                button.setChecked(true);
            }
        }
    }
    builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
        filterValues.clear();
        for (int i = 0; i < rows.getChildCount(); i++) {
            if (!(rows.getChildAt(i) instanceof RecursiveRadioGroup)) {
                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());
                }
            }
        }
        updateFilter(filterValues);
    });
    builder.setNegativeButton(R.string.cancel_label, null);
    builder.create().show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) FeedItemFilterGroup(de.danoeh.antennapod.core.feed.FeedItemFilterGroup) RadioButton(android.widget.RadioButton) View(android.view.View) LayoutInflater(android.view.LayoutInflater) RecursiveRadioGroup(de.danoeh.antennapod.ui.common.RecursiveRadioGroup) LinearLayout(android.widget.LinearLayout) HashSet(java.util.HashSet)

Aggregations

LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 LinearLayout (android.widget.LinearLayout)1 RadioButton (android.widget.RadioButton)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 FeedItemFilterGroup (de.danoeh.antennapod.core.feed.FeedItemFilterGroup)1 RecursiveRadioGroup (de.danoeh.antennapod.ui.common.RecursiveRadioGroup)1 HashSet (java.util.HashSet)1