blob: a38ca6b71b4e9ca745ac1533331f4c8dfbb2cdf3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
package de.danoeh.antennapod.dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import androidx.appcompat.app.AlertDialog;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.model.feed.FeedItemFilter;
import de.danoeh.antennapod.core.feed.FeedItemFilterGroup;
import de.danoeh.antennapod.ui.common.RecursiveRadioGroup;
public abstract class FilterDialog {
protected FeedItemFilter filter;
protected Context context;
public FilterDialog(Context context, FeedItemFilter feedItemFilter) {
this.context = context;
this.filter = feedItemFilter;
}
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) 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.create().show();
}
protected abstract void updateFilter(Set<String> filterValues);
}
|