mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 11:02:35 +01:00
added show watched items toggle preference
default sharedpreference is used to persist and retrieve show watched menu option toggle state
This commit is contained in:
parent
b5ad24eb47
commit
63291f8101
@ -128,6 +128,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
|
|
||||||
val factory = FeedViewModel.Factory(requireContext(), groupId, showPlayedItems)
|
val factory = FeedViewModel.Factory(requireContext(), groupId, showPlayedItems)
|
||||||
viewModel = ViewModelProvider(this, factory).get(FeedViewModel::class.java)
|
viewModel = ViewModelProvider(this, factory).get(FeedViewModel::class.java)
|
||||||
|
showPlayedItems = viewModel.getSavedPlayedItemsToggle()
|
||||||
viewModel.stateLiveData.observe(viewLifecycleOwner, { it?.let(::handleResult) })
|
viewModel.stateLiveData.observe(viewLifecycleOwner, { it?.let(::handleResult) })
|
||||||
|
|
||||||
groupAdapter = GroupieAdapter().apply {
|
groupAdapter = GroupieAdapter().apply {
|
||||||
@ -158,7 +159,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setupListViewMode() {
|
private fun setupListViewMode() {
|
||||||
// does everything needed to setup the layouts for grid or list modes
|
// does everything needed to setup the layouts for grid or list modes
|
||||||
groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCountStreams(context) else 1
|
groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCountStreams(context) else 1
|
||||||
feedBinding.itemsList.layoutManager = GridLayoutManager(requireContext(), groupAdapter.spanCount).apply {
|
feedBinding.itemsList.layoutManager = GridLayoutManager(requireContext(), groupAdapter.spanCount).apply {
|
||||||
@ -213,6 +214,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
showPlayedItems = !item.isChecked
|
showPlayedItems = !item.isChecked
|
||||||
updateTogglePlayedItemsButton(item)
|
updateTogglePlayedItemsButton(item)
|
||||||
viewModel.togglePlayedItems(showPlayedItems)
|
viewModel.togglePlayedItems(showPlayedItems)
|
||||||
|
viewModel.savePlayedItemsToggle(showPlayedItems)
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package org.schabi.newpipe.local.feed
|
package org.schabi.newpipe.local.feed
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import androidx.core.content.edit
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.rxjava3.core.Flowable
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
import io.reactivex.rxjava3.functions.Function4
|
import io.reactivex.rxjava3.functions.Function4
|
||||||
@ -28,6 +30,10 @@ class FeedViewModel(
|
|||||||
initialShowPlayedItems: Boolean = true
|
initialShowPlayedItems: Boolean = true
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
private var feedDatabaseManager: FeedDatabaseManager = FeedDatabaseManager(applicationContext)
|
private var feedDatabaseManager: FeedDatabaseManager = FeedDatabaseManager(applicationContext)
|
||||||
|
private var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
|
||||||
|
companion object {
|
||||||
|
const val SHOW_PLAYED_ITEMS_PREFERENCE = "show_played_items_preference_tag"
|
||||||
|
}
|
||||||
|
|
||||||
private val toggleShowPlayedItems = BehaviorProcessor.create<Boolean>()
|
private val toggleShowPlayedItems = BehaviorProcessor.create<Boolean>()
|
||||||
private val streamItems = toggleShowPlayedItems
|
private val streamItems = toggleShowPlayedItems
|
||||||
@ -81,6 +87,13 @@ class FeedViewModel(
|
|||||||
toggleShowPlayedItems.onNext(showPlayedItems)
|
toggleShowPlayedItems.onNext(showPlayedItems)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun savePlayedItemsToggle(showPlayedItems: Boolean) = sharedPreferences.edit {
|
||||||
|
this.putBoolean(SHOW_PLAYED_ITEMS_PREFERENCE, showPlayedItems)
|
||||||
|
this.apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getSavedPlayedItemsToggle() = sharedPreferences.getBoolean(SHOW_PLAYED_ITEMS_PREFERENCE, true)
|
||||||
|
|
||||||
class Factory(
|
class Factory(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val groupId: Long = FeedGroupEntity.GROUP_ALL_ID,
|
private val groupId: Long = FeedGroupEntity.GROUP_ALL_ID,
|
||||||
|
Loading…
Reference in New Issue
Block a user