Refactor LiveData extensions

This commit is contained in:
Koitharu
2022-07-13 15:58:20 +03:00
parent 29c82177a9
commit 4607e5ba0f
9 changed files with 21 additions and 61 deletions

View File

@@ -1,5 +1,6 @@
package org.koitharu.kotatsu.widget.shelf
import androidx.lifecycle.LiveData
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
@@ -8,7 +9,6 @@ import org.koitharu.kotatsu.base.ui.BaseViewModel
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
import org.koitharu.kotatsu.widget.shelf.model.CategoryItem
import java.util.*
class ShelfConfigViewModel(
favouritesRepository: FavouritesRepository
@@ -16,7 +16,7 @@ class ShelfConfigViewModel(
private val selectedCategoryId = MutableStateFlow(0L)
val content = combine(
val content: LiveData<List<CategoryItem>> = combine(
favouritesRepository.observeCategories(),
selectedCategoryId
) { categories, selectedId ->
@@ -26,7 +26,7 @@ class ShelfConfigViewModel(
CategoryItem(it.id, it.title, selectedId == it.id)
}
list
}.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default)
}.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, emptyList())
var checkedId: Long by selectedCategoryId::value
}