@@ -28,20 +28,17 @@ import org.schabi.newpipe.util.DEFAULT_THROTTLE_TIMEOUT
2828import java.time.OffsetDateTime
2929import java.util.concurrent.TimeUnit
3030
31- enum class ShowItems {
32- WATCHED , PARTIALLY_WATCHED , DEFAULT
33- }
3431class FeedViewModel (
3532 private val application : Application ,
3633 groupId : Long = FeedGroupEntity .GROUP_ALL_ID ,
37- initialShowPlayedItems : ShowItems = ShowItems .DEFAULT ,
34+ initialStreamVisibility : StreamVisibilityStatus = StreamVisibilityStatus .DEFAULT ,
3835 initialShowFutureItems : Boolean = true
3936) : ViewModel() {
4037 private val feedDatabaseManager = FeedDatabaseManager (application)
4138
42- private val toggleShowPlayedItems = BehaviorProcessor .create<ShowItems >()
43- private val toggleShowPlayedItemsFlowable = toggleShowPlayedItems
44- .startWithItem(initialShowPlayedItems )
39+ private val streamVisibilityState = BehaviorProcessor .create<StreamVisibilityStatus >()
40+ private val streamVisibilityStateFlowable = streamVisibilityState
41+ .startWithItem(initialStreamVisibility )
4542 .distinctUntilChanged()
4643
4744 private val toggleShowFutureItems = BehaviorProcessor .create<Boolean >()
@@ -55,12 +52,12 @@ class FeedViewModel(
5552 private var combineDisposable = Flowable
5653 .combineLatest(
5754 FeedEventManager .events(),
58- toggleShowPlayedItemsFlowable ,
55+ streamVisibilityStateFlowable ,
5956 toggleShowFutureItemsFlowable,
6057 feedDatabaseManager.notLoadedCount(groupId),
6158 feedDatabaseManager.oldestSubscriptionUpdate(groupId),
6259
63- Function5 { t1: FeedEventManager .Event , t2: ShowItems , t3: Boolean ,
60+ Function5 { t1: FeedEventManager .Event , t2: StreamVisibilityStatus , t3: Boolean ,
6461 t4: Long , t5: List <OffsetDateTime > ->
6562 return @Function5 CombineResultEventHolder (t1, t2, t3, t4, t5.firstOrNull())
6663 }
@@ -74,10 +71,10 @@ class FeedViewModel(
7471 .getStreams(
7572 groupId,
7673 ! (
77- showPlayedItems == ShowItems . WATCHED ||
78- showPlayedItems == ShowItems . PARTIALLY_WATCHED
74+ showPlayedItems == StreamVisibilityStatus . HIDE_WATCHED ||
75+ showPlayedItems == StreamVisibilityStatus . HIDE_PARTIALLY_WATCHED
7976 ),
80- showPlayedItems != ShowItems . PARTIALLY_WATCHED ,
77+ showPlayedItems != StreamVisibilityStatus . HIDE_PARTIALLY_WATCHED ,
8178 showFutureItems
8279 )
8380 .blockingGet(arrayListOf ())
@@ -110,7 +107,7 @@ class FeedViewModel(
110107
111108 private data class CombineResultEventHolder (
112109 val t1 : FeedEventManager .Event ,
113- val t2 : ShowItems ,
110+ val t2 : StreamVisibilityStatus ,
114111 val t3 : Boolean ,
115112 val t4 : Long ,
116113 val t5 : OffsetDateTime ?
@@ -123,20 +120,20 @@ class FeedViewModel(
123120 val t4 : OffsetDateTime ?
124121 )
125122
126- fun togglePlayedItems ( showItems : ShowItems ) {
127- toggleShowPlayedItems .onNext(showItems )
123+ fun changeVisibilityState ( streamVisibilityStatus : StreamVisibilityStatus ) {
124+ streamVisibilityState .onNext(streamVisibilityStatus )
128125 }
129126
130- fun saveShowPlayedItemsToPreferences ( showItems : ShowItems ) =
127+ fun saveStreamVisibilityStateToPreferences ( streamVisibilityStatus : StreamVisibilityStatus ) =
131128 PreferenceManager .getDefaultSharedPreferences(application).edit {
132129 this .putString(
133- application.getString(R .string.feed_show_played_items_key ),
134- showItems .toString()
130+ application.getString(R .string.feed_stream_visibility_state_key ),
131+ streamVisibilityStatus .toString()
135132 )
136133 this .apply ()
137134 }
138135
139- fun getItemsVisibilityFromPreferences () = getItemsVisibilityFromPreferences (application)
136+ fun getItemsVisibilityFromPreferences () = getStreamVisibilityStateFromPreferences (application)
140137
141138 fun toggleFutureItems (showFutureItems : Boolean ) {
142139 toggleShowFutureItems.onNext(showFutureItems)
@@ -152,13 +149,13 @@ class FeedViewModel(
152149
153150 companion object {
154151
155- private fun getItemsVisibilityFromPreferences (context : Context ): ShowItems {
152+ private fun getStreamVisibilityStateFromPreferences (context : Context ): StreamVisibilityStatus {
156153 val s = PreferenceManager .getDefaultSharedPreferences(context)
157154 .getString(
158- context.getString(R .string.feed_show_played_items_key ),
159- ShowItems .DEFAULT .toString()
160- ) ? : ShowItems .DEFAULT .toString()
161- return ShowItems .valueOf(s)
155+ context.getString(R .string.feed_stream_visibility_state_key ),
156+ StreamVisibilityStatus .DEFAULT .toString()
157+ ) ? : StreamVisibilityStatus .DEFAULT .toString()
158+ return StreamVisibilityStatus .valueOf(s)
162159 }
163160
164161 private fun getShowFutureItemsFromPreferences (context : Context ) =
@@ -170,7 +167,7 @@ class FeedViewModel(
170167 App .getApp(),
171168 groupId,
172169 // Read initial value from preferences
173- getItemsVisibilityFromPreferences (context.applicationContext),
170+ getStreamVisibilityStateFromPreferences (context.applicationContext),
174171 getShowFutureItemsFromPreferences(context.applicationContext)
175172 )
176173 }
0 commit comments