From 32652460ce85b47430e54c11363929fc12e658c2 Mon Sep 17 00:00:00 2001 From: Daniel de Haan Date: Sun, 27 Oct 2024 14:38:10 +1100 Subject: [PATCH] resolved setSaveShowShorts and getShowShorts --- .../schabi/newpipe/local/feed/FeedFragment.kt | 4 +-- .../newpipe/local/feed/FeedViewModel.kt | 25 +++++++++++++++++-- .../local/feed/service/FeedLoadManager.kt | 4 +-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index f185eb10dcd..2e951a8757f 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -252,7 +252,7 @@ class FeedFragment : BaseStateFragment() { viewModel.getShowPlayedItemsFromPreferences(), viewModel.getShowPartiallyPlayedItemsFromPreferences(), viewModel.getShowFutureItemsFromPreferences(), - viewModel.getShowShortsFromPreferences() + viewModel.getShowShortsItemsFromPreferences() ) AlertDialog.Builder(context!!) @@ -264,7 +264,7 @@ class FeedFragment : BaseStateFragment() { viewModel.setSaveShowPlayedItems(checkedDialogItems[0]) viewModel.setSaveShowPartiallyPlayedItems(checkedDialogItems[1]) viewModel.setSaveShowFutureItems(checkedDialogItems[2]) - viewModel.setSaveShowShorts(checkedDialogItems[3]) + viewModel.setSaveShowShortsItems(checkedDialogItems[3]) } .setNegativeButton(R.string.cancel, null) .show() diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt index 728570b17e0..868042406d8 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt @@ -33,7 +33,8 @@ class FeedViewModel( groupId: Long = FeedGroupEntity.GROUP_ALL_ID, initialShowPlayedItems: Boolean, initialShowPartiallyPlayedItems: Boolean, - initialShowFutureItems: Boolean + initialShowFutureItems: Boolean, + initialShowShortsItems: Boolean ) : ViewModel() { private val feedDatabaseManager = FeedDatabaseManager(application) @@ -52,6 +53,11 @@ class FeedViewModel( .startWithItem(initialShowFutureItems) .distinctUntilChanged() + private val showShortsItems = BehaviorProcessor.create() + private val showShortsItemsFlowable = showShortsItems + .startWithItem(initialShowShortsItems) + .distinctUntilChanged() + private val mutableStateLiveData = MutableLiveData() val stateLiveData: LiveData = mutableStateLiveData @@ -149,6 +155,16 @@ class FeedViewModel( fun getShowFutureItemsFromPreferences() = getShowFutureItemsFromPreferences(application) + fun setSaveShowShortsItems(showShortsItems: Boolean) { + PreferenceManager.getDefaultSharedPreferences(application).edit { + + this.putBoolean(application.getString(R.string.feed_show_future_items_key), showShortsItems) + this.apply() + } + } + + fun getShowShortsItemsFromPreferences() = getShowShortsItemsFromPreferences(application) + companion object { private fun getShowPlayedItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context) @@ -162,6 +178,10 @@ class FeedViewModel( PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(context.getString(R.string.feed_show_future_items_key), true) + private fun getShowShortsItemsFromPreferences(context: Context) = + PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(context.getString(R.string.feed_show_shorts_items_key), true) + fun getFactory(context: Context, groupId: Long) = viewModelFactory { initializer { FeedViewModel( @@ -170,7 +190,8 @@ class FeedViewModel( // Read initial value from preferences getShowPlayedItemsFromPreferences(context.applicationContext), getShowPartiallyPlayedItemsFromPreferences(context.applicationContext), - getShowFutureItemsFromPreferences(context.applicationContext) + getShowFutureItemsFromPreferences(context.applicationContext), + getShowShortsItemsFromPreferences(context.applicationContext) ) } } diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt index 11c6a67000e..d94e1587800 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadManager.kt @@ -222,8 +222,8 @@ class FeedLoadManager(private val context: Context) { originalInfo!!, streams!!.filter { defaultSharedPreferences - .getBoolean(context.getString(R.string.feed_show_shorts_items_key), true) - ||!it.isShortFormContent() + .getBoolean(context.getString(R.string.feed_show_shorts_items_key), true) || + !it.isShortFormContent() }, errors, )