11package org.schabi.newpipe.local.feed
22
3+ import android.app.Application
34import android.content.Context
45import androidx.core.content.edit
56import androidx.lifecycle.LiveData
@@ -13,6 +14,7 @@ import io.reactivex.rxjava3.core.Flowable
1314import io.reactivex.rxjava3.functions.Function5
1415import io.reactivex.rxjava3.processors.BehaviorProcessor
1516import io.reactivex.rxjava3.schedulers.Schedulers
17+ import org.schabi.newpipe.App
1618import org.schabi.newpipe.R
1719import org.schabi.newpipe.database.feed.model.FeedGroupEntity
1820import org.schabi.newpipe.database.stream.StreamWithState
@@ -27,12 +29,12 @@ import java.time.OffsetDateTime
2729import java.util.concurrent.TimeUnit
2830
2931class FeedViewModel (
30- private val applicationContext : Context ,
32+ private val application : Application ,
3133 groupId : Long = FeedGroupEntity .GROUP_ALL_ID ,
3234 initialShowPlayedItems : Boolean = true ,
3335 initialShowFutureItems : Boolean = true
3436) : ViewModel() {
35- private var feedDatabaseManager: FeedDatabaseManager = FeedDatabaseManager (applicationContext )
37+ private val feedDatabaseManager = FeedDatabaseManager (application )
3638
3739 private val toggleShowPlayedItems = BehaviorProcessor .create<Boolean >()
3840 private val toggleShowPlayedItemsFlowable = toggleShowPlayedItems
@@ -114,24 +116,24 @@ class FeedViewModel(
114116 }
115117
116118 fun saveShowPlayedItemsToPreferences (showPlayedItems : Boolean ) =
117- PreferenceManager .getDefaultSharedPreferences(applicationContext ).edit {
118- this .putBoolean(applicationContext .getString(R .string.feed_show_played_items_key), showPlayedItems)
119+ PreferenceManager .getDefaultSharedPreferences(application ).edit {
120+ this .putBoolean(application .getString(R .string.feed_show_played_items_key), showPlayedItems)
119121 this .apply ()
120122 }
121123
122- fun getShowPlayedItemsFromPreferences () = getShowPlayedItemsFromPreferences(applicationContext )
124+ fun getShowPlayedItemsFromPreferences () = getShowPlayedItemsFromPreferences(application )
123125
124126 fun toggleFutureItems (showFutureItems : Boolean ) {
125127 toggleShowFutureItems.onNext(showFutureItems)
126128 }
127129
128130 fun saveShowFutureItemsToPreferences (showFutureItems : Boolean ) =
129- PreferenceManager .getDefaultSharedPreferences(applicationContext ).edit {
130- this .putBoolean(applicationContext .getString(R .string.feed_show_future_items_key), showFutureItems)
131+ PreferenceManager .getDefaultSharedPreferences(application ).edit {
132+ this .putBoolean(application .getString(R .string.feed_show_future_items_key), showFutureItems)
131133 this .apply ()
132134 }
133135
134- fun getShowFutureItemsFromPreferences () = getShowFutureItemsFromPreferences(applicationContext )
136+ fun getShowFutureItemsFromPreferences () = getShowFutureItemsFromPreferences(application )
135137
136138 companion object {
137139 private fun getShowPlayedItemsFromPreferences (context : Context ) =
@@ -143,7 +145,7 @@ class FeedViewModel(
143145 fun getFactory (context : Context , groupId : Long ) = viewModelFactory {
144146 initializer {
145147 FeedViewModel (
146- context.applicationContext ,
148+ App .getApp() ,
147149 groupId,
148150 // Read initial value from preferences
149151 getShowPlayedItemsFromPreferences(context.applicationContext),
0 commit comments