keypad, modify

This commit is contained in:
moon 2026-05-21 11:25:32 +06:30
parent 0f435192ee
commit 72ecfbe4e7
2 changed files with 181 additions and 134 deletions

View File

@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Backspace
import androidx.compose.material.icons.rounded.KeyboardArrowLeft import androidx.compose.material.icons.rounded.KeyboardArrowLeft
import androidx.compose.material3.* import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
@ -28,152 +29,170 @@ fun AmountScreen(
val displayAmount = amount.ifEmpty { "0" } val displayAmount = amount.ifEmpty { "0" }
Column( Box(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.background(Color.IvoryBeige) .background(Color.IvoryBeige)
.padding(horizontal = 20.dp)
.navigationBarsPadding() .navigationBarsPadding()
.statusBarsPadding() .statusBarsPadding()
) { ) {
Box( Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxSize()
.height(56.dp), .padding(horizontal = 20.dp)
contentAlignment = Alignment.Center
) { ) {
IconButton( Box(
onClick = onBackClick, modifier = Modifier
modifier = Modifier.align(Alignment.CenterStart) .fillMaxWidth()
.height(56.dp),
contentAlignment = Alignment.Center
) { ) {
Icon( IconButton(
imageVector = Icons.Rounded.KeyboardArrowLeft, onClick = onBackClick,
contentDescription = "Back", modifier = Modifier.align(Alignment.CenterStart)
tint = Color.LegacyRed ) {
) Icon(
} imageVector = Icons.Rounded.KeyboardArrowLeft,
contentDescription = "Back",
Text( tint = Color.LegacyRed
text = "Amount", )
color = Color.LegacyRed,
fontSize = 14.sp,
fontWeight = FontWeight.Bold
)
}
Spacer(modifier = Modifier.height(36.dp))
Text(
text = "Enter Amount",
color = Color.Gray,
fontSize = 11.sp,
modifier = Modifier.align(Alignment.CenterHorizontally)
)
Spacer(modifier = Modifier.height(8.dp))
Row(
modifier = Modifier.align(Alignment.CenterHorizontally),
verticalAlignment = Alignment.Bottom
) {
Text(
text = "MMK",
color = Color.LegacyRed,
fontSize = 13.sp,
fontWeight = FontWeight.Medium,
modifier = Modifier.padding(end = 10.dp, bottom = 6.dp)
)
Text(
text = formatAmount(displayAmount),
color = Color.LegacyRed,
fontSize = 32.sp,
fontWeight = FontWeight.Bold
)
}
Spacer(modifier = Modifier.height(12.dp))
Text(
text = "Enter the amount to charge",
color = Color.Gray,
fontSize = 11.sp,
modifier = Modifier.align(Alignment.CenterHorizontally)
)
Spacer(modifier = Modifier.height(28.dp))
AmountKeypad(
onNumberClick = { value ->
if (amount.length < 9) {
amount += value
} }
},
onDeleteClick = {
amount = amount.dropLast(1)
}
)
Spacer(modifier = Modifier.weight(1f)) Text(
text = "Amount",
Row( color = Color.LegacyRed,
modifier = Modifier.fillMaxWidth(), fontSize = 14.sp,
horizontalArrangement = Arrangement.spacedBy(12.dp) fontWeight = FontWeight.Bold
) {
Button(
onClick = { },
modifier = Modifier
.weight(1f)
.height(56.dp),
shape = RoundedCornerShape(8.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color.White,
contentColor = Color.LegacyRed
) )
) {
Text("Cancel")
} }
Button( Spacer(modifier = Modifier.height(36.dp))
onClick = {
if (amount.isNotEmpty()) { Text(
onChargeClick(amount) text = "Enter Amount",
} color = Color.Gray,
}, fontSize = 11.sp,
modifier = Modifier modifier = Modifier.align(Alignment.CenterHorizontally)
.weight(1f) )
.height(56.dp),
enabled = amount.isNotEmpty(), Spacer(modifier = Modifier.height(8.dp))
shape = RoundedCornerShape(8.dp),
colors = ButtonDefaults.buttonColors( Row(
containerColor = Color.LegacyRed, modifier = Modifier.align(Alignment.CenterHorizontally),
contentColor = Color.White, verticalAlignment = Alignment.Bottom
disabledContainerColor = Color.LegacyRed.copy(alpha = 0.5f),
disabledContentColor = Color.White
)
) { ) {
Text( Text(
text = "Next", text = "MMK",
fontSize = 14.sp, color = Color.LegacyRed,
fontWeight = FontWeight.Medium fontSize = 13.sp,
fontWeight = FontWeight.Medium,
modifier = Modifier.padding(end = 10.dp, bottom = 6.dp)
)
Text(
text = formatAmount(displayAmount),
color = Color.LegacyRed,
fontSize = 32.sp,
fontWeight = FontWeight.Bold
) )
} }
Spacer(modifier = Modifier.height(12.dp))
Text(
text = "Enter the amount to charge",
color = Color.Gray,
fontSize = 11.sp,
modifier = Modifier.align(Alignment.CenterHorizontally)
)
Spacer(modifier = Modifier.height(28.dp))
AmountKeypad(
onNumberClick = { value ->
amount = appendAmountValue(amount, value)
}
)
Spacer(modifier = Modifier.weight(1f))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
Button(
onClick = { },
modifier = Modifier
.weight(1f)
.height(56.dp),
shape = RoundedCornerShape(8.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color.White,
contentColor = Color.LegacyRed
)
) {
Text("Cancel")
}
Button(
onClick = {
if (amount.isNotEmpty()) {
onChargeClick(amount)
}
},
modifier = Modifier
.weight(1f)
.height(56.dp),
enabled = amount.isNotEmpty(),
shape = RoundedCornerShape(8.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color.LegacyRed,
contentColor = Color.White,
disabledContainerColor = Color.LegacyRed.copy(alpha = 0.5f),
disabledContentColor = Color.White
)
) {
Text(
text = "Next",
fontSize = 14.sp,
fontWeight = FontWeight.Medium
)
}
}
Spacer(modifier = Modifier.height(18.dp))
} }
Spacer(modifier = Modifier.height(18.dp)) Card(
modifier = Modifier
.align(Alignment.TopEnd)//?
.padding(top = 110.dp, end = 20.dp)
.clickable(enabled = amount.isNotEmpty()) {
amount = amount.dropLast(1)
},
shape = RoundedCornerShape(18.dp),
colors = CardDefaults.cardColors(containerColor = Color.White),
elevation = CardDefaults.cardElevation(defaultElevation = 6.dp)
) {
Icon(
imageVector = Icons.Rounded.Backspace,
contentDescription = "Delete",
tint = if (amount.isNotEmpty()) Color.LegacyRed else Color.Gray,
modifier = Modifier.padding(horizontal = 14.dp, vertical = 12.dp)
)
}
} }
} }
@Composable @Composable
private fun AmountKeypad( private fun AmountKeypad(
onNumberClick: (String) -> Unit, onNumberClick: (String) -> Unit
onDeleteClick: () -> Unit
) { ) {
val keys = listOf( val keys = listOf(
listOf("1", "2", "3"), listOf("1", "2", "3"),
listOf("4", "5", "6"), listOf("4", "5", "6"),
listOf("7", "8", "9"), listOf("7", "8", "9"),
listOf("", "0", "00") listOf(".", "0", "00")
) )
Column( Column(
@ -186,19 +205,11 @@ private fun AmountKeypad(
horizontalArrangement = Arrangement.spacedBy(6.dp) horizontalArrangement = Arrangement.spacedBy(6.dp)
) { ) {
row.forEach { key -> row.forEach { key ->
if (key.isEmpty()) { KeypadButton(
Box( text = key,
modifier = Modifier modifier = Modifier.weight(1f),
.weight(1f) onClick = { onNumberClick(key) }
.height(66.dp) )
)
} else {
KeypadButton(
text = key,
modifier = Modifier.weight(1f),
onClick = { onNumberClick(key) }
)
}
} }
} }
} }
@ -237,8 +248,46 @@ private fun KeypadButton(
} }
private fun formatAmount(value: String): String { private fun formatAmount(value: String): String {
val number = value.toLongOrNull() ?: 0L val normalized = value.ifEmpty { "0" }
return "%,d".format(number) val wholePart = normalized.substringBefore(".").ifEmpty { "0" }
val groupedWholePart = "%,d".format(wholePart.toLongOrNull() ?: 0L)
if (!normalized.contains(".")) {
return groupedWholePart
}
val decimalPart = normalized.substringAfter(".", "")
return if (normalized.endsWith(".")) {
"$groupedWholePart."
} else {
"$groupedWholePart.$decimalPart"
}
}
private fun appendAmountValue(current: String, value: String): String {
if (value == ".") {
if (current.contains(".")) return current
return if (current.isEmpty()) "0." else "$current."
}
val decimalIndex = current.indexOf('.')
return if (decimalIndex >= 0) {
val decimalPart = current.substring(decimalIndex + 1)
val remainingDecimalDigits = 2 - decimalPart.length
if (remainingDecimalDigits <= 0) {
current
} else {
current + value.take(remainingDecimalDigits)
}
} else {
val wholeDigitsCount = current.filter(Char::isDigit).length
val remainingWholeDigits = 9 - wholeDigitsCount
if (remainingWholeDigits <= 0) {
current
} else {
current + value.take(remainingWholeDigits)
}
}
} }
@P2Preview @P2Preview

View File

@ -61,10 +61,8 @@ fun DashboardScreen2(
private fun AdvertisingArea() { private fun AdvertisingArea() {
Card( Card(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(0.dp), shape = RoundedCornerShape(0.dp),
colors = CardDefaults.cardColors(containerColor = Color.White), colors = CardDefaults.cardColors(containerColor = Color.White),
elevation = CardDefaults.cardElevation(8.dp)
) { ) {
Row( Row(
modifier = Modifier.height(170.dp) ) { modifier = Modifier.height(170.dp) ) {