push me
This commit is contained in:
parent
29c3dce90c
commit
80a8c8cb06
@ -37,7 +37,7 @@ fun LedgerApp(modifier: Modifier = Modifier){
|
||||
composable(AppRoutes.Home.route){
|
||||
Home(
|
||||
onCardClick = {
|
||||
navController.navigate("edit/$id")
|
||||
navController.navigate("edit/$it")
|
||||
},
|
||||
onButtonClick = {
|
||||
navController.navigate("add")
|
||||
@ -57,7 +57,6 @@ fun LedgerApp(modifier: Modifier = Modifier){
|
||||
})
|
||||
) {
|
||||
backStackEntry ->
|
||||
Log.w("xaver", "edit")
|
||||
Edit(
|
||||
modifier = Modifier,
|
||||
onCardClick = {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package at.xaxa.ledger.ui.edit
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
@ -7,13 +8,12 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ExposedDropdownMenuBox
|
||||
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
||||
import androidx.compose.material3.ExposedDropdownMenuDefaults.TrailingIcon
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableLongStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@ -23,7 +23,6 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import at.xaxa.ledger.data.Entry
|
||||
import at.xaxa.ledger.ui.AppViewModelProvider
|
||||
import at.xaxa.ledger.ui.ButtonDanger
|
||||
import at.xaxa.ledger.ui.ButtonSuccess
|
||||
@ -32,15 +31,22 @@ import at.xaxa.ledger.ui.DatePickerDocked
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun Edit(modifier: Modifier = Modifier, onCardClick: () -> Unit, editViewModel : EditViewModel = viewModel(factory = AppViewModelProvider.Factory)) {
|
||||
val libraryEntity = editViewModel.editUiState.entry
|
||||
val entry = editViewModel.editUiState.entry
|
||||
val categories by editViewModel.categoryUiState.categories.collectAsState(initial = emptyList())
|
||||
|
||||
var name by remember { mutableStateOf(libraryEntity.name) }
|
||||
var spending by remember { mutableStateOf(libraryEntity.amount.toString()) }
|
||||
var selectedDate by remember { mutableLongStateOf(libraryEntity.date) }
|
||||
Log.w("xaver", entry.name)
|
||||
Log.w("xaver", entry.amount.toString())
|
||||
Log.w("xaver", entry.date.toString())
|
||||
Log.w("xaver", editViewModel.categoryUi.categories.categoryName)
|
||||
Log.w("xaver", entry.categoryID.toString())
|
||||
|
||||
|
||||
var name by remember { mutableStateOf(entry.name) }
|
||||
var spending by remember { mutableStateOf(entry.amount.toString()) }
|
||||
var selectedDate by remember { mutableLongStateOf(entry.date) }
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
var selectedItem by remember { mutableStateOf("") }
|
||||
var selectedCategory by remember { mutableIntStateOf(libraryEntity.categoryID) }
|
||||
var selectedItem by remember { mutableStateOf(editViewModel.categoryUi.categories.categoryName) }
|
||||
var selectedCategory by remember { mutableIntStateOf(entry.categoryID) }
|
||||
|
||||
Column(
|
||||
modifier = modifier.fillMaxSize()
|
||||
@ -58,9 +64,9 @@ fun Edit(modifier: Modifier = Modifier, onCardClick: () -> Unit, editViewModel :
|
||||
.fillMaxWidth()
|
||||
)
|
||||
OutlinedTextField(
|
||||
value = name,
|
||||
value = spending,
|
||||
onValueChange = { spending = it },
|
||||
label = { Text("Name") },
|
||||
label = { Text("Spending") },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
)
|
||||
@ -76,7 +82,7 @@ fun Edit(modifier: Modifier = Modifier, onCardClick: () -> Unit, editViewModel :
|
||||
label = { Text("Category") },
|
||||
readOnly = true,
|
||||
trailingIcon = {
|
||||
ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded)
|
||||
TrailingIcon(expanded = expanded)
|
||||
},
|
||||
modifier = Modifier
|
||||
.menuAnchor()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package at.xaxa.ledger.ui.edit
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
@ -27,12 +28,11 @@ 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())
|
||||
var categoryUi by mutableStateOf(CategoryUIState())
|
||||
|
||||
|
||||
init {
|
||||
@ -41,6 +41,8 @@ class EditViewModel(private val savedStateHandle: SavedStateHandle,
|
||||
entryRepository.findEntryById(entryId)
|
||||
}
|
||||
editUiState = EditUI(entry)
|
||||
|
||||
findCategoryByID(entry.categoryID)
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,12 +69,12 @@ class EditViewModel(private val savedStateHandle: SavedStateHandle,
|
||||
}
|
||||
|
||||
}
|
||||
fun findCategoryByID() {
|
||||
fun findCategoryByID(categoryId: Int) {
|
||||
viewModelScope.launch {
|
||||
val category = withContext(Dispatchers.IO) {
|
||||
entryRepository.findCategoryById(categoryId)
|
||||
}
|
||||
categoryui = CategoryUIState(category)
|
||||
categoryUi = CategoryUIState(category)
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user