Merge remote-tracking branch 'origin/Florian'

# Conflicts:
#	Ledger/app/src/main/java/at/xaxa/ledger/ui/edit/EditUI.kt
#	Ledger/app/src/main/java/at/xaxa/ledger/ui/edit/EditViewModel.kt
This commit is contained in:
Xaver 2025-01-15 09:51:44 +01:00
commit d299f54a1e
4 changed files with 28 additions and 3 deletions

View File

@ -0,0 +1,2 @@
package at.xaxa.ledger.ui.category

View File

@ -0,0 +1,2 @@
package at.xaxa.ledger.ui.category

View File

@ -30,8 +30,10 @@ import at.xaxa.ledger.ui.DatePickerDocked
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun Edit(modifier: Modifier = Modifier, onCardClick: () -> Unit, editViewModel : EditViewModel = viewModel(factory = AppViewModelProvider.Factory)) { fun Edit(modifier: Modifier = Modifier, onCardClick: (Int) -> Unit, EditViewModel : EditViewModel = viewModel(factory = AppViewModelProvider.Factory)) {
val libraryEntity = editViewModel.editUiState.entry val libraryEntity = editViewModel.editUiState.entry
var name by remember { mutableStateOf("") }
var spending by remember { mutableStateOf("") }
var name by remember { mutableStateOf(libraryEntity.name) } var name by remember { mutableStateOf(libraryEntity.name) }
var spending by remember { mutableStateOf(libraryEntity.amount.toString()) } var spending by remember { mutableStateOf(libraryEntity.amount.toString()) }

View File

@ -8,10 +8,19 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope 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.ui.add.CategoryListUIState
import kotlinx.coroutines.Dispatchers 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.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
data class CategoryListUIState(val categories: Flow<List<CategoryEntity>> = flowOf(emptyList()))
data class EditUI( data class EditUI(
val entry: Entry = Entry(0, "", 0.0f, 0, 0) val entry: Entry = Entry(0, "", 0.0f, 0, 0)
@ -23,7 +32,7 @@ class EditViewModel(private val savedStateHandle: SavedStateHandle,
private val entryId: Int = checkNotNull(savedStateHandle["entryId"]) private val entryId: Int = checkNotNull(savedStateHandle["entryId"])
var editUiState by mutableStateOf(EditUI()) var editUiState by mutableStateOf(EditUI())
private set var categoryUiState by mutableStateOf(CategoryListUIState())
init { init {
viewModelScope.launch { viewModelScope.launch {
@ -47,5 +56,15 @@ class EditViewModel(private val savedStateHandle: SavedStateHandle,
entryRepository.updateEntry(editUiState.entry) entryRepository.updateEntry(editUiState.entry)
} }
} }
fun getAllCategories() {
viewModelScope.launch {
val categories = withContext(Dispatchers.IO) {
entryRepository.getAllCategories()
}
categoryUiState = CategoryListUIState(categories)
}
}
} }