Search in sources :

Example 1 with RecursiveRadioGroup

use of de.danoeh.antennapod.ui.common.RecursiveRadioGroup 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)

Example 2 with RecursiveRadioGroup

use of de.danoeh.antennapod.ui.common.RecursiveRadioGroup in project AntennaPod by AntennaPod.

the class SubscriptionsFilterDialog method showDialog.

public static void showDialog(Context context) {
    SubscriptionsFilter subscriptionsFilter = UserPreferences.getSubscriptionsFilter();
    final Set<String> filterValues = new HashSet<>(Arrays.asList(subscriptionsFilter.getValues()));
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(context.getString(R.string.pref_filter_feed_title));
    LayoutInflater inflater = LayoutInflater.from(context);
    View layout = inflater.inflate(R.layout.filter_dialog, null, false);
    LinearLayout rows = layout.findViewById(R.id.filter_rows);
    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);
        if (item.values.length == 2) {
            filter2.setText(item.values[1].displayName);
            filter2.setTag(item.values[1].filterId);
        } else {
            filter2.setVisibility(View.GONE);
        }
        rows.addView(row);
    }
    for (String filterId : filterValues) {
        if (!TextUtils.isEmpty(filterId)) {
            ((RadioButton) layout.findViewWithTag(filterId)).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.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) SubscriptionsFilterGroup(de.danoeh.antennapod.core.feed.SubscriptionsFilterGroup) RadioButton(android.widget.RadioButton) View(android.view.View) LayoutInflater(android.view.LayoutInflater) RecursiveRadioGroup(de.danoeh.antennapod.ui.common.RecursiveRadioGroup) SubscriptionsFilter(de.danoeh.antennapod.core.feed.SubscriptionsFilter) LinearLayout(android.widget.LinearLayout) HashSet(java.util.HashSet)

Aggregations

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