Add subscriptions filter

This commit is contained in:
asdoi 2020-08-09 09:20:10 +00:00 committed by GitHub
parent 362cb70b8d
commit 23792f4067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 179 additions and 24 deletions

View File

@ -61,7 +61,7 @@ public class NavListAdapter extends BaseAdapter
private final ItemAccess itemAccess;
private final WeakReference<Activity> activity;
private boolean showSubscriptionList = true;
public boolean showSubscriptionList = true;
public NavListAdapter(ItemAccess itemAccess, Activity context) {
this.itemAccess = itemAccess;
@ -296,9 +296,17 @@ public class NavListAdapter extends BaseAdapter
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.nav_section_item, parent, false);
TextView feedsFilteredMsg = convertView.findViewById(R.id.nav_feeds_filtered_message);
convertView.setEnabled(false);
convertView.setOnClickListener(null);
if (UserPreferences.getFeedFilter() != UserPreferences.FEED_FILTER_NONE && showSubscriptionList) {
convertView.setEnabled(true);
feedsFilteredMsg.setText("{md-info-outline} " + context.getString(R.string.subscriptions_are_filtered));
Iconify.addIcons(feedsFilteredMsg);
feedsFilteredMsg.setVisibility(View.VISIBLE);
} else {
convertView.setEnabled(false);
feedsFilteredMsg.setVisibility(View.GONE);
}
return convertView;
}

View File

@ -0,0 +1,40 @@
package de.danoeh.antennapod.dialog;
import android.content.Context;
import androidx.appcompat.app.AlertDialog;
import org.greenrobot.eventbus.EventBus;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
import de.danoeh.antennapod.core.preferences.UserPreferences;
public class FeedFilterDialog {
public static void showDialog(Context context) {
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(context.getString(R.string.pref_filter_feed_title));
dialog.setNegativeButton(android.R.string.cancel, (d, listener) -> d.dismiss());
int selectedIndexTemp = 0;
int selected = UserPreferences.getFeedFilter();
String[] entryValues = context.getResources().getStringArray(R.array.nav_drawer_feed_filter_values);
for (int i = 0; i < entryValues.length; i++) {
if (Integer.parseInt(entryValues[i]) == selected) {
selectedIndexTemp = i;
}
}
final int selectedIndex = selectedIndexTemp;
String[] items = context.getResources().getStringArray(R.array.nav_drawer_feed_filter_options);
dialog.setSingleChoiceItems(items, selectedIndex, (d, which) -> {
if (selectedIndex != which) {
UserPreferences.setFeedFilter(entryValues[which]);
//Update subscriptions
EventBus.getDefault().post(new UnreadItemsUpdateEvent());
}
d.dismiss();
});
dialog.show();
}
}

View File

@ -36,6 +36,7 @@ import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.dialog.FeedFilterDialog;
import de.danoeh.antennapod.dialog.RenameFeedDialog;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
@ -384,6 +385,9 @@ public class NavDrawerFragment extends Fragment implements AdapterView.OnItemCli
startActivity(intent);
}
}
} else if (UserPreferences.getFeedFilter() != UserPreferences.FEED_FILTER_NONE
&& navAdapter.showSubscriptionList) {
FeedFilterDialog.showDialog(requireContext());
}
}

View File

@ -19,8 +19,10 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.joanzapata.iconify.Iconify;
import java.util.concurrent.Callable;
@ -34,6 +36,7 @@ import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
import de.danoeh.antennapod.core.event.UnreadItemsUpdateEvent;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.download.DownloadService;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.storage.DBReader;
@ -42,6 +45,7 @@ import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.download.AutoUpdateManager;
import de.danoeh.antennapod.dialog.FeedFilterDialog;
import de.danoeh.antennapod.dialog.RenameFeedDialog;
import de.danoeh.antennapod.menuhandler.MenuItemUtils;
import de.danoeh.antennapod.view.EmptyViewHandler;
@ -68,6 +72,7 @@ public class SubscriptionFragment extends Fragment {
private FloatingActionButton subscriptionAddButton;
private ProgressBar progressBar;
private EmptyViewHandler emptyView;
private TextView feedsFilteredMsg;
private int mPosition = -1;
private boolean isUpdatingFeeds = false;
@ -94,6 +99,9 @@ public class SubscriptionFragment extends Fragment {
registerForContextMenu(subscriptionGridLayout);
subscriptionAddButton = root.findViewById(R.id.subscriptions_add);
progressBar = root.findViewById(R.id.progLoading);
feedsFilteredMsg = root.findViewById(R.id.feeds_filtered_message);
feedsFilteredMsg.setOnClickListener((l) -> FeedFilterDialog.showDialog(requireContext()));
return root;
}
@ -120,6 +128,9 @@ public class SubscriptionFragment extends Fragment {
case R.id.refresh_item:
AutoUpdateManager.runImmediate(requireContext());
return true;
case R.id.subscriptions_filter:
FeedFilterDialog.showDialog(requireContext());
return true;
case R.id.subscription_num_columns_2:
setColumnNumber(2);
return true;
@ -198,6 +209,14 @@ public class SubscriptionFragment extends Fragment {
emptyView.updateVisibility();
progressBar.setVisibility(View.GONE);
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
if (UserPreferences.getFeedFilter() != UserPreferences.FEED_FILTER_NONE) {
feedsFilteredMsg.setText("{md-info-outline} " + getString(R.string.subscriptions_are_filtered));
Iconify.addIcons(feedsFilteredMsg);
feedsFilteredMsg.setVisibility(View.VISIBLE);
} else {
feedsFilteredMsg.setVisibility(View.GONE);
}
}
private int getDefaultNumOfColumns() {

View File

@ -12,6 +12,7 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.dialog.FeedFilterDialog;
import de.danoeh.antennapod.fragment.NavDrawerFragment;
import org.apache.commons.lang3.ArrayUtils;
@ -75,6 +76,12 @@ public class UserInterfacePreferencesFragment extends PreferenceFragmentCompat {
return true;
});
findPreference(UserPreferences.PREF_FILTER_FEED)
.setOnPreferenceClickListener((preference -> {
FeedFilterDialog.showDialog(requireContext());
return true;
}));
if (Build.VERSION.SDK_INT >= 26) {
findPreference(UserPreferences.PREF_EXPANDED_NOTIFICATION).setVisible(false);
}

View File

@ -14,8 +14,22 @@
app:title="@string/subscriptions_label"
android:id="@+id/toolbar"/>
<GridView
<TextView
android:id="@+id/feeds_filtered_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar"
android:background="?android:attr/selectableItemBackground"
android:gravity="start"
android:paddingStart="8dp"
android:paddingTop="4dp"
android:paddingEnd="8dp"
android:paddingBottom="8dp"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/text_size_small" />
<GridView
android:layout_below="@id/feeds_filtered_message"
android:id="@+id/subscriptions_grid"
android:layout_width="match_parent"
android:numColumns="3"

View File

@ -1,16 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="16dp"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:orientation="vertical"
android:importantForAccessibility="no">
android:importantForAccessibility="no"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:background="?android:attr/listDivider"
tools:background="@android:color/holo_red_dark"/>
</RelativeLayout>
<TextView
android:id="@+id/nav_feeds_filtered_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:paddingStart="@dimen/listitem_icon_leftpadding"
android:paddingTop="4dp"
android:paddingEnd="@dimen/listitem_icon_leftpadding"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/text_size_small" />
</LinearLayout>

View File

@ -9,6 +9,11 @@
custom:showAsAction="always"
android:icon="?attr/navigation_refresh"/>
<item
android:id="@+id/subscriptions_filter"
android:title="@string/filter"
custom:showAsAction="never" />
<item
android:id="@+id/subscription_num_columns"
android:title="@string/subscription_num_columns"

View File

@ -14,20 +14,6 @@
android:key="prefHiddenDrawerItems"
android:summary="@string/pref_nav_drawer_items_sum"
android:title="@string/pref_nav_drawer_items_title"/>
<ListPreference
android:entryValues="@array/nav_drawer_feed_order_values"
android:entries="@array/nav_drawer_feed_order_options"
android:title="@string/pref_nav_drawer_feed_order_title"
android:key="prefDrawerFeedOrder"
android:summary="@string/pref_nav_drawer_feed_order_sum"
android:defaultValue="0"/>
<ListPreference
android:entryValues="@array/nav_drawer_feed_counter_values"
android:entries="@array/nav_drawer_feed_counter_options"
android:title="@string/pref_nav_drawer_feed_counter_title"
android:key="prefDrawerFeedIndicator"
android:summary="@string/pref_nav_drawer_feed_counter_sum"
android:defaultValue="1"/>
<SwitchPreference
android:title="@string/pref_episode_cover_title"
android:key="prefEpisodeCover"
@ -35,6 +21,26 @@
android:defaultValue="true"
android:enabled="true"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/subscriptions_label">
<ListPreference
android:entryValues="@array/nav_drawer_feed_order_values"
android:entries="@array/nav_drawer_feed_order_options"
android:title="@string/pref_nav_drawer_feed_order_title"
android:key="prefDrawerFeedOrder"
android:summary="@string/pref_nav_drawer_feed_order_sum"
android:defaultValue="0"/>
<ListPreference
android:entryValues="@array/nav_drawer_feed_counter_values"
android:entries="@array/nav_drawer_feed_counter_options"
android:title="@string/pref_nav_drawer_feed_counter_title"
android:key="prefDrawerFeedIndicator"
android:summary="@string/pref_nav_drawer_feed_counter_sum"
android:defaultValue="1"/>
<Preference
android:title="@string/pref_filter_feed_title"
android:key="prefFeedFilter"
android:summary="@string/pref_filter_feed_sum" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/external_elements">
<SwitchPreference
android:defaultValue="false"

View File

@ -68,6 +68,7 @@ public class UserPreferences {
private static final String PREF_SHOW_AUTO_DOWNLOAD_REPORT = "prefShowAutoDownloadReport";
public static final String PREF_BACK_BUTTON_BEHAVIOR = "prefBackButtonBehavior";
private static final String PREF_BACK_BUTTON_GO_TO_PAGE = "prefBackButtonGoToPage";
public static final String PREF_FILTER_FEED = "prefFeedFilter";
public static final String PREF_QUEUE_KEEP_SORTED = "prefQueueKeepSorted";
public static final String PREF_QUEUE_KEEP_SORTED_ORDER = "prefQueueKeepSortedOrder";
@ -150,6 +151,8 @@ public class UserPreferences {
public static final int FEED_COUNTER_SHOW_UNPLAYED = 2;
public static final int FEED_COUNTER_SHOW_NONE = 3;
public static final int FEED_COUNTER_SHOW_DOWNLOADED = 4;
public static final int FEED_FILTER_NONE = 0;
public static final int FEED_FILTER_COUNTER_ZERO = 1;
private static Context context;
private static SharedPreferences prefs;
@ -1058,4 +1061,16 @@ public class UserPreferences {
.putString(PREF_QUEUE_KEEP_SORTED_ORDER, sortOrder.name())
.apply();
}
public static int getFeedFilter() {
String value = prefs.getString(PREF_FILTER_FEED, "" + FEED_FILTER_NONE);
return Integer.parseInt(value);
}
public static void setFeedFilter(String value) {
prefs.edit()
.putString(PREF_FILTER_FEED, value)
.commit();
}
}

View File

@ -801,6 +801,16 @@ public final class DBReader {
}
final LongIntMap feedCounters = adapter.getFeedCounters(feedIds);
int feedFilter = UserPreferences.getFeedFilter();
if (feedFilter == UserPreferences.FEED_FILTER_COUNTER_ZERO) {
for (int i = feeds.size() - 1; i >= 0; i--) {
if (feedCounters.get(feeds.get(i).getId()) <= 0) {
feedCounters.delete(feeds.get(i).getId());
feeds.remove(i);
}
}
}
Comparator<Feed> comparator;
int feedOrder = UserPreferences.getFeedOrder();
if (feedOrder == UserPreferences.FEED_ORDER_COUNTER) {

View File

@ -233,6 +233,16 @@
<item>3</item>
</string-array>
<string-array name="nav_drawer_feed_filter_values">
<item>0</item>
<item>1</item>
</string-array>
<string-array name="nav_drawer_feed_filter_options">
<item>@string/no_filter_label</item>
<item>@string/hide_subscriptions_where_counter_is_zero</item>
</string-array>
<string-array name="media_player_options">
<item>@string/media_player_builtin</item>
<item>@string/media_player_sonic</item>

View File

@ -401,7 +401,7 @@
<string name="pref_mobileUpdate_episode_download">Episode download</string>
<string name="pref_mobileUpdate_streaming">Streaming</string>
<string name="user_interface_label">User Interface</string>
<string name="user_interface_sum">Appearance, Subscription order, Lockscreen</string>
<string name="user_interface_sum">Appearance, Subscriptions, Lockscreen</string>
<string name="pref_set_theme_title">Select Theme</string>
<string name="pref_nav_drawer_items_title">Set Navigation Drawer items</string>
<string name="pref_nav_drawer_items_sum">Change which items appear in the navigation drawer.</string>
@ -522,6 +522,11 @@
<string name="back_button_go_to_page_title">Select page</string>
<string name="pref_delete_removes_from_queue_title">Delete removes from Queue</string>
<string name="pref_delete_removes_from_queue_sum">Automatically remove an episode from the queue when it is deleted.</string>
<string name="pref_filter_feed_title">Subscription Filter</string>
<string name="pref_filter_feed_sum">Filter your subscriptions in navigation drawer and subscriptions screen.</string>
<string name="hide_subscriptions_where_counter_is_zero">Hide if counter is zero</string>
<string name="no_filter_label">None</string>
<string name="subscriptions_are_filtered">Subscriptions are filtered.</string>
<!-- About screen -->
<string name="about_pref">About</string>