From aab19f3a5c35a30847cf6b3f50680a0269e795df Mon Sep 17 00:00:00 2001 From: mueller-ma Date: Fri, 5 May 2023 17:22:31 +0200 Subject: [PATCH] Ignore subscription filter when suggesting tags (#6453) I have the following setup: * A tag 'Done' with fully listened podcasts * The subscription filter "counter greater 0" * The subscription counter "downloaded episodes" This way all done podcasts aren't visible in the drawer. When I want to tag another podcast as done, 'Done' isn't auto-completed. With this change all tags will be auto-completed. --- .../activity/SelectSubscriptionActivity.java | 3 +- .../antennapod/dialog/TagSettingsDialog.java | 17 ++++++----- .../fragment/NavDrawerFragment.java | 28 +++++++++++-------- .../fragment/SubscriptionFragment.java | 20 +++++++------ .../antennapod/ui/home/HomeFragment.java | 21 ++++++++------ .../antennapod/core/storage/DBReader.java | 28 +++++++++++-------- .../antennapod/core/storage/DbReaderTest.java | 4 +-- 7 files changed, 71 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/SelectSubscriptionActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/SelectSubscriptionActivity.java index 48f91672a..34e93bf22 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/SelectSubscriptionActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/SelectSubscriptionActivity.java @@ -31,6 +31,7 @@ import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.NavDrawerData; import de.danoeh.antennapod.databinding.SubscriptionSelectionActivityBinding; import de.danoeh.antennapod.model.feed.Feed; +import de.danoeh.antennapod.storage.preferences.UserPreferences; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -142,7 +143,7 @@ public class SelectSubscriptionActivity extends AppCompatActivity { } disposable = Observable.fromCallable( () -> { - NavDrawerData data = DBReader.getNavDrawerData(); + NavDrawerData data = DBReader.getNavDrawerData(UserPreferences.getSubscriptionsFilter()); return getFeedItems(data.items, new ArrayList<>()); }) .subscribeOn(Schedulers.io()) diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java index d7ca80b17..64bb32897 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/TagSettingsDialog.java @@ -7,11 +7,19 @@ import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.widget.ArrayAdapter; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.google.android.material.dialog.MaterialAlertDialogBuilder; import androidx.fragment.app.DialogFragment; import androidx.recyclerview.widget.GridLayoutManager; + +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.SimpleChipAdapter; import de.danoeh.antennapod.core.storage.DBReader; @@ -24,11 +32,6 @@ import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - public class TagSettingsDialog extends DialogFragment { public static final String TAG = "TagSettingsDialog"; private static final String ARG_FEED_PREFERENCES = "feed_preferences"; @@ -107,7 +110,7 @@ public class TagSettingsDialog extends DialogFragment { private void loadTags() { Observable.fromCallable( () -> { - NavDrawerData data = DBReader.getNavDrawerData(); + NavDrawerData data = DBReader.getNavDrawerData(null); List items = data.items; List folders = new ArrayList(); for (NavDrawerData.DrawerItem item : items) { 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 ecb24a1e1..9f3e6465f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java @@ -13,6 +13,7 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ProgressBar; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; @@ -20,14 +21,26 @@ import androidx.core.util.Pair; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; + import com.google.android.material.bottomsheet.BottomSheetBehavior; + +import org.apache.commons.lang3.StringUtils; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.PreferenceActivity; import de.danoeh.antennapod.adapter.NavListAdapter; import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.menuhandler.MenuItemUtils; -import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.NavDrawerData; @@ -40,22 +53,13 @@ import de.danoeh.antennapod.event.FeedListUpdateEvent; import de.danoeh.antennapod.event.QueueEvent; import de.danoeh.antennapod.event.UnreadItemsUpdateEvent; import de.danoeh.antennapod.model.feed.Feed; +import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter; import de.danoeh.antennapod.ui.home.HomeFragment; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; -import org.apache.commons.lang3.StringUtils; -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; public class NavDrawerFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener { @VisibleForTesting @@ -369,7 +373,7 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS private void loadData() { disposable = Observable.fromCallable( () -> { - NavDrawerData data = DBReader.getNavDrawerData(); + NavDrawerData data = DBReader.getNavDrawerData(UserPreferences.getSubscriptionsFilter()); return new Pair<>(data, makeFlatDrawerData(data.items, 0)); }) .subscribeOn(Schedulers.io()) 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 a0698229a..490c79d47 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -13,15 +13,26 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ProgressBar; import android.widget.TextView; + import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.joanzapata.iconify.Iconify; import com.leinardi.android.speeddial.SpeedDialView; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.adapter.SubscriptionsRecyclerAdapter; @@ -47,13 +58,6 @@ import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; /** * Fragment for displaying feed subscriptions @@ -289,7 +293,7 @@ public class SubscriptionFragment extends Fragment emptyView.hide(); disposable = Observable.fromCallable( () -> { - NavDrawerData data = DBReader.getNavDrawerData(); + NavDrawerData data = DBReader.getNavDrawerData(UserPreferences.getSubscriptionsFilter()); List items = data.items; for (NavDrawerData.DrawerItem item : items) { if (item.type == NavDrawerData.DrawerItem.Type.TAG diff --git a/app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java b/app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java index f65e9fee7..1a700a296 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java @@ -14,11 +14,21 @@ import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; + import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentContainerView; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.menuhandler.MenuItemUtils; @@ -28,6 +38,7 @@ import de.danoeh.antennapod.databinding.HomeFragmentBinding; import de.danoeh.antennapod.event.FeedListUpdateEvent; import de.danoeh.antennapod.event.FeedUpdateRunningEvent; import de.danoeh.antennapod.fragment.SearchFragment; +import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.ui.home.sections.AllowNotificationsSection; import de.danoeh.antennapod.ui.home.sections.DownloadsSection; import de.danoeh.antennapod.ui.home.sections.EpisodesSurpriseSection; @@ -39,13 +50,6 @@ import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; /** * Shows unread or recently published episodes @@ -182,7 +186,8 @@ public class HomeFragment extends Fragment implements Toolbar.OnMenuItemClickLis if (disposable != null) { disposable.dispose(); } - disposable = Observable.fromCallable(() -> DBReader.getNavDrawerData().items.size()) + disposable = Observable.fromCallable(() -> + DBReader.getNavDrawerData(UserPreferences.getSubscriptionsFilter()).items.size()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(numSubscriptions -> { diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index 4a2c6148a..94a7334f3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -1,11 +1,12 @@ package de.danoeh.antennapod.core.storage; import android.database.Cursor; +import android.text.TextUtils; +import android.util.Log; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.collection.ArrayMap; -import android.text.TextUtils; -import android.util.Log; import java.util.ArrayList; import java.util.Collections; @@ -14,6 +15,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import de.danoeh.antennapod.core.util.LongList; +import de.danoeh.antennapod.core.util.comparator.DownloadStatusComparator; +import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator; +import de.danoeh.antennapod.core.util.comparator.PlaybackCompletionDateComparator; +import de.danoeh.antennapod.model.download.DownloadStatus; import de.danoeh.antennapod.model.feed.Chapter; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedItem; @@ -22,19 +28,14 @@ import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.model.feed.SortOrder; import de.danoeh.antennapod.model.feed.SubscriptionsFilter; -import de.danoeh.antennapod.storage.preferences.UserPreferences; -import de.danoeh.antennapod.model.download.DownloadStatus; import de.danoeh.antennapod.storage.database.PodDBAdapter; -import de.danoeh.antennapod.storage.database.mapper.DownloadStatusCursorMapper; import de.danoeh.antennapod.storage.database.mapper.ChapterCursorMapper; +import de.danoeh.antennapod.storage.database.mapper.DownloadStatusCursorMapper; import de.danoeh.antennapod.storage.database.mapper.FeedCursorMapper; import de.danoeh.antennapod.storage.database.mapper.FeedItemCursorMapper; import de.danoeh.antennapod.storage.database.mapper.FeedMediaCursorMapper; import de.danoeh.antennapod.storage.database.mapper.FeedPreferencesCursorMapper; -import de.danoeh.antennapod.core.util.LongList; -import de.danoeh.antennapod.core.util.comparator.DownloadStatusComparator; -import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator; -import de.danoeh.antennapod.core.util.comparator.PlaybackCompletionDateComparator; +import de.danoeh.antennapod.storage.preferences.UserPreferences; /** * Provides methods for reading data from the AntennaPod database. @@ -811,14 +812,17 @@ public final class DBReader { * items. */ @NonNull - public static NavDrawerData getNavDrawerData() { + public static NavDrawerData getNavDrawerData(@Nullable SubscriptionsFilter subscriptionsFilter) { Log.d(TAG, "getNavDrawerData() called with: " + ""); PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); final Map feedCounters = adapter.getFeedCounters(UserPreferences.getFeedCounterSetting()); - SubscriptionsFilter subscriptionsFilter = UserPreferences.getSubscriptionsFilter(); - List feeds = subscriptionsFilter.filter(getFeedList(adapter), feedCounters); + List feeds = getFeedList(adapter); + + if (subscriptionsFilter != null) { + feeds = subscriptionsFilter.filter(feeds, feedCounters); + } Comparator comparator; int feedOrder = UserPreferences.getFeedOrder(); diff --git a/core/src/test/java/de/danoeh/antennapod/core/storage/DbReaderTest.java b/core/src/test/java/de/danoeh/antennapod/core/storage/DbReaderTest.java index 3fadf7528..b67bc48ea 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/storage/DbReaderTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/storage/DbReaderTest.java @@ -330,7 +330,7 @@ public class DbReaderTest { final int numFeeds = 10; final int numItems = 10; DbTestUtils.saveFeedlist(numFeeds, numItems, true); - NavDrawerData navDrawerData = DBReader.getNavDrawerData(); + NavDrawerData navDrawerData = DBReader.getNavDrawerData(UserPreferences.getSubscriptionsFilter()); assertEquals(numFeeds, navDrawerData.items.size()); assertEquals(0, navDrawerData.numNewItems); assertEquals(0, navDrawerData.queueSize); @@ -359,7 +359,7 @@ public class DbReaderTest { adapter.close(); - NavDrawerData navDrawerData = DBReader.getNavDrawerData(); + NavDrawerData navDrawerData = DBReader.getNavDrawerData(UserPreferences.getSubscriptionsFilter()); assertEquals(numFeeds, navDrawerData.items.size()); assertEquals(numNew, navDrawerData.numNewItems); assertEquals(numQueue, navDrawerData.queueSize);