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