Redesign filter dialog
This commit is contained in:
parent
65ec9e5f45
commit
f243bcd4cc
|
@ -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()));
|
||||
|
||||
// make sure we have no empty strings in the filter list
|
||||
for (String filterValue : filterValues) {
|
||||
if (TextUtils.isEmpty(filterValue)) {
|
||||
filterValues.remove(filterValue);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
String value = values[i];
|
||||
if (filterValues.contains(value)) {
|
||||
checkedItems[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
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()) {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
|
@ -0,0 +1,84 @@
|
|||
package de.danoeh.antennapod.core.feed;
|
||||
|
||||
import de.danoeh.antennapod.core.R;
|
||||
|
||||
public class FeedItemFilterGroup {
|
||||
|
||||
private static boolean DEFAULT_SELECTED_STATE = false;
|
||||
|
||||
private static final String NO_FILTERID = "";
|
||||
private static final int HASMEDIA_LABEL = R.string.has_media;
|
||||
private static final int NOTPAUSED_LABEL = R.string.not_paused;
|
||||
private static final int NOTFAVORITE_LABEL = R.string.not_favorite;
|
||||
|
||||
private static final int UNPLAYED_LABEL = R.string.not_played;
|
||||
private static final String UNPLAYED_FILTERID = "unplayed";
|
||||
|
||||
private static final int PLAYED_LABEL = R.string.hide_played_episodes_label;
|
||||
private static final String PLAYED_FILTERID = "played";
|
||||
|
||||
private static final int PAUSED_LABEL = R.string.hide_paused_episodes_label;
|
||||
private static final String PAUSED_FILTERID = "paused";
|
||||
|
||||
private static final int ISFAVORITE_LABEL = R.string.hide_is_favorite_label;
|
||||
private static final String ISFAVORITE_FILTERID = "is_favorite";
|
||||
|
||||
private static final int NOMEDIA_LABEL = R.string.no_media;
|
||||
private static final String NOMEDIA_FILTERID = "no_media";
|
||||
|
||||
private static final int QUEUED_LABEL = R.string.queue_label;
|
||||
private static final String QUEUED_FILTERID = "queued";
|
||||
|
||||
private static final int NOTQUEUED_LABEL = R.string.not_queued_label;
|
||||
private static final String NOTQUEUED_FILTERID = "not_queued";
|
||||
|
||||
private static final int NOTDOWNLOADED_LABEL = R.string.hide_downloaded_episodes_label;
|
||||
private static final String NOTDOWNLOADED_FILTERID = "not_downloaded";
|
||||
|
||||
private static final int DOWNLOADED_LABEL = R.string.hide_downloaded_episodes_label;
|
||||
private static final String DOWNLOADED_FILTERID = "downloaded";
|
||||
|
||||
public enum FeedItemEnum {
|
||||
|
||||
PLAYED(new ItemProperties(DEFAULT_SELECTED_STATE, UNPLAYED_LABEL, UNPLAYED_FILTERID),
|
||||
new ItemProperties(DEFAULT_SELECTED_STATE, PLAYED_LABEL, PLAYED_FILTERID)),
|
||||
PAUSED(new ItemProperties(DEFAULT_SELECTED_STATE, NOTPAUSED_LABEL, NO_FILTERID),
|
||||
new ItemProperties(DEFAULT_SELECTED_STATE, PAUSED_LABEL, PAUSED_FILTERID)),
|
||||
FAVORITE(new ItemProperties(DEFAULT_SELECTED_STATE, NOTFAVORITE_LABEL, NO_FILTERID),
|
||||
new ItemProperties(DEFAULT_SELECTED_STATE, ISFAVORITE_LABEL, ISFAVORITE_FILTERID)),
|
||||
MEDIA(new ItemProperties(DEFAULT_SELECTED_STATE, NOMEDIA_LABEL, NOMEDIA_FILTERID),
|
||||
new ItemProperties(DEFAULT_SELECTED_STATE, HASMEDIA_LABEL, NO_FILTERID)),
|
||||
QUEUED(new ItemProperties(DEFAULT_SELECTED_STATE, NOTQUEUED_LABEL, NOTQUEUED_FILTERID),
|
||||
new ItemProperties(DEFAULT_SELECTED_STATE, QUEUED_LABEL, QUEUED_FILTERID)),
|
||||
DOWNLOADED(new ItemProperties(DEFAULT_SELECTED_STATE, NOTDOWNLOADED_LABEL, NOTDOWNLOADED_FILTERID),
|
||||
new ItemProperties(DEFAULT_SELECTED_STATE, DOWNLOADED_LABEL, DOWNLOADED_FILTERID));
|
||||
|
||||
public final ItemProperties[] values;
|
||||
|
||||
FeedItemEnum(ItemProperties... values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public static class ItemProperties {
|
||||
|
||||
public final int displayName;
|
||||
public boolean selected;
|
||||
public final String filterId;
|
||||
|
||||
public void setSelected(boolean value) {
|
||||
this.selected = value;
|
||||
}
|
||||
|
||||
public boolean getSelected() {
|
||||
return this.selected;
|
||||
}
|
||||
|
||||
public ItemProperties(boolean selected, int displayName, String filterId) {
|
||||
this.selected = selected;
|
||||
this.displayName = displayName;
|
||||
this.filterId = filterId;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,56 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:bottom="5dp"
|
||||
android:left="5dp"
|
||||
android:right="5dp"
|
||||
android:top="5dp">
|
||||
|
||||
<shape android:shape="oval">
|
||||
<stroke
|
||||
android:width="4dp"
|
||||
android:color="@color/master_switch_background_light" />
|
||||
</shape>
|
||||
|
||||
</item>
|
||||
|
||||
<!-- x -->
|
||||
<item
|
||||
android:bottom="12dp"
|
||||
android:left="12dp"
|
||||
android:right="12dp"
|
||||
android:top="12dp">
|
||||
<rotate
|
||||
android:fromDegrees="135"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
android:toDegrees="135">
|
||||
<shape android:shape="line">
|
||||
<stroke
|
||||
android:width="4dp"
|
||||
android:color="@color/master_switch_background_light" />
|
||||
</shape>
|
||||
</rotate>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:bottom="12dp"
|
||||
android:left="12dp"
|
||||
android:right="12dp"
|
||||
android:top="12dp">
|
||||
<rotate
|
||||
android:fromDegrees="45"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
android:toDegrees="45">
|
||||
<shape android:shape="line">
|
||||
<stroke
|
||||
android:width="4dp"
|
||||
android:color="@color/master_switch_background_light" />
|
||||
</shape>
|
||||
|
||||
</rotate>
|
||||
</item>
|
||||
|
||||
</layer-list>
|
|
@ -0,0 +1,56 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:bottom="5dp"
|
||||
android:left="5dp"
|
||||
android:right="5dp"
|
||||
android:top="5dp">
|
||||
|
||||
<shape android:shape="oval">
|
||||
<stroke
|
||||
android:width="4dp"
|
||||
android:color="@color/grey" />
|
||||
</shape>
|
||||
|
||||
</item>
|
||||
|
||||
<!-- x -->
|
||||
<item
|
||||
android:bottom="12dp"
|
||||
android:left="12dp"
|
||||
android:right="12dp"
|
||||
android:top="12dp">
|
||||
<rotate
|
||||
android:fromDegrees="135"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
android:toDegrees="135">
|
||||
<shape android:shape="line">
|
||||
<stroke
|
||||
android:width="4dp"
|
||||
android:color="@color/grey" />
|
||||
</shape>
|
||||
</rotate>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:bottom="12dp"
|
||||
android:left="12dp"
|
||||
android:right="12dp"
|
||||
android:top="12dp">
|
||||
<rotate
|
||||
android:fromDegrees="45"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
android:toDegrees="45">
|
||||
<shape android:shape="line">
|
||||
<stroke
|
||||
android:width="4dp"
|
||||
android:color="@color/grey" />
|
||||
</shape>
|
||||
|
||||
</rotate>
|
||||
</item>
|
||||
|
||||
</layer-list>
|
|
@ -257,18 +257,6 @@
|
|||
<item>@string/hide_is_favorite_label</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="episode_filter_values">
|
||||
<item>unplayed</item>
|
||||
<item>paused</item>
|
||||
<item>played</item>
|
||||
<item>queued</item>
|
||||
<item>not_queued</item>
|
||||
<item>downloaded</item>
|
||||
<item>not_downloaded</item>
|
||||
<item>has_media</item>
|
||||
<item>is_favorite</item>
|
||||
</string-array>
|
||||
|
||||
<!-- sort for podcast screen, not for queue -->
|
||||
<string-array name="feed_episodes_sort_options">
|
||||
<item>@string/sort_date_new_old</item>
|
||||
|
|
|
@ -151,14 +151,9 @@
|
|||
<string name="select_all_above">Select all above</string>
|
||||
<string name="select_all_below">Select all below</string>
|
||||
<string name="hide_unplayed_episodes_label">Unplayed</string>
|
||||
<string name="hide_paused_episodes_label">Paused</string>
|
||||
<string name="hide_played_episodes_label">Played</string>
|
||||
<string name="hide_queued_episodes_label">Queued</string>
|
||||
<string name="hide_not_queued_episodes_label">Not queued</string>
|
||||
<string name="hide_downloaded_episodes_label">Downloaded</string>
|
||||
<string name="hide_not_downloaded_episodes_label">Not downloaded</string>
|
||||
<string name="hide_has_media_label">Has media</string>
|
||||
<string name="hide_is_favorite_label">Is favorite</string>
|
||||
<string name="filtered_label">Filtered</string>
|
||||
<string name="refresh_failed_msg">{fa-exclamation-circle} Last Refresh failed</string>
|
||||
<string name="open_podcast">Open Podcast</string>
|
||||
|
@ -736,13 +731,23 @@
|
|||
<string name="selected_downloaded_label">Selected downloaded Episodes</string>
|
||||
<string name="not_downloaded_label">Not downloaded</string>
|
||||
<string name="selected_not_downloaded_label">Selected not downloaded Episodes</string>
|
||||
<string name="queued_label">Queued</string>
|
||||
<string name="selected_queued_label">Selected queued Episodes</string>
|
||||
<string name="not_queued_label">Not queued</string>
|
||||
<string name="selected_not_queued_label">Selected not queued Episodes</string>
|
||||
<string name="has_media">Has media</string>
|
||||
<string name="selected_has_media_label">Selected episodes with media</string>
|
||||
|
||||
<string name="hide_is_favorite_label">Is favorite</string>
|
||||
<string name="not_favorite">Not favorite</string>
|
||||
<string name="hide_downloaded_episodes_label">Downloaded</string>
|
||||
<string name="hide_not_downloaded_episodes_label">Not downloaded</string>
|
||||
<string name="queued_label">Queued</string>
|
||||
<string name="not_queued_label">Not queued</string>
|
||||
<string name="has_media">Has media</string>
|
||||
<string name="no_media">No media</string>
|
||||
<string name="hide_paused_episodes_label">Paused</string>
|
||||
<string name="not_paused">Not paused</string>
|
||||
<string name="hide_played_episodes_label">Played</string>
|
||||
<string name="not_played">Not played</string>
|
||||
|
||||
<!-- Sort -->
|
||||
<string name="sort_title_a_z">Title (A \u2192 Z)</string>
|
||||
<string name="sort_title_z_a">Title (Z \u2192 A)</string>
|
||||
|
|
Loading…
Reference in New Issue