Merge pull request #8734 from Stypox/feed-group-factory
Improve `FeedGroupDialogViewModel` factory
This commit is contained in:
commit
ed4eb124e4
|
@ -124,11 +124,13 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
|
||||||
|
|
||||||
viewModel = ViewModelProvider(
|
viewModel = ViewModelProvider(
|
||||||
this,
|
this,
|
||||||
FeedGroupDialogViewModel.Factory(
|
FeedGroupDialogViewModel.getFactory(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
groupId, subscriptionsCurrentSearchQuery, subscriptionsShowOnlyUngrouped
|
groupId,
|
||||||
|
subscriptionsCurrentSearchQuery,
|
||||||
|
subscriptionsShowOnlyUngrouped
|
||||||
)
|
)
|
||||||
).get(FeedGroupDialogViewModel::class.java)
|
)[FeedGroupDialogViewModel::class.java]
|
||||||
|
|
||||||
viewModel.groupLiveData.observe(viewLifecycleOwner, Observer(::handleGroup))
|
viewModel.groupLiveData.observe(viewLifecycleOwner, Observer(::handleGroup))
|
||||||
viewModel.subscriptionsLiveData.observe(viewLifecycleOwner) {
|
viewModel.subscriptionsLiveData.observe(viewLifecycleOwner) {
|
||||||
|
|
|
@ -4,7 +4,8 @@ import android.content.Context
|
||||||
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.viewmodel.initializer
|
||||||
|
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||||
import io.reactivex.rxjava3.core.Completable
|
import io.reactivex.rxjava3.core.Completable
|
||||||
import io.reactivex.rxjava3.core.Flowable
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
import io.reactivex.rxjava3.disposables.Disposable
|
import io.reactivex.rxjava3.disposables.Disposable
|
||||||
|
@ -115,18 +116,18 @@ class FeedGroupDialogViewModel(
|
||||||
|
|
||||||
data class Filter(val query: String, val showOnlyUngrouped: Boolean)
|
data class Filter(val query: String, val showOnlyUngrouped: Boolean)
|
||||||
|
|
||||||
class Factory(
|
companion object {
|
||||||
private val context: Context,
|
fun getFactory(
|
||||||
private val groupId: Long = FeedGroupEntity.GROUP_ALL_ID,
|
context: Context,
|
||||||
private val initialQuery: String = "",
|
groupId: Long,
|
||||||
private val initialShowOnlyUngrouped: Boolean = false
|
initialQuery: String,
|
||||||
) : ViewModelProvider.Factory {
|
initialShowOnlyUngrouped: Boolean
|
||||||
@Suppress("UNCHECKED_CAST")
|
) = viewModelFactory {
|
||||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
initializer {
|
||||||
return FeedGroupDialogViewModel(
|
FeedGroupDialogViewModel(
|
||||||
context.applicationContext,
|
context.applicationContext, groupId, initialQuery, initialShowOnlyUngrouped
|
||||||
groupId, initialQuery, initialShowOnlyUngrouped
|
)
|
||||||
) as T
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue