summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2020-06-21 12:49:02 +0200
committerByteHamster <info@bytehamster.com>2020-06-21 13:17:36 +0200
commit7de9e0d4c1807bff054c1aef999fc600088ab521 (patch)
treec22e722c152aa5b95955391e41c681bff6cc8ca1 /app/src/main
parentf243bcd4cce1f3af9449c74fa38f6c90f2ea9d22 (diff)
downloadAntennaPod-7de9e0d4c1807bff054c1aef999fc600088ab521.zip
Using state lists for colors
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java112
-rw-r--r--app/src/main/java/de/danoeh/antennapod/view/RecursiveRadioGroup.java68
-rw-r--r--app/src/main/res/layout/filter_dialog.xml (renamed from app/src/main/res/layout/filter_dialog_layout.xml)0
-rw-r--r--app/src/main/res/layout/filter_dialog_relative_cardview.xml55
-rw-r--r--app/src/main/res/layout/filter_dialog_row.xml63
5 files changed, 157 insertions, 141 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java
index ece286eb4..2448742ca 100644
--- a/app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java
+++ b/app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java
@@ -1,22 +1,18 @@
package de.danoeh.antennapod.dialog;
import android.content.Context;
-import android.graphics.Color;
+import android.text.TextUtils;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.RadioButton;
-import android.widget.RelativeLayout;
-
import androidx.appcompat.app.AlertDialog;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.feed.FeedItemFilter;
import de.danoeh.antennapod.core.feed.FeedItemFilterGroup;
+import de.danoeh.antennapod.view.RecursiveRadioGroup;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
public abstract class FilterDialog {
@@ -35,91 +31,35 @@ public abstract class FilterDialog {
builder.setTitle(R.string.filter);
LayoutInflater inflater = LayoutInflater.from(this.context);
- LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.filter_dialog_layout, null, false);
+ LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.filter_dialog, null, false);
builder.setView(layout);
- for (FeedItemFilterGroup.FeedItemEnum item : FeedItemFilterGroup.FeedItemEnum.values()) {
-
- RelativeLayout row = (RelativeLayout) inflater.inflate(R.layout.filter_dialog_relative_cardview, null);
- RadioButton radioButton1 = row.findViewById(R.id.filter_dialog_radioButton1);
- RadioButton radioButton2 = row.findViewById(R.id.filter_dialog_radioButton2);
- RadioButton radioButton3 = row.findViewById(R.id.filter_dialog_radioButton3);
- radioButton1.setText(item.values[1].displayName);
- radioButton1.setTextColor(Color.BLACK);
- radioButton2.setText(item.values[0].displayName);
- radioButton2.setTextColor(Color.BLACK);
-
- Iterator<String> filterIterator = filterValues.iterator();
- while (filterIterator.hasNext()) {
- String nextItem = filterIterator.next();
- if (item.values[1].filterId.equals(nextItem)) {
- item.values[1].setSelected(true);
- item.values[0].setSelected(false);
- radioButton1.setBackgroundResource(R.color.accent_light);
- radioButton2.setBackgroundResource(R.color.master_switch_background_light);
- radioButton3.setBackgroundResource(R.drawable.filter_dialog_x_on);
- radioButton1.setSelected(true);
- radioButton2.setSelected(false);
- radioButton1.setTextColor(Color.WHITE);
- radioButton2.setTextColor(Color.BLACK);
- }
- if (item.values[0].filterId.equals(nextItem)) {
- item.values[0].setSelected(true);
- item.values[1].setSelected(false);
- radioButton2.setBackgroundResource(R.color.accent_light);
- radioButton1.setBackgroundResource(R.color.master_switch_background_light);
- radioButton3.setBackgroundResource(R.drawable.filter_dialog_x_on);
- radioButton2.setSelected(true);
- radioButton1.setSelected(false);
- radioButton2.setTextColor(Color.WHITE);
- radioButton1.setTextColor(Color.BLACK);
- }
- }
-
- radioButton1.setOnClickListener(arg0 -> {
- item.values[1].setSelected(true);
- item.values[0].setSelected(false);
- radioButton1.setBackgroundResource(R.color.accent_light);
- radioButton2.setBackgroundResource(R.color.master_switch_background_light);
- radioButton3.setBackgroundResource(R.drawable.filter_dialog_x_on);
- radioButton2.setSelected(false);
- radioButton2.setTextColor(Color.BLACK);
- radioButton1.setSelected(true);
- radioButton1.setTextColor(Color.WHITE);
- });
- radioButton2.setOnClickListener(arg0 -> {
- item.values[0].setSelected(true);
- item.values[1].setSelected(false);
- radioButton2.setBackgroundResource(R.color.accent_light);
- radioButton1.setBackgroundResource(R.color.master_switch_background_light);
- radioButton3.setBackgroundResource(R.drawable.filter_dialog_x_on);
- radioButton1.setSelected(false);
- radioButton1.setTextColor(Color.BLACK);
- radioButton2.setSelected(true);
- radioButton2.setTextColor(Color.WHITE);
- });
- radioButton3.setOnClickListener(arg0 -> {
- item.values[0].setSelected(false);
- item.values[1].setSelected(false);
- radioButton1.setBackgroundResource(R.color.master_switch_background_light);
- radioButton2.setBackgroundResource(R.color.master_switch_background_light);
- radioButton3.setBackgroundResource(R.drawable.filter_dialog_x_off);
- radioButton2.setTextColor(Color.BLACK);
- radioButton2.setSelected(false);
- radioButton1.setTextColor(Color.BLACK);
- radioButton1.setSelected(false);
- });
+ for (FeedItemFilterGroup item : FeedItemFilterGroup.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);
+ filter2.setText(item.values[1].displayName);
+ filter2.setTag(item.values[1].filterId);
layout.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 (FeedItemFilterGroup.FeedItemEnum item : FeedItemFilterGroup.FeedItemEnum.values()) {
- for (int i = 0; i < item.values.length; i++) {
- if (item.values[i].getSelected()) {
- filterValues.add(item.values[i].filterId);
- }
+ for (int i = 0; i < layout.getChildCount(); i++) {
+ if (!(layout.getChildAt(i) instanceof RecursiveRadioGroup)) {
+ continue;
+ }
+ RecursiveRadioGroup group = (RecursiveRadioGroup) layout.getChildAt(i);
+ if (group.getCheckedButton() != null) {
+ filterValues.add((String) group.getCheckedButton().getTag());
}
}
updateFilter(filterValues);
diff --git a/app/src/main/java/de/danoeh/antennapod/view/RecursiveRadioGroup.java b/app/src/main/java/de/danoeh/antennapod/view/RecursiveRadioGroup.java
new file mode 100644
index 000000000..162f524bf
--- /dev/null
+++ b/app/src/main/java/de/danoeh/antennapod/view/RecursiveRadioGroup.java
@@ -0,0 +1,68 @@
+package de.danoeh.antennapod.view;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.ActionMode;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.RadioButton;
+import java.util.ArrayList;
+
+/**
+ * An alternative to {@link android.widget.RadioGroup} that allows to nest children.
+ * Basend on https://stackoverflow.com/a/14309274.
+ */
+public class RecursiveRadioGroup extends LinearLayout {
+ private final ArrayList<RadioButton> radioButtons = new ArrayList<>();
+ private RadioButton checkedButton = null;
+
+ public RecursiveRadioGroup(Context context) {
+ super(context);
+ }
+
+ public RecursiveRadioGroup(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public RecursiveRadioGroup(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @Override
+ public void addView(View child, int index, ViewGroup.LayoutParams params) {
+ super.addView(child, index, params);
+ parseChild(child);
+ }
+
+ public void parseChild(final View child) {
+ if (child instanceof RadioButton) {
+ RadioButton button = (RadioButton) child;
+ radioButtons.add(button);
+ button.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ if (!isChecked) {
+ return;
+ }
+ checkedButton = (RadioButton) buttonView;
+
+ for (RadioButton view : radioButtons) {
+ if (view != buttonView) {
+ view.setChecked(false);
+ }
+ }
+ });
+ } else if (child instanceof ViewGroup) {
+ parseChildren((ViewGroup) child);
+ }
+ }
+
+ public void parseChildren(final ViewGroup child) {
+ for (int i = 0; i < child.getChildCount(); i++) {
+ parseChild(child.getChildAt(i));
+ }
+ }
+
+ public RadioButton getCheckedButton() {
+ return checkedButton;
+ }
+}
diff --git a/app/src/main/res/layout/filter_dialog_layout.xml b/app/src/main/res/layout/filter_dialog.xml
index c50e08814..c50e08814 100644
--- a/app/src/main/res/layout/filter_dialog_layout.xml
+++ b/app/src/main/res/layout/filter_dialog.xml
diff --git a/app/src/main/res/layout/filter_dialog_relative_cardview.xml b/app/src/main/res/layout/filter_dialog_relative_cardview.xml
deleted file mode 100644
index e3dc94f64..000000000
--- a/app/src/main/res/layout/filter_dialog_relative_cardview.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <androidx.cardview.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="260dp"
- android:layout_height="48dp"
- android:layout_marginBottom="10dp"
- android:clipChildren="true"
- app:cardCornerRadius="24dp"
- app:cardElevation="0dp">
-
- <RadioGroup
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal">
-
- <RadioButton
- android:id="@+id/filter_dialog_radioButton1"
- android:layout_width="130dp"
- android:layout_height="48dp"
- android:layout_weight="1"
- android:background="@color/master_switch_background_light"
- android:button="@android:color/transparent"
- android:checked="false"
- android:gravity="center" />
-
- <RadioButton
- android:id="@+id/filter_dialog_radioButton2"
- android:layout_width="130dp"
- android:layout_height="48dp"
- android:layout_weight="1"
- android:background="@color/master_switch_background_light"
- android:button="@android:color/transparent"
- android:checked="false"
- android:gravity="center" />
- </RadioGroup>
- </androidx.cardview.widget.CardView>
-
- <RadioButton
- android:id="@+id/filter_dialog_radioButton3"
- android:layout_width="50dp"
- android:layout_height="48dp"
- android:layout_marginStart="270dp"
- android:layout_marginLeft="270dp"
- android:layout_marginEnd="0dp"
- android:layout_marginRight="0dp"
- android:background="@drawable/filter_dialog_x_off"
- android:button="@android:color/transparent"
- android:checked="false" />
-
-
-</RelativeLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/filter_dialog_row.xml b/app/src/main/res/layout/filter_dialog_row.xml
new file mode 100644
index 000000000..bf90e17e0
--- /dev/null
+++ b/app/src/main/res/layout/filter_dialog_row.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<de.danoeh.antennapod.view.RecursiveRadioGroup
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="horizontal">
+
+ <androidx.cardview.widget.CardView
+ android:layout_width="0dp"
+ android:layout_height="48dp"
+ android:layout_marginBottom="10dp"
+ android:layout_weight="1"
+ android:clipChildren="true"
+ app:cardCornerRadius="24dp"
+ app:cardElevation="0dp">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="horizontal">
+
+ <RadioButton
+ android:id="@+id/filter_dialog_radioButton1"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:background="@color/filter_dialog_button_background_light"
+ android:textColor="@color/filter_dialog_button_text_light"
+ android:button="@android:color/transparent"
+ android:layout_marginRight="2dp"
+ android:layout_marginEnd="2dp"
+ android:checked="false"
+ android:foreground="?attr/selectableItemBackground"
+ android:tag=""
+ android:gravity="center" />
+
+ <RadioButton
+ android:id="@+id/filter_dialog_radioButton2"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:background="@color/filter_dialog_button_background_light"
+ android:textColor="@color/filter_dialog_button_text_light"
+ android:button="@android:color/transparent"
+ android:checked="false"
+ android:foreground="?attr/selectableItemBackground"
+ android:tag=""
+ android:gravity="center" />
+ </LinearLayout>
+ </androidx.cardview.widget.CardView>
+
+ <RadioButton
+ android:id="@+id/filter_dialog_clear"
+ android:layout_width="48dp"
+ android:layout_height="48dp"
+ android:background="@drawable/ic_filter_close_light"
+ android:button="@android:color/transparent"
+ android:foreground="?attr/selectableItemBackground"
+ android:tag=""
+ android:checked="true" />
+
+</de.danoeh.antennapod.view.RecursiveRadioGroup>