82 lines
2.8 KiB
Kotlin
82 lines
2.8 KiB
Kotlin
package com.hyperling.expensetracker
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
import androidx.compose.material3.AlertDialog
|
|
import androidx.compose.material3.Button
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.material3.TextField
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.text.input.KeyboardCapitalization
|
|
import androidx.compose.ui.text.input.KeyboardType
|
|
import androidx.compose.ui.text.style.TextGeometricTransform
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
@Composable
|
|
fun ExpenseDialogAdd(
|
|
state: ExpenseState,
|
|
onEvent: (ExpenseEvent) -> Unit,
|
|
modifier: Modifier = Modifier
|
|
) {
|
|
AlertDialog(
|
|
onDismissRequest = {
|
|
onEvent(ExpenseEvent.HideDialog)
|
|
},
|
|
title = { Text(text = "Add Expense") },
|
|
text = {
|
|
Column (
|
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
){
|
|
TextField(
|
|
value = state.name,
|
|
onValueChange = {
|
|
onEvent(ExpenseEvent.SetName(it))
|
|
},
|
|
placeholder = {
|
|
Text(text = "Name")
|
|
},
|
|
keyboardOptions = KeyboardOptions(capitalization = KeyboardCapitalization.Words)
|
|
)
|
|
// TBD: Had to make this a String, can we turn it back to a Double somehow?
|
|
TextField(
|
|
value = state.cost,
|
|
onValueChange = {
|
|
onEvent(ExpenseEvent.SetCost(it))
|
|
},
|
|
placeholder = {
|
|
Text(text = "Cost")
|
|
},
|
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal)
|
|
)
|
|
/* Unsure what to do here yet, a simple Picker type does not seems to exist?
|
|
TextField(
|
|
value = state.rate,
|
|
onValueChange = {
|
|
onEvent(ExpenseEvent.SetRate(it))
|
|
},
|
|
placeholder = {
|
|
Text(text = "Rate")
|
|
},
|
|
)
|
|
*/
|
|
}
|
|
},
|
|
confirmButton = {
|
|
Box(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
contentAlignment = Alignment.Center
|
|
) {
|
|
Button(onClick = {
|
|
onEvent(ExpenseEvent.SaveExpense)
|
|
}) {
|
|
Text(text = "Save")
|
|
}
|
|
}
|
|
}
|
|
)
|
|
} |