25 lines
607 B
Kotlin
25 lines
607 B
Kotlin
|
|
package xyz.pixelatedw.recipe.data
|
||
|
|
|
||
|
|
import androidx.lifecycle.ViewModel
|
||
|
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||
|
|
import kotlinx.coroutines.flow.asStateFlow
|
||
|
|
import kotlinx.coroutines.flow.update
|
||
|
|
|
||
|
|
class RecipesView : ViewModel() {
|
||
|
|
private val _activeRecipe = MutableStateFlow<Recipe?>( null )
|
||
|
|
val activeRecipe = _activeRecipe.asStateFlow()
|
||
|
|
|
||
|
|
private val _recipes = MutableStateFlow<List<Recipe>>( arrayListOf() )
|
||
|
|
val recipes = _recipes.asStateFlow()
|
||
|
|
|
||
|
|
fun addRecipe(recipe: Recipe) {
|
||
|
|
_recipes.update {
|
||
|
|
it + recipe
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
fun setActive(recipe: Recipe) {
|
||
|
|
_activeRecipe.update { recipe }
|
||
|
|
}
|
||
|
|
}
|