Compare commits
4 Commits
10f5bcf355
...
72ecfbe4e7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72ecfbe4e7 | ||
|
|
0f435192ee | ||
|
|
fe6c5ad15e | ||
|
|
f4fc2fa730 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@
|
|||||||
.cxx
|
.cxx
|
||||||
local.properties
|
local.properties
|
||||||
/.idea
|
/.idea
|
||||||
|
/.idea
|
||||||
|
|||||||
@ -57,5 +57,6 @@
|
|||||||
<option name="composableFile" value="true" />
|
<option name="composableFile" value="true" />
|
||||||
<option name="previewFile" value="true" />
|
<option name="previewFile" value="true" />
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
|
<inspection_tool class="UsePropertyAccessSyntax" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||||
</profile>
|
</profile>
|
||||||
</component>
|
</component>
|
||||||
@ -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,13 +29,17 @@ 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()
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(horizontal = 20.dp)
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -105,12 +110,7 @@ fun AmountScreen(
|
|||||||
|
|
||||||
AmountKeypad(
|
AmountKeypad(
|
||||||
onNumberClick = { value ->
|
onNumberClick = { value ->
|
||||||
if (amount.length < 9) {
|
amount = appendAmountValue(amount, value)
|
||||||
amount += value
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onDeleteClick = {
|
|
||||||
amount = amount.dropLast(1)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -162,18 +162,37 @@ fun AmountScreen(
|
|||||||
|
|
||||||
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,13 +205,6 @@ private fun AmountKeypad(
|
|||||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||||
) {
|
) {
|
||||||
row.forEach { key ->
|
row.forEach { key ->
|
||||||
if (key.isEmpty()) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.height(66.dp)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
KeypadButton(
|
KeypadButton(
|
||||||
text = key,
|
text = key,
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
@ -202,7 +214,6 @@ private fun AmountKeypad(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -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
|
||||||
|
|||||||
@ -25,7 +25,8 @@ import com.mob.utsmyanmar.ui.theme.Color
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DashboardScreen2(
|
fun DashboardScreen2(
|
||||||
onNavigateAmount: (String) -> Unit = {}
|
onNavigateAmount: (String) -> Unit = {},
|
||||||
|
onNavigateSignOn: () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
Scaffold(
|
Scaffold(
|
||||||
containerColor = Color.IvoryBeige,
|
containerColor = Color.IvoryBeige,
|
||||||
@ -44,7 +45,10 @@ fun DashboardScreen2(
|
|||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
SummaryCard()
|
SummaryCard()
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
MenuGrid(onNavigateAmount = onNavigateAmount)
|
MenuGrid(
|
||||||
|
onNavigateAmount = onNavigateAmount,
|
||||||
|
onNavigateSignOn = onNavigateSignOn
|
||||||
|
)
|
||||||
Spacer(modifier = Modifier.height(18.dp))
|
Spacer(modifier = Modifier.height(18.dp))
|
||||||
// RecentTransactionHeader()
|
// RecentTransactionHeader()
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
@ -57,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) ) {
|
||||||
@ -164,7 +166,8 @@ private fun SummaryItem(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun MenuGrid(
|
private fun MenuGrid(
|
||||||
onNavigateAmount: (String) -> Unit
|
onNavigateAmount: (String) -> Unit,
|
||||||
|
onNavigateSignOn: () -> Unit
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
verticalArrangement = Arrangement.spacedBy(10.dp)
|
verticalArrangement = Arrangement.spacedBy(10.dp)
|
||||||
@ -181,7 +184,12 @@ private fun MenuGrid(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
MenuCard("Sign On", Icons.Default.Link, Modifier.weight(1f))
|
MenuCard(
|
||||||
|
"Sign On",
|
||||||
|
Icons.Default.Link,
|
||||||
|
Modifier.weight(1f),
|
||||||
|
onClick = onNavigateSignOn
|
||||||
|
)
|
||||||
MenuCard("Settlement", Icons.Default.Wallet, Modifier.weight(1f))
|
MenuCard("Settlement", Icons.Default.Wallet, Modifier.weight(1f))
|
||||||
MenuCard("See More", Icons.Default.GridView, Modifier.weight(1f))
|
MenuCard("See More", Icons.Default.GridView, Modifier.weight(1f))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,9 @@ import com.mob.utsmyanmar.ui.pinpad.PinPadRoute
|
|||||||
import com.mob.utsmyanmar.ui.processing_card.ProcessingCardRoute
|
import com.mob.utsmyanmar.ui.processing_card.ProcessingCardRoute
|
||||||
import com.mob.utsmyanmar.ui.processing_card.ProcessingCardViewModel
|
import com.mob.utsmyanmar.ui.processing_card.ProcessingCardViewModel
|
||||||
import com.mob.utsmyanmar.ui.print_receipt.PrintReceiptScreen
|
import com.mob.utsmyanmar.ui.print_receipt.PrintReceiptScreen
|
||||||
|
import com.mob.utsmyanmar.ui.sign_on.SignOnResultScreen
|
||||||
|
import com.mob.utsmyanmar.ui.sign_on.SignOnRoute
|
||||||
|
import com.mob.utsmyanmar.ui.sending_to_host.SendingToHostRoute
|
||||||
import com.mob.utsmyanmar.ui.transaction_result.TransactionResultRoute
|
import com.mob.utsmyanmar.ui.transaction_result.TransactionResultRoute
|
||||||
import com.mob.utsmyanmar.viewmodel.CardReaderViewModel
|
import com.mob.utsmyanmar.viewmodel.CardReaderViewModel
|
||||||
import com.mob.utsmyanmar.viewmodel.EmvTransactionProcessViewModel
|
import com.mob.utsmyanmar.viewmodel.EmvTransactionProcessViewModel
|
||||||
@ -46,6 +49,62 @@ fun AppNavGraph(
|
|||||||
}
|
}
|
||||||
launchSingleTop = true
|
launchSingleTop = true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onNavigateSignOn = {
|
||||||
|
navController.navigate(Routes.SignOn.route) {
|
||||||
|
launchSingleTop = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(Routes.SignOn.route) {
|
||||||
|
SignOnRoute(
|
||||||
|
onBack = { navController.popBackStack() },
|
||||||
|
onNavigateResult = { isSuccess, message ->
|
||||||
|
navController.navigate(Routes.SignOnResult.createRoute(isSuccess, message)) {
|
||||||
|
popUpTo(Routes.SignOn.route) {
|
||||||
|
inclusive = true
|
||||||
|
}
|
||||||
|
launchSingleTop = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = Routes.SignOnResult.route,
|
||||||
|
arguments = listOf(
|
||||||
|
navArgument("isSuccess") {
|
||||||
|
type = NavType.BoolType
|
||||||
|
},
|
||||||
|
navArgument("message") {
|
||||||
|
type = NavType.StringType
|
||||||
|
}
|
||||||
|
)
|
||||||
|
) { backStackEntry ->
|
||||||
|
val isSuccess = backStackEntry.arguments?.getBoolean("isSuccess") ?: false
|
||||||
|
val message = backStackEntry.arguments?.getString("message").orEmpty()
|
||||||
|
|
||||||
|
SignOnResultScreen(
|
||||||
|
isSuccess = isSuccess,
|
||||||
|
message = message,
|
||||||
|
onBack = { navController.popBackStack() },
|
||||||
|
onDone = {
|
||||||
|
navController.navigate(Routes.Dashboard.route) {
|
||||||
|
popUpTo(Routes.Dashboard.route) {
|
||||||
|
inclusive = false
|
||||||
|
}
|
||||||
|
launchSingleTop = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onRetry = {
|
||||||
|
navController.navigate(Routes.SignOn.route) {
|
||||||
|
popUpTo(Routes.SignOnResult.route) {
|
||||||
|
inclusive = true
|
||||||
|
}
|
||||||
|
launchSingleTop = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -153,8 +212,8 @@ fun AppNavGraph(
|
|||||||
pinPadViewModel = pinPadViewModel,
|
pinPadViewModel = pinPadViewModel,
|
||||||
sharedViewModel = sharedViewModel,
|
sharedViewModel = sharedViewModel,
|
||||||
transProcessViewModel = transProcessViewModel,
|
transProcessViewModel = transProcessViewModel,
|
||||||
onNavigateTransactionResult = {
|
onNavigateSendingToHost = {
|
||||||
navController.navigate(Routes.TransactionResult.route) {
|
navController.navigate(Routes.SendingToHost.route) {
|
||||||
popUpTo(Routes.PinPad.route) {
|
popUpTo(Routes.PinPad.route) {
|
||||||
inclusive = true
|
inclusive = true
|
||||||
}
|
}
|
||||||
@ -165,6 +224,19 @@ fun AppNavGraph(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
composable(Routes.SendingToHost.route) {
|
||||||
|
SendingToHostRoute(
|
||||||
|
onNavigateTransactionResult = {
|
||||||
|
navController.navigate(Routes.TransactionResult.route) {
|
||||||
|
popUpTo(Routes.SendingToHost.route) {
|
||||||
|
inclusive = true
|
||||||
|
}
|
||||||
|
launchSingleTop = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
composable(Routes.TransactionResult.route) {
|
composable(Routes.TransactionResult.route) {
|
||||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,22 @@
|
|||||||
package com.mob.utsmyanmar.ui.navigation
|
package com.mob.utsmyanmar.ui.navigation
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
|
||||||
sealed class Routes(val route: String) {
|
sealed class Routes(val route: String) {
|
||||||
data object Dashboard : Routes("dashboard")
|
data object Dashboard : Routes("dashboard")
|
||||||
data object Amount : Routes("amount/{action}") {
|
data object Amount : Routes("amount/{action}") {
|
||||||
fun createRoute(action: String): String = "amount/$action"
|
fun createRoute(action: String): String = "amount/$action"
|
||||||
}
|
}
|
||||||
|
data object SignOn : Routes("sign_on")
|
||||||
|
data object SignOnResult : Routes("sign_on_result/{isSuccess}/{message}") {
|
||||||
|
fun createRoute(isSuccess: Boolean, message: String): String {
|
||||||
|
return "sign_on_result/$isSuccess/${Uri.encode(message)}"
|
||||||
|
}
|
||||||
|
}
|
||||||
data object CardWaiting : Routes("card_waiting")
|
data object CardWaiting : Routes("card_waiting")
|
||||||
data object ProcessingCard : Routes("processing_card")
|
data object ProcessingCard : Routes("processing_card")
|
||||||
data object PinPad : Routes("pin_pad")
|
data object PinPad : Routes("pin_pad")
|
||||||
|
data object SendingToHost : Routes("sending_to_host")
|
||||||
data object TransactionResult : Routes("transaction_result")
|
data object TransactionResult : Routes("transaction_result")
|
||||||
data object PrintReceipt : Routes("print_receipt")
|
data object PrintReceipt : Routes("print_receipt")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ fun PinPadRoute(
|
|||||||
pinPadViewModel: PinPadViewModel,
|
pinPadViewModel: PinPadViewModel,
|
||||||
sharedViewModel: SharedViewModel,
|
sharedViewModel: SharedViewModel,
|
||||||
transProcessViewModel: TransProcessViewModel,
|
transProcessViewModel: TransProcessViewModel,
|
||||||
onNavigateTransactionResult: () -> Unit,
|
onNavigateSendingToHost: () -> Unit,
|
||||||
onBack: () -> Unit
|
onBack: () -> Unit
|
||||||
) {
|
) {
|
||||||
val pinText by pinPadViewModel.pinText.collectAsStateWithLifecycle()
|
val pinText by pinPadViewModel.pinText.collectAsStateWithLifecycle()
|
||||||
@ -37,7 +37,7 @@ fun PinPadRoute(
|
|||||||
payDetail?.tradeAnswerCode = Constant.ANSWER_CODE_APPROVED
|
payDetail?.tradeAnswerCode = Constant.ANSWER_CODE_APPROVED
|
||||||
sharedViewModel.payDetail.value = payDetail
|
sharedViewModel.payDetail.value = payDetail
|
||||||
transProcessViewModel.resetTransactionStatus()
|
transProcessViewModel.resetTransactionStatus()
|
||||||
onNavigateTransactionResult()
|
onNavigateSendingToHost()
|
||||||
}
|
}
|
||||||
|
|
||||||
PinPadStatus.ON_CANCEL,
|
PinPadStatus.ON_CANCEL,
|
||||||
|
|||||||
@ -2,6 +2,9 @@ package com.mob.utsmyanmar.ui.print_receipt
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
|
import androidx.compose.animation.core.Animatable
|
||||||
|
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||||
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
@ -15,40 +18,47 @@ import androidx.compose.material3.OutlinedButton
|
|||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||||
import com.mob.utsmyanmar.ui.theme.Primary
|
import com.mob.utsmyanmar.ui.theme.Color
|
||||||
import com.mob.utsmyanmar.ui.theme.White
|
import com.utsmyanmar.paylibs.print.PrintReceipt
|
||||||
import com.utsmyanmar.paylibs.print.NewPrintReceipt
|
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PrintReceiptScreen(
|
fun PrintReceiptScreen(
|
||||||
onPrint: () -> Unit,
|
onPrint: () -> Unit,
|
||||||
onDone: () -> Unit
|
onDone: () -> Unit
|
||||||
) {
|
) {
|
||||||
BackHandler {
|
|
||||||
onDone()
|
val scope = rememberCoroutineScope();
|
||||||
|
val receiptOffsetY = remember {
|
||||||
|
Animatable(0f);
|
||||||
}
|
}
|
||||||
|
val animationDuration = 3000;
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
AppBar(title = "Receipt")
|
AppBar(title = "Receipt")
|
||||||
}
|
},
|
||||||
|
containerColor = Color.IvoryBeige
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(paddingValues)
|
.padding(paddingValues)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.background(Color(0xFFF5F5F5))
|
|
||||||
.padding(16.dp),
|
.padding(16.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
) {
|
) {
|
||||||
@ -57,6 +67,9 @@ fun PrintReceiptScreen(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.verticalScroll(rememberScrollState())
|
.verticalScroll(rememberScrollState())
|
||||||
|
.graphicsLayer{
|
||||||
|
translationY = receiptOffsetY.value
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
@ -87,18 +100,41 @@ fun PrintReceiptScreen(
|
|||||||
.weight(1f)
|
.weight(1f)
|
||||||
.height(50.dp),
|
.height(50.dp),
|
||||||
colors = ButtonDefaults.buttonColors(
|
colors = ButtonDefaults.buttonColors(
|
||||||
containerColor = Primary,
|
containerColor = Color.LegacyRed,
|
||||||
contentColor = White,
|
contentColor = Color.White,
|
||||||
disabledContainerColor = Primary,
|
disabledContainerColor = Color.LegacyRed.copy(alpha = 0.5f),
|
||||||
disabledContentColor = White,
|
disabledContentColor = Color.White.copy(alpha = 0.5f),
|
||||||
),
|
),
|
||||||
shape = RoundedCornerShape(12.dp),
|
shape = RoundedCornerShape(12.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
onPrint()
|
// onPrint()
|
||||||
try {
|
try {
|
||||||
NewPrintReceipt.getInstance().testPrint()
|
PrintReceipt.getInstance().printNow()
|
||||||
|
scope.launch {
|
||||||
|
launch {
|
||||||
|
receiptOffsetY.animateTo(
|
||||||
|
targetValue = -1500f,
|
||||||
|
animationSpec = tween(
|
||||||
|
durationMillis = animationDuration,
|
||||||
|
easing = FastOutSlowInEasing
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
delay(5000)
|
||||||
|
launch {
|
||||||
|
receiptOffsetY.animateTo(
|
||||||
|
targetValue = 0f,
|
||||||
|
animationSpec = tween(
|
||||||
|
durationMillis = 0,
|
||||||
|
easing = FastOutSlowInEasing
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
||||||
Log.d("PrintReceipt", "error with $e")
|
Log.d("PrintReceipt", "error with $e")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
@ -116,6 +152,7 @@ fun PrintReceiptScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ReceiptPreview(
|
fun ReceiptPreview(
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
@ -127,32 +164,26 @@ fun ReceiptPreview(
|
|||||||
.background(Color.White)
|
.background(Color.White)
|
||||||
.border(
|
.border(
|
||||||
width = 1.dp,
|
width = 1.dp,
|
||||||
color = Color.LightGray,
|
color = Color.Gray,
|
||||||
shape = RoundedCornerShape(12.dp)
|
shape = RoundedCornerShape(12.dp)
|
||||||
)
|
)
|
||||||
.padding(20.dp),
|
.padding(20.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = "MOB POS",
|
text = "MOB POS",
|
||||||
fontSize = 24.sp,
|
fontSize = 24.sp,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
fontFamily = FontFamily.Monospace
|
fontFamily = FontFamily.Monospace
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = "Transaction Receipt",
|
text = "Transaction Receipt",
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
fontFamily = FontFamily.Monospace
|
fontFamily = FontFamily.Monospace
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
ReceiptDivider()
|
ReceiptDivider()
|
||||||
|
|
||||||
ReceiptRow("Merchant", "MOB UTS Myanmar")
|
ReceiptRow("Merchant", "MOB UTS Myanmar")
|
||||||
ReceiptRow("Terminal ID", "POS001")
|
ReceiptRow("Terminal ID", "POS001")
|
||||||
ReceiptRow("Transaction", "SALE")
|
ReceiptRow("Transaction", "SALE")
|
||||||
@ -163,11 +194,8 @@ fun ReceiptPreview(
|
|||||||
ReceiptRow("Date", "13/05/2026")
|
ReceiptRow("Date", "13/05/2026")
|
||||||
ReceiptRow("Time", "14:30:22")
|
ReceiptRow("Time", "14:30:22")
|
||||||
ReceiptRow("Ref No", "REF123456789")
|
ReceiptRow("Ref No", "REF123456789")
|
||||||
|
|
||||||
ReceiptDivider()
|
ReceiptDivider()
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = "Thank You",
|
text = "Thank You",
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
@ -200,7 +228,7 @@ fun ReceiptRow(
|
|||||||
text = label,
|
text = label,
|
||||||
fontSize = 13.sp,
|
fontSize = 13.sp,
|
||||||
fontFamily = FontFamily.Monospace,
|
fontFamily = FontFamily.Monospace,
|
||||||
color = Color.DarkGray
|
color = Color.Gray
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
@ -0,0 +1,19 @@
|
|||||||
|
package com.mob.utsmyanmar.ui.sending_to_host
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
|
private const val MOCK_HOST_DELAY_MS = 2000L
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SendingToHostRoute(
|
||||||
|
onNavigateTransactionResult: () -> Unit
|
||||||
|
) {
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
delay(MOCK_HOST_DELAY_MS)
|
||||||
|
onNavigateTransactionResult()
|
||||||
|
}
|
||||||
|
|
||||||
|
SendingToHostScreen()
|
||||||
|
}
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
package com.mob.utsmyanmar.ui.sending_to_host
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
import com.mob.utsmyanmar.ui.theme.Black
|
||||||
|
import com.mob.utsmyanmar.ui.theme.Primary
|
||||||
|
import com.mob.utsmyanmar.ui.theme.White
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SendingToHostScreen() {
|
||||||
|
Scaffold(
|
||||||
|
containerColor = White
|
||||||
|
) { paddingValues ->
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(paddingValues)
|
||||||
|
.background(White)
|
||||||
|
.padding(horizontal = 24.dp, vertical = 32.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(
|
||||||
|
color = Primary,
|
||||||
|
shape = RoundedCornerShape(24.dp)
|
||||||
|
)
|
||||||
|
.padding(horizontal = 24.dp, vertical = 32.dp),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator(color = White)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(20.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = "Sending Data",
|
||||||
|
color = White,
|
||||||
|
fontSize = 24.sp,
|
||||||
|
fontWeight = FontWeight.Bold
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(10.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = "Please wait while we send transaction data to host.",
|
||||||
|
color = White,
|
||||||
|
fontSize = 15.sp,
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = "Mock host communication in progress.",
|
||||||
|
color = Black,
|
||||||
|
fontSize = 14.sp,
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
262
app/src/main/java/com/mob/utsmyanmar/ui/sign_on/SignOnScreen.kt
Normal file
262
app/src/main/java/com/mob/utsmyanmar/ui/sign_on/SignOnScreen.kt
Normal file
@ -0,0 +1,262 @@
|
|||||||
|
package com.mob.utsmyanmar.ui.sign_on
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.filled.CheckCircle
|
||||||
|
import androidx.compose.material.icons.filled.ErrorOutline
|
||||||
|
import androidx.compose.material.icons.filled.Sync
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedButton
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||||
|
import com.mob.utsmyanmar.ui.theme.Color as AppColor
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SignOnRoute(
|
||||||
|
onBack: () -> Unit,
|
||||||
|
onNavigateResult: (Boolean, String) -> Unit,
|
||||||
|
viewModel: SignOnViewModel = viewModel()
|
||||||
|
) {
|
||||||
|
val state by viewModel.uiState.collectAsState()
|
||||||
|
|
||||||
|
LaunchedEffect(viewModel) {
|
||||||
|
viewModel.resultEvents.collect { result ->
|
||||||
|
onNavigateResult(result.isSuccess, result.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SignOnScreen(
|
||||||
|
state = state,
|
||||||
|
onBack = onBack,
|
||||||
|
onStartSignOn = viewModel::startSignOn
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SignOnScreen(
|
||||||
|
state: SignOnUiState,
|
||||||
|
onBack: () -> Unit,
|
||||||
|
onStartSignOn: () -> Unit
|
||||||
|
) {
|
||||||
|
Scaffold(
|
||||||
|
containerColor = AppColor.IvoryBeige,
|
||||||
|
topBar = {
|
||||||
|
AppBar(
|
||||||
|
title = "Sign On",
|
||||||
|
icon = Icons.Default.ArrowBack,
|
||||||
|
onIconClick = onBack
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) { paddingValues ->
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(paddingValues)
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
shape = RoundedCornerShape(20.dp),
|
||||||
|
colors = CardDefaults.cardColors(containerColor = AppColor.White),
|
||||||
|
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(20.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Sync,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = AppColor.LegacyRed,
|
||||||
|
modifier = Modifier.height(42.dp)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "Host Sign On",
|
||||||
|
fontSize = 22.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = AppColor.LegacyRed
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "Run sign on and verify immediately whether the host accepted or rejected the terminal.",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = AppColor.Gray
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
shape = RoundedCornerShape(20.dp),
|
||||||
|
colors = CardDefaults.cardColors(containerColor = AppColor.White)
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(20.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "Current Status",
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
color = AppColor.Black
|
||||||
|
)
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(
|
||||||
|
color = if (state.isLoading) AppColor.GoldenGlow.copy(alpha = 0.18f) else AppColor.SkylineBlue.copy(alpha = 0.12f),
|
||||||
|
shape = RoundedCornerShape(16.dp)
|
||||||
|
)
|
||||||
|
.padding(16.dp)
|
||||||
|
) {
|
||||||
|
if (state.isLoading) {
|
||||||
|
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||||
|
CircularProgressIndicator(color = AppColor.LegacyRed)
|
||||||
|
Text(text = state.statusText, color = AppColor.Black)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Text(text = state.statusText, color = AppColor.Black)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Button(
|
||||||
|
onClick = onStartSignOn,
|
||||||
|
enabled = !state.isLoading,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = ButtonDefaults.buttonColors(
|
||||||
|
containerColor = AppColor.CrimsonRed,
|
||||||
|
disabledContainerColor = AppColor.Gray
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Text(text = if (state.isLoading) "Processing..." else "Start Sign On")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.canRetry) {
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = onStartSignOn,
|
||||||
|
enabled = !state.isLoading,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Text(text = "Retry")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SignOnResultScreen(
|
||||||
|
isSuccess: Boolean,
|
||||||
|
message: String,
|
||||||
|
onBack: () -> Unit,
|
||||||
|
onDone: () -> Unit,
|
||||||
|
onRetry: () -> Unit
|
||||||
|
) {
|
||||||
|
val accent = if (isSuccess) AppColor.Success else AppColor.LegacyRed
|
||||||
|
val background = if (isSuccess) AppColor.Success.copy(alpha = 0.12f) else AppColor.CrimsonRed.copy(alpha = 0.12f)
|
||||||
|
|
||||||
|
Scaffold(
|
||||||
|
containerColor = AppColor.IvoryBeige,
|
||||||
|
topBar = {
|
||||||
|
AppBar(
|
||||||
|
title = "Sign On Result",
|
||||||
|
icon = Icons.Default.ArrowBack,
|
||||||
|
onIconClick = onBack
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) { paddingValues ->
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(paddingValues)
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
shape = RoundedCornerShape(24.dp),
|
||||||
|
colors = CardDefaults.cardColors(containerColor = AppColor.White)
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(24.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.background(background, RoundedCornerShape(50))
|
||||||
|
.padding(18.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = if (isSuccess) Icons.Default.CheckCircle else Icons.Default.ErrorOutline,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = accent
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = if (isSuccess) "Sign On Success" else "Sign On Failed",
|
||||||
|
fontSize = 24.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = accent
|
||||||
|
)
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = message,
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
color = Color.Black
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
|
||||||
|
if (!isSuccess) {
|
||||||
|
Button(
|
||||||
|
onClick = onRetry,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = ButtonDefaults.buttonColors(containerColor = AppColor.CrimsonRed)
|
||||||
|
) {
|
||||||
|
Text(text = "Try Again")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = onDone,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Text(text = "Back To Dashboard")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,90 @@
|
|||||||
|
package com.mob.utsmyanmar.ui.sign_on
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import com.utsmyanmar.paylibs.sign_on.SignOnListener
|
||||||
|
import com.utsmyanmar.paylibs.sign_on.SignOnProcess
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
data class SignOnUiState(
|
||||||
|
val isLoading: Boolean = false,
|
||||||
|
val statusText: String = "Ready to start sign on.",
|
||||||
|
val canRetry: Boolean = false
|
||||||
|
)
|
||||||
|
|
||||||
|
data class SignOnResult(
|
||||||
|
val isSuccess: Boolean,
|
||||||
|
val message: String
|
||||||
|
)
|
||||||
|
|
||||||
|
class SignOnViewModel : ViewModel() {
|
||||||
|
|
||||||
|
private val _uiState = MutableStateFlow(SignOnUiState())
|
||||||
|
val uiState: StateFlow<SignOnUiState> = _uiState.asStateFlow()
|
||||||
|
|
||||||
|
private val _resultEvents = MutableSharedFlow<SignOnResult>()
|
||||||
|
val resultEvents: SharedFlow<SignOnResult> = _resultEvents.asSharedFlow()
|
||||||
|
|
||||||
|
fun startSignOn() {
|
||||||
|
if (_uiState.value.isLoading) return
|
||||||
|
|
||||||
|
_uiState.update {
|
||||||
|
it.copy(
|
||||||
|
isLoading = true,
|
||||||
|
statusText = "Signing on to host...",
|
||||||
|
canRetry = false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// SignOnProcess.getInstance()
|
||||||
|
// .enqueue()
|
||||||
|
// .startSignOn(object : SignOnListener {
|
||||||
|
// override fun onSuccessSignOn() {
|
||||||
|
// dispatchResult(
|
||||||
|
// SignOnResult(
|
||||||
|
// isSuccess = true,
|
||||||
|
// message = "Sign on completed successfully."
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override fun onFailureSignOn(resultCode: Integer?) {
|
||||||
|
// dispatchResult(
|
||||||
|
// SignOnResult(
|
||||||
|
// isSuccess = false,
|
||||||
|
// message = "Sign on failed. Response code: ${resultCode ?: -1}"
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override fun onNetworkFailSignOn(message: String?) {
|
||||||
|
// dispatchResult(
|
||||||
|
// SignOnResult(
|
||||||
|
// isSuccess = false,
|
||||||
|
// message = message?.takeIf { it.isNotBlank() } ?: "Network error during sign on."
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun dispatchResult(result: SignOnResult) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
_uiState.update {
|
||||||
|
it.copy(
|
||||||
|
isLoading = false,
|
||||||
|
statusText = result.message,
|
||||||
|
canRetry = !result.isSuccess
|
||||||
|
)
|
||||||
|
}
|
||||||
|
_resultEvents.emit(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user