make it possible to rename a wallet
sorry for being lazy for some days
This commit is contained in:
parent
88095d1edb
commit
7f9eccba34
2 changed files with 95 additions and 1 deletions
|
@ -111,10 +111,17 @@ fun App(
|
|||
val wallet = walletState
|
||||
|
||||
var actionsVisible by rememberSaveable { mutableStateOf(false) }
|
||||
var renameVisible by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
if (actionsVisible) {
|
||||
ActionsDialog(
|
||||
onDismiss = { actionsVisible = false },
|
||||
onRename = {
|
||||
actionsVisible = false
|
||||
renameVisible = true
|
||||
},
|
||||
onDismiss = {
|
||||
actionsVisible = false
|
||||
},
|
||||
onDelete = {
|
||||
viewModel.delete()
|
||||
finish()
|
||||
|
@ -122,6 +129,18 @@ fun App(
|
|||
)
|
||||
}
|
||||
|
||||
if (renameVisible) {
|
||||
RenameDialog(
|
||||
name = wallet!!.label,
|
||||
onDismiss = { renameVisible = false },
|
||||
onRename = {
|
||||
viewModel.rename(it)
|
||||
wallet.label = it
|
||||
renameVisible = false
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (wallet != null) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
|
@ -288,8 +307,68 @@ fun TransactionDialog(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun RenameDialog(
|
||||
name: String,
|
||||
onDismiss: () -> Unit,
|
||||
onRename: (String) -> Unit
|
||||
) {
|
||||
var value by rememberSaveable { mutableStateOf(name) }
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
focusRequester.requestFocus()
|
||||
}
|
||||
|
||||
Dialog(
|
||||
onDismissRequest = {
|
||||
onDismiss()
|
||||
}
|
||||
) {
|
||||
Card {
|
||||
Column(
|
||||
modifier = Modifier.padding(16.dp)
|
||||
) {
|
||||
Row {
|
||||
TextField(
|
||||
value = value,
|
||||
onValueChange = { value = it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f)
|
||||
.focusRequester(focusRequester),
|
||||
supportingText = { Text("New name") },
|
||||
singleLine = true
|
||||
)
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.End
|
||||
) {
|
||||
TextButton(
|
||||
onClick = {
|
||||
value = name
|
||||
onDismiss()
|
||||
}
|
||||
) {
|
||||
Text(text = "Cancel")
|
||||
}
|
||||
TextButton(
|
||||
onClick = {
|
||||
onRename(value)
|
||||
}
|
||||
) {
|
||||
Text("Rename")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ActionsDialog(
|
||||
onRename: () -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
onDelete: () -> Unit
|
||||
) {
|
||||
|
@ -305,6 +384,9 @@ fun ActionsDialog(
|
|||
Column(
|
||||
modifier = Modifier.padding(16.dp)
|
||||
) {
|
||||
TextButton(onClick = onRename) {
|
||||
Text("Rename wallet")
|
||||
}
|
||||
TextButton(onClick = onDelete) {
|
||||
Text("Delete wallet")
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import eu.m724.coincounter.data.entity.Wallet
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
import kotlin.properties.Delegates
|
||||
|
@ -33,6 +34,17 @@ class WalletViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun rename(label: String) {
|
||||
wallet = wallet.map {
|
||||
it.copy(label = label)
|
||||
}
|
||||
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val wallet = wallet.first()
|
||||
repository.updateWallet(wallet)
|
||||
}
|
||||
}
|
||||
|
||||
fun transact(value: Int, label: String?) {
|
||||
val transaction = Transaction(
|
||||
walletId = walletId,
|
||||
|
|
Loading…
Reference in a new issue