@@ -5,7 +5,8 @@ import androidx.core.content.edit
55import androidx.lifecycle.LiveData
66import androidx.lifecycle.MutableLiveData
77import androidx.lifecycle.ViewModel
8- import androidx.lifecycle.ViewModelProvider
8+ import androidx.lifecycle.viewmodel.initializer
9+ import androidx.lifecycle.viewmodel.viewModelFactory
910import androidx.preference.PreferenceManager
1011import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
1112import io.reactivex.rxjava3.core.Flowable
@@ -139,21 +140,16 @@ class FeedViewModel(
139140 private fun getShowFutureItemsFromPreferences (context : Context ) =
140141 PreferenceManager .getDefaultSharedPreferences(context)
141142 .getBoolean(context.getString(R .string.feed_show_future_items_key), true )
142- }
143-
144- class Factory (
145- private val context : Context ,
146- private val groupId : Long = FeedGroupEntity .GROUP_ALL_ID
147- ) : ViewModelProvider.Factory {
148- @Suppress(" UNCHECKED_CAST" )
149- override fun <T : ViewModel > create (modelClass : Class <T >): T {
150- return FeedViewModel (
151- context.applicationContext,
152- groupId,
153- // Read initial value from preferences
154- getShowPlayedItemsFromPreferences(context.applicationContext),
155- getShowFutureItemsFromPreferences(context.applicationContext)
156- ) as T
143+ fun getFactory (context : Context , groupId : Long ) = viewModelFactory {
144+ initializer {
145+ FeedViewModel (
146+ context.applicationContext,
147+ groupId,
148+ // Read initial value from preferences
149+ getShowPlayedItemsFromPreferences(context.applicationContext),
150+ getShowFutureItemsFromPreferences(context.applicationContext)
151+ )
152+ }
157153 }
158154 }
159155}
0 commit comments