Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to filter shorts #11650

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,15 @@ class FeedFragment : BaseStateFragment<FeedState>() {
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!!)
Expand All @@ -262,6 +264,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
viewModel.setSaveShowPlayedItems(checkedDialogItems[0])
viewModel.setSaveShowPartiallyPlayedItems(checkedDialogItems[1])
viewModel.setSaveShowFutureItems(checkedDialogItems[2])
viewModel.setSaveShowShortsItems(checkedDialogItems[3])
}
.setNegativeButton(R.string.cancel, null)
.show()
Expand Down
25 changes: 23 additions & 2 deletions app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -52,6 +53,11 @@ class FeedViewModel(
.startWithItem(initialShowFutureItems)
.distinctUntilChanged()

private val showShortsItems = BehaviorProcessor.create<Boolean>()
private val showShortsItemsFlowable = showShortsItems
.startWithItem(initialShowShortsItems)
.distinctUntilChanged()

private val mutableStateLiveData = MutableLiveData<FeedState>()
val stateLiveData: LiveData<FeedState> = mutableStateLiveData

Expand Down Expand Up @@ -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)
TobiGr marked this conversation as resolved.
Show resolved Hide resolved
this.apply()
}
}

fun getShowShortsItemsFromPreferences() = getShowShortsItemsFromPreferences(application)

companion object {
private fun getShowPlayedItemsFromPreferences(context: Context) =
PreferenceManager.getDefaultSharedPreferences(context)
Expand All @@ -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(
Expand All @@ -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)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
Expand Down Expand Up @@ -260,7 +264,6 @@ class FeedLoadManager(private val context: Context) {
override fun accept(item: Notification<FeedUpdateInfo>) {
currentProgress.incrementAndGet()
notificationUpdater.onNext(item.value?.name.orEmpty())

broadcastProgress()
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -857,4 +857,6 @@
<string name="show_more">Show more</string>
<string name="show_less">Show less</string>
<string name="import_settings_vulnerable_format">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.</string>
<string name="feed_show_shorts_items_key">feed_show_shorts_items</string>
<string name="feed_show_shorts">Short form content</string>
</resources>
Loading