Merge remote-tracking branch 'origin/Florian'
This commit is contained in:
commit
29c3dce90c
@ -9,17 +9,14 @@ import androidx.lifecycle.viewModelScope
|
||||
import at.xaxa.ledger.data.Entry
|
||||
import at.xaxa.ledger.data.EntryRepository
|
||||
import at.xaxa.ledger.data.db.Category.CategoryEntity
|
||||
import at.xaxa.ledger.ui.add.CategoryListUIState
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
data class CategoryListUIState(val categories: Flow<List<CategoryEntity>> = flowOf(emptyList()))
|
||||
data class CategoryUIState(val categories: CategoryEntity = CategoryEntity(0,"",0))
|
||||
|
||||
|
||||
data class EditUI(
|
||||
@ -30,9 +27,13 @@ class EditViewModel(private val savedStateHandle: SavedStateHandle,
|
||||
private val entryRepository: EntryRepository) : ViewModel() {
|
||||
|
||||
private val entryId: Int = checkNotNull(savedStateHandle["entryId"])
|
||||
private val categoryId: Int = checkNotNull(savedStateHandle["categoryId"])
|
||||
|
||||
|
||||
var editUiState by mutableStateOf(EditUI())
|
||||
var categoryUiState by mutableStateOf(CategoryListUIState())
|
||||
var categoryui by mutableStateOf(CategoryUIState())
|
||||
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
@ -66,5 +67,15 @@ class EditViewModel(private val savedStateHandle: SavedStateHandle,
|
||||
}
|
||||
|
||||
}
|
||||
fun findCategoryByID() {
|
||||
viewModelScope.launch {
|
||||
val category = withContext(Dispatchers.IO) {
|
||||
entryRepository.findCategoryById(categoryId)
|
||||
}
|
||||
categoryui = CategoryUIState(category)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user