Merge remote-tracking branch 'origin/Florian'

This commit is contained in:
Xaver 2025-01-15 10:07:20 +01:00
commit 29c3dce90c

View File

@ -9,17 +9,14 @@ import androidx.lifecycle.viewModelScope
import at.xaxa.ledger.data.Entry import at.xaxa.ledger.data.Entry
import at.xaxa.ledger.data.EntryRepository import at.xaxa.ledger.data.EntryRepository
import at.xaxa.ledger.data.db.Category.CategoryEntity import at.xaxa.ledger.data.db.Category.CategoryEntity
import at.xaxa.ledger.ui.add.CategoryListUIState
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
data class CategoryListUIState(val categories: Flow<List<CategoryEntity>> = flowOf(emptyList())) data class CategoryListUIState(val categories: Flow<List<CategoryEntity>> = flowOf(emptyList()))
data class CategoryUIState(val categories: CategoryEntity = CategoryEntity(0,"",0))
data class EditUI( data class EditUI(
@ -30,9 +27,13 @@ class EditViewModel(private val savedStateHandle: SavedStateHandle,
private val entryRepository: EntryRepository) : ViewModel() { private val entryRepository: EntryRepository) : ViewModel() {
private val entryId: Int = checkNotNull(savedStateHandle["entryId"]) private val entryId: Int = checkNotNull(savedStateHandle["entryId"])
private val categoryId: Int = checkNotNull(savedStateHandle["categoryId"])
var editUiState by mutableStateOf(EditUI()) var editUiState by mutableStateOf(EditUI())
var categoryUiState by mutableStateOf(CategoryListUIState()) var categoryUiState by mutableStateOf(CategoryListUIState())
var categoryui by mutableStateOf(CategoryUIState())
init { init {
viewModelScope.launch { 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)
}
}
} }