Redesign filter dialog

This commit is contained in:
bws9000 2020-07-02 20:34:11 -04:00
parent ecf4b60fce
commit f4677c0d9a
11 changed files with 145 additions and 96 deletions

View File

@ -5,14 +5,17 @@ import android.text.TextUtils;
import android.view.LayoutInflater;
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.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 {
@ -47,7 +50,9 @@ public abstract class FilterDialog {
for (String filterId : filterValues) {
if (!TextUtils.isEmpty(filterId)) {
((RadioButton) layout.findViewWithTag(filterId)).setChecked(true);
if (layout.findViewWithTag(filterId) != null) {
((RadioButton) layout.findViewWithTag(filterId)).setChecked(true);
}
}
}

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<de.danoeh.antennapod.view.RecursiveRadioGroup
xmlns:android="http://schemas.android.com/apk/res/android"
<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"
@ -24,29 +23,25 @@
android:id="@+id/filter_dialog_radioButton1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/filter_dialog_button_background_light"
android:textColor="@drawable/filter_dialog_button_text_light"
android:button="@android:color/transparent"
android:layout_marginRight="2dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="?attr/filter_dialog_button_background"
android:button="@android:color/transparent"
android:checked="false"
android:foreground="?attr/selectableItemBackground"
android:tag=""
android:gravity="center" />
android:gravity="center"
android:textColor="@drawable/filter_dialog_button_text_light" />
<RadioButton
android:id="@+id/filter_dialog_radioButton2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/filter_dialog_button_background_light"
android:textColor="@drawable/filter_dialog_button_text_light"
android:background="?attr/filter_dialog_button_background"
android:button="@android:color/transparent"
android:checked="false"
android:foreground="?attr/selectableItemBackground"
android:tag=""
android:gravity="center" />
android:gravity="center"
android:textColor="@drawable/filter_dialog_button_text_light" />
</LinearLayout>
</androidx.cardview.widget.CardView>
@ -54,10 +49,8 @@
android:id="@+id/filter_dialog_clear"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/filter_dialog_button_clear"
android:background="?attr/filter_dialog_button_clear"
android:button="@android:color/transparent"
android:foreground="?attr/selectableItemBackground"
android:tag=""
android:checked="true" />
</de.danoeh.antennapod.view.RecursiveRadioGroup>

View File

@ -1,8 +1,10 @@
package de.danoeh.antennapod.core.feed;
import android.text.TextUtils;
import android.util.Log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import de.danoeh.antennapod.core.storage.DBReader;
@ -11,17 +13,21 @@ import de.danoeh.antennapod.core.util.LongList;
import static de.danoeh.antennapod.core.feed.FeedItem.TAG_FAVORITE;
public class FeedItemFilter {
private final String[] mProperties;
private boolean showPlayed = false;
private boolean showUnplayed = false;
private boolean showPaused = false;
private boolean showNotPaused = false;
private boolean showQueued = false;
private boolean showNotQueued = false;
private boolean showDownloaded = false;
private boolean showNotDownloaded = false;
private boolean showHasMedia = false;
private boolean showNoMedia = false;
private boolean showIsFavorite = false;
private boolean showNotFavorite = false;
public FeedItemFilter(String properties) {
this(TextUtils.split(properties, ","));
@ -29,14 +35,17 @@ public class FeedItemFilter {
public FeedItemFilter(String[] properties) {
this.mProperties = properties;
for(String property : properties) {
Log.d("***xxx***", Arrays.toString(properties));
for (String property : properties) {
// see R.arrays.feed_filter_values
switch(property) {
switch ("" + property) {
case "unplayed":
showUnplayed = true;
break;
case "paused":
showPaused = true;
case "not_paused":
showNotPaused = true;
break;
case "played":
showPlayed = true;
@ -55,10 +64,14 @@ public class FeedItemFilter {
break;
case "has_media":
showHasMedia = true;
case "no_media":
showNoMedia = true;
break;
case "is_favorite":
showIsFavorite = true;
break;
case "not_favorite":
showNotFavorite = true;
}
}
}
@ -67,7 +80,7 @@ public class FeedItemFilter {
* Run a list of feed items through the filter.
*/
public List<FeedItem> filter(List<FeedItem> items) {
if(mProperties.length == 0) return items;
if (mProperties.length == 0) return items;
List<FeedItem> result = new ArrayList<>();
@ -77,12 +90,15 @@ public class FeedItemFilter {
if (showQueued && showNotQueued) return result;
if (showDownloaded && showNotDownloaded) return result;
final LongList queuedIds = DBReader.getQueueIDList();
for(FeedItem item : items) {
final LongList queuedIds = DBReader.getQueueIDList();
for (FeedItem item : items) {
// If the item does not meet a requirement, skip it.
if (showPlayed && !item.isPlayed()) continue;
if (showUnplayed && item.isPlayed()) continue;
if (showPaused && item.getState() != FeedItem.State.IN_PROGRESS) continue;
if (showNotPaused && item.getState() == FeedItem.State.IN_PROGRESS) continue;
boolean queued = queuedIds.contains(item.getId());
if (showQueued && !queued) continue;
@ -93,8 +109,10 @@ public class FeedItemFilter {
if (showNotDownloaded && downloaded) continue;
if (showHasMedia && !item.hasMedia()) continue;
if (showNoMedia && item.hasMedia()) continue;
if (showIsFavorite && !item.isTagged(TAG_FAVORITE)) continue;
if (showNotFavorite && item.isTagged(TAG_FAVORITE)) continue;
// If the item reaches here, it meets all criteria
result.add(item);

View File

@ -6,10 +6,10 @@ public enum FeedItemFilterGroup {
PLAYED(new ItemProperties(R.string.hide_played_episodes_label, "played"),
new ItemProperties(R.string.not_played, "unplayed")),
PAUSED(new ItemProperties(R.string.hide_paused_episodes_label, "paused"),
new ItemProperties(R.string.not_paused, "_no_id_not_paused")),
new ItemProperties(R.string.not_paused, "not_paused")),
FAVORITE(new ItemProperties(R.string.hide_is_favorite_label, "is_favorite"),
new ItemProperties(R.string.not_favorite, "_no_id_not_favorite")),
MEDIA(new ItemProperties(R.string.has_media, "_no_id_no_media"),
new ItemProperties(R.string.not_favorite, "not_favorite")),
MEDIA(new ItemProperties(R.string.has_media, "has_media"),
new ItemProperties(R.string.no_media, "no_media")),
QUEUED(new ItemProperties(R.string.queued_label, "queued"),
new ItemProperties(R.string.not_queued_label, "not_queued")),

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/dialog_filter_button_active_dark" android:state_checked="true" />
<item android:drawable="@color/dialog_filter_button_inactive_dark" />
</selector>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/accent_light" android:state_checked="true" />
<item android:drawable="@color/master_switch_background_light" />
<item android:drawable="@color/dialog_filter_button_active_light" android:state_checked="true" />
<item android:drawable="@color/dialog_filter_button_inactive_light" />
</selector>

View File

@ -10,7 +10,7 @@
<shape android:shape="oval">
<stroke
android:width="4dp"
android:color="@color/grey" />
android:color="?attr/filter_dialog_clear_active" />
</shape>
</item>
@ -29,7 +29,7 @@
<shape android:shape="line">
<stroke
android:width="4dp"
android:color="@color/grey" />
android:color="?attr/filter_dialog_clear_active" />
</shape>
</rotate>
</item>
@ -47,7 +47,7 @@
<shape android:shape="line">
<stroke
android:width="4dp"
android:color="@color/grey" />
android:color="?attr/filter_dialog_clear_active" />
</shape>
</rotate>

View File

@ -10,7 +10,7 @@
<shape android:shape="oval">
<stroke
android:width="4dp"
android:color="@color/master_switch_background_light" />
android:color="?attr/filter_dialog_clear_inactive" />
</shape>
</item>
@ -28,7 +28,7 @@
<shape android:shape="line">
<stroke
android:width="4dp"
android:color="@color/master_switch_background_light" />
android:color="?attr/filter_dialog_clear_inactive" />
</shape>
</rotate>
</item>
@ -46,7 +46,7 @@
<shape android:shape="line">
<stroke
android:width="4dp"
android:color="@color/master_switch_background_light" />
android:color="?attr/filter_dialog_clear_inactive" />
</shape>
</rotate>

View File

@ -1,69 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="action_about" format="reference"/>
<attr name="action_search" format="reference"/>
<attr name="action_stream" format="reference"/>
<attr name="av_download" format="reference"/>
<attr name="av_fast_forward" format="reference"/>
<attr name="av_pause" format="reference"/>
<attr name="av_play" format="reference"/>
<attr name="av_skip" format="reference"/>
<attr name="av_rewind" format="reference"/>
<attr name="ic_delete" format="reference"/>
<attr name="content_new" format="reference"/>
<attr name="content_remove_from_queue" format="reference"/>
<attr name="storage" format="reference"/>
<attr name="statistics" format="reference"/>
<attr name="feed" format="reference"/>
<attr name="location_web_site" format="reference"/>
<attr name="navigation_accept" format="reference"/>
<attr name="navigation_cancel" format="reference"/>
<attr name="ic_load_more" format="reference"/>
<attr name="navigation_refresh" format="reference"/>
<attr name="navigation_up" format="reference"/>
<attr name="stat_playlist" format="reference"/>
<attr name="ic_folder" format="reference"/>
<attr name="type_video" format="reference"/>
<attr name="dragview_background" format="reference"/>
<attr name="ic_history" format="reference"/>
<attr name="ic_sliders" format="reference"/>
<attr name="ic_settings_playback" format="reference"/>
<attr name="ic_settings" format="reference"/>
<attr name="ic_lock_open" format="reference"/>
<attr name="ic_lock_closed" format="reference"/>
<attr name="ic_filter" format="reference"/>
<attr name="progressBarTheme" format="reference"/>
<attr name="ic_fav" format="reference"/>
<attr name="ic_unfav" format="reference"/>
<attr name="ic_sleep" format="reference"/>
<attr name="ic_sleep_off" format="reference"/>
<attr name="checkbox_multiple" format="reference"/>
<attr name="ic_select_all" format="reference"/>
<attr name="ic_select_none" format="reference"/>
<attr name="ic_sort" format="reference"/>
<attr name="ic_key" format="reference"/>
<attr name="ic_volume_adaption" format="reference"/>
<attr name="ic_network" format="reference"/>
<attr name="ic_appearance" format="reference"/>
<attr name="filter_dialog_button_background" format="reference" />
<attr name="filter_dialog_button_clear" format="reference" />
<attr name="filter_dialog_clear_active" format="reference" />
<attr name="filter_dialog_clear_inactive" format="reference" />
<attr name="action_about" format="reference" />
<attr name="action_search" format="reference" />
<attr name="action_stream" format="reference" />
<attr name="av_download" format="reference" />
<attr name="av_fast_forward" format="reference" />
<attr name="av_pause" format="reference" />
<attr name="av_play" format="reference" />
<attr name="av_skip" format="reference" />
<attr name="av_rewind" format="reference" />
<attr name="ic_delete" format="reference" />
<attr name="content_new" format="reference" />
<attr name="content_remove_from_queue" format="reference" />
<attr name="storage" format="reference" />
<attr name="statistics" format="reference" />
<attr name="feed" format="reference" />
<attr name="location_web_site" format="reference" />
<attr name="navigation_accept" format="reference" />
<attr name="navigation_cancel" format="reference" />
<attr name="ic_load_more" format="reference" />
<attr name="navigation_refresh" format="reference" />
<attr name="navigation_up" format="reference" />
<attr name="stat_playlist" format="reference" />
<attr name="ic_folder" format="reference" />
<attr name="type_video" format="reference" />
<attr name="dragview_background" format="reference" />
<attr name="ic_history" format="reference" />
<attr name="ic_sliders" format="reference" />
<attr name="ic_settings_playback" format="reference" />
<attr name="ic_settings" format="reference" />
<attr name="ic_lock_open" format="reference" />
<attr name="ic_lock_closed" format="reference" />
<attr name="ic_filter" format="reference" />
<attr name="progressBarTheme" format="reference" />
<attr name="ic_fav" format="reference" />
<attr name="ic_unfav" format="reference" />
<attr name="ic_sleep" format="reference" />
<attr name="ic_sleep_off" format="reference" />
<attr name="checkbox_multiple" format="reference" />
<attr name="ic_select_all" format="reference" />
<attr name="ic_select_none" format="reference" />
<attr name="ic_sort" format="reference" />
<attr name="ic_key" format="reference" />
<attr name="ic_volume_adaption" format="reference" />
<attr name="ic_network" format="reference" />
<attr name="ic_appearance" format="reference" />
<attr name="ic_questionmark" format="reference" />
<attr name="ic_chat" format="reference"/>
<attr name="ic_chat" format="reference" />
<attr name="ic_bug" format="reference" />
<attr name="master_switch_background" format="color"/>
<attr name="currently_playing_background" format="color"/>
<attr name="ic_bookmark" format="reference"/>
<attr name="master_switch_background" format="color" />
<attr name="currently_playing_background" format="color" />
<attr name="ic_bookmark" format="reference" />
<attr name="ic_settings_speed" format="reference" />
<attr name="ic_settings_skip" format="reference" />
<attr name="drawer_activated_color" format="color"/>
<attr name="batch_edit_fab_icon" format="reference"/>
<attr name="action_icon_color" format="color"/>
<attr name="scrollbar_thumb" format="reference"/>
<attr name="background_elevated" format="color"/>
<attr name="drawer_activated_color" format="color" />
<attr name="batch_edit_fab_icon" format="reference" />
<attr name="action_icon_color" format="color" />
<attr name="scrollbar_thumb" format="reference" />
<attr name="background_elevated" format="color" />
<declare-styleable name="SquareImageView">
<attr name="direction" format="enum">
<enum name="width" value="0"/>
<enum name="height" value="1"/>
<enum name="minimum" value="2"/>
<enum name="width" value="0" />
<enum name="height" value="1" />
<enum name="minimum" value="2" />
</attr>
</declare-styleable>
</resources>

View File

@ -28,4 +28,16 @@
<color name="master_switch_background_light">#DDDDDD</color>
<color name="master_switch_background_dark">#191919</color>
<!-- filter dialog -->
<color name="dialog_filter_button_inactive_dark">#757575</color>
<color name="dialog_filter_button_inactive_light">#DDDDDD</color>
<color name="dialog_filter_button_active_dark">#3D8BFF</color>
<color name="dialog_filter_button_active_light">#0078C2</color>
<color name="dialog_filter_clear_active_light">#46C6C6C6</color>
<color name="dialog_filter_clear_active_dark">#43707070</color>
<color name="dialog_filter_clear_inactive_light">#757575</color>
<color name="dialog_filter_clear_inactive_dark">#46C6C6C6</color>
</resources>

View File

@ -1,11 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.AntennaPod.Light" parent="Theme.Base.AntennaPod.Light">
<!-- Room for API dependent attributes -->
</style>
<style name="Theme.Base.AntennaPod.Light" parent="Theme.MaterialComponents.Light">
<item name="filter_dialog_button_background">
@drawable/filter_dialog_button_background_light
</item>
<item name="filter_dialog_button_clear">@drawable/filter_dialog_button_clear</item>
<item name="filter_dialog_clear_active">@color/dialog_filter_clear_active_light</item>
<item name="filter_dialog_clear_inactive">@color/dialog_filter_clear_inactive_light</item>
<item name="colorPrimary">@color/accent_light</item>
<item name="colorAccent">@color/accent_light</item>
<item name="colorSecondary">@color/accent_light</item>
@ -80,6 +86,12 @@
</style>
<style name="Theme.Base.AntennaPod.Dark" parent="Theme.MaterialComponents">
<item name="filter_dialog_button_background">
@drawable/filter_dialog_button_background_dark
</item>
<item name="filter_dialog_button_clear">@drawable/filter_dialog_button_clear</item>
<item name="filter_dialog_clear_active">@color/dialog_filter_clear_active_dark</item>
<item name="filter_dialog_clear_inactive">@color/dialog_filter_clear_inactive_dark</item>
<item name="colorAccent">@color/accent_dark</item>
<item name="colorSecondary">@color/accent_dark</item>
<item name="colorOnSecondary">@color/black</item>