diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java index 9da83435e..eea977c2e 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -61,7 +61,7 @@ public class NavListAdapter extends BaseAdapter private final ItemAccess itemAccess; private final WeakReference 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; } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/FeedFilterDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/FeedFilterDialog.java new file mode 100644 index 000000000..7d1fe4026 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/dialog/FeedFilterDialog.java @@ -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(); + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java index 590f487f6..04714f4aa 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java @@ -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()); } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java index 7ae28130e..33e4cb764 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -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() { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/UserInterfacePreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/UserInterfacePreferencesFragment.java index a44623f48..4596fc90e 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/UserInterfacePreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/UserInterfacePreferencesFragment.java @@ -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); } diff --git a/app/src/main/res/layout/fragment_subscriptions.xml b/app/src/main/res/layout/fragment_subscriptions.xml index f37a6febd..a1a5a26f2 100644 --- a/app/src/main/res/layout/fragment_subscriptions.xml +++ b/app/src/main/res/layout/fragment_subscriptions.xml @@ -14,8 +14,22 @@ app:title="@string/subscriptions_label" android:id="@+id/toolbar"/> - + + - + android:importantForAccessibility="no" + android:paddingTop="8dp" + android:paddingBottom="8dp"> - + + + diff --git a/app/src/main/res/menu/subscriptions.xml b/app/src/main/res/menu/subscriptions.xml index 1780592d5..8009061e5 100644 --- a/app/src/main/res/menu/subscriptions.xml +++ b/app/src/main/res/menu/subscriptions.xml @@ -9,6 +9,11 @@ custom:showAsAction="always" android:icon="?attr/navigation_refresh"/> + + - - + + + + + = 0; i--) { + if (feedCounters.get(feeds.get(i).getId()) <= 0) { + feedCounters.delete(feeds.get(i).getId()); + feeds.remove(i); + } + } + } + Comparator comparator; int feedOrder = UserPreferences.getFeedOrder(); if (feedOrder == UserPreferences.FEED_ORDER_COUNTER) { diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 13ff092b0..ba6c2f196 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -233,6 +233,16 @@ 3 + + 0 + 1 + + + + @string/no_filter_label + @string/hide_subscriptions_where_counter_is_zero + + @string/media_player_builtin @string/media_player_sonic diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 295f539ad..1059a55c1 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -401,7 +401,7 @@ Episode download Streaming User Interface - Appearance, Subscription order, Lockscreen + Appearance, Subscriptions, Lockscreen Select Theme Set Navigation Drawer items Change which items appear in the navigation drawer. @@ -522,6 +522,11 @@ Select page Delete removes from Queue Automatically remove an episode from the queue when it is deleted. + Subscription Filter + Filter your subscriptions in navigation drawer and subscriptions screen. + Hide if counter is zero + None + Subscriptions are filtered. About