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 61eb4c8d201..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 @@ -244,13 +244,15 @@ class FeedFragment : BaseStateFragment() { val dialogItems = arrayOf( getString(R.string.feed_show_watched), getString(R.string.feed_show_partially_watched), - getString(R.string.feed_show_upcoming) + getString(R.string.feed_show_upcoming), + getString(R.string.feed_show_shorts) ) val checkedDialogItems = booleanArrayOf( viewModel.getShowPlayedItemsFromPreferences(), viewModel.getShowPartiallyPlayedItemsFromPreferences(), - viewModel.getShowFutureItemsFromPreferences() + viewModel.getShowFutureItemsFromPreferences(), + viewModel.getShowShortsItemsFromPreferences() ) AlertDialog.Builder(context!!) @@ -262,6 +264,7 @@ class FeedFragment : BaseStateFragment() { viewModel.setSaveShowPlayedItems(checkedDialogItems[0]) viewModel.setSaveShowPartiallyPlayedItems(checkedDialogItems[1]) viewModel.setSaveShowFutureItems(checkedDialogItems[2]) + 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..8d2a1e71322 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) { + this.showShortsItems.onNext(showShortsItems) + 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 0b6a8068c99..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 @@ -220,7 +220,11 @@ class FeedLoadManager(private val context: Context) { FeedUpdateInfo( subscriptionEntity, originalInfo!!, - streams!!, + streams!!.filter { + defaultSharedPreferences + .getBoolean(context.getString(R.string.feed_show_shorts_items_key), true) || + !it.isShortFormContent() + }, errors, ) ) @@ -260,7 +264,6 @@ class FeedLoadManager(private val context: Context) { override fun accept(item: Notification) { currentProgress.incrementAndGet() notificationUpdater.onNext(item.value?.name.orEmpty()) - broadcastProgress() } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 56140441cd0..c58035d1054 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -857,4 +857,6 @@ Show more Show less The settings in the export being imported use a vulnerable format that was deprecated since NewPipe 0.27.0. Make sure the export being imported is from a trusted source, and prefer using only exports obtained from NewPipe 0.27.0 or newer in the future. Support for importing settings in this vulnerable format will soon be removed completely, and then old versions of NewPipe will not be able to import settings of exports from new versions anymore. + feed_show_shorts_items + Short form content