diff options
author | bws9000 <armorsoft@gmail.com> | 2020-06-21 12:52:15 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-06-21 12:59:05 +0200 |
commit | f243bcd4cce1f3af9449c74fa38f6c90f2ea9d22 (patch) | |
tree | 66917ea84f00e0e327cbe3371f06cad5931c201a /app | |
parent | 65ec9e5f458e1d3c9003f79c21abb217a81d1910 (diff) | |
download | AntennaPod-f243bcd4cce1f3af9449c74fa38f6c90f2ea9d22.zip |
Redesign filter dialog
Diffstat (limited to 'app')
3 files changed, 160 insertions, 23 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 d2912f90f..ece286eb4 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/FilterDialog.java @@ -1,15 +1,22 @@ package de.danoeh.antennapod.dialog; import android.content.Context; +import android.graphics.Color; +import android.view.LayoutInflater; +import android.widget.LinearLayout; +import android.widget.RadioButton; +import android.widget.RelativeLayout; + import androidx.appcompat.app.AlertDialog; -import android.text.TextUtils; 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; public abstract class FilterDialog { @@ -22,38 +29,102 @@ public abstract class FilterDialog { } public void openDialog() { - final String[] items = context.getResources().getStringArray(R.array.episode_filter_options); - final String[] values = context.getResources().getStringArray(R.array.episode_filter_values); - final boolean[] checkedItems = new boolean[items.length]; final Set<String> filterValues = new HashSet<>(Arrays.asList(filter.getValues())); + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.filter); - // make sure we have no empty strings in the filter list - for (String filterValue : filterValues) { - if (TextUtils.isEmpty(filterValue)) { - filterValues.remove(filterValue); - } - } + LayoutInflater inflater = LayoutInflater.from(this.context); + LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.filter_dialog_layout, null, false); + builder.setView(layout); + + for (FeedItemFilterGroup.FeedItemEnum item : FeedItemFilterGroup.FeedItemEnum.values()) { - for (int i = 0; i < values.length; i++) { - String value = values[i]; - if (filterValues.contains(value)) { - checkedItems[i] = true; + 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); + }); + layout.addView(row); } - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(R.string.filter); - builder.setMultiChoiceItems(items, checkedItems, (dialog, which, isChecked) -> { - if (isChecked) { - filterValues.add(values[which]); - } else { - filterValues.remove(values[which]); - } - }); + 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); + } + } + } updateFilter(filterValues); }); + builder.setNegativeButton(R.string.cancel_label, null); builder.create().show(); } diff --git a/app/src/main/res/layout/filter_dialog_layout.xml b/app/src/main/res/layout/filter_dialog_layout.xml new file mode 100644 index 000000000..c50e08814 --- /dev/null +++ b/app/src/main/res/layout/filter_dialog_layout.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:paddingLeft="20dp" + android:paddingTop="25dp" + android:paddingRight="20dp" + android:paddingBottom="0dp"> + +</LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/filter_dialog_relative_cardview.xml b/app/src/main/res/layout/filter_dialog_relative_cardview.xml new file mode 100644 index 000000000..e3dc94f64 --- /dev/null +++ b/app/src/main/res/layout/filter_dialog_relative_cardview.xml @@ -0,0 +1,55 @@ +<?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 |