Skip to content

Commit

Permalink
Merge pull request #1 from DehaanSolo/internal
Browse files Browse the repository at this point in the history
empty commit (to allow internal review)
  • Loading branch information
DehaanSolo authored Oct 27, 2024
2 parents 709aeea + 3265246 commit f2645e0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
viewModel.getShowPlayedItemsFromPreferences(),
viewModel.getShowPartiallyPlayedItemsFromPreferences(),
viewModel.getShowFutureItemsFromPreferences(),
viewModel.getShowShortsFromPreferences()
viewModel.getShowShortsItemsFromPreferences()
)

AlertDialog.Builder(context!!)
Expand All @@ -264,7 +264,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
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()
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)
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 @@ -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,
)
Expand Down

0 comments on commit f2645e0

Please sign in to comment.