Compare commits
No commits in common. "72ecfbe4e7fcf5634d66f1ea7b848c2680e38ec1" and "10f5bcf355cd437dbeaa2e9050f40a4b59cc476b" have entirely different histories.
72ecfbe4e7
...
10f5bcf355
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,4 +14,3 @@
|
|||||||
.cxx
|
.cxx
|
||||||
local.properties
|
local.properties
|
||||||
/.idea
|
/.idea
|
||||||
/.idea
|
|
||||||
|
|||||||
@ -57,6 +57,5 @@
|
|||||||
<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,7 +6,6 @@ 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.*
|
||||||
@ -29,17 +28,13 @@ fun AmountScreen(
|
|||||||
|
|
||||||
val displayAmount = amount.ifEmpty { "0" }
|
val displayAmount = amount.ifEmpty { "0" }
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(Color.IvoryBeige)
|
|
||||||
.navigationBarsPadding()
|
|
||||||
.statusBarsPadding()
|
|
||||||
) {
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
.background(Color.IvoryBeige)
|
||||||
.padding(horizontal = 20.dp)
|
.padding(horizontal = 20.dp)
|
||||||
|
.navigationBarsPadding()
|
||||||
|
.statusBarsPadding()
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -110,7 +105,12 @@ fun AmountScreen(
|
|||||||
|
|
||||||
AmountKeypad(
|
AmountKeypad(
|
||||||
onNumberClick = { value ->
|
onNumberClick = { value ->
|
||||||
amount = appendAmountValue(amount, value)
|
if (amount.length < 9) {
|
||||||
|
amount += value
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onDeleteClick = {
|
||||||
|
amount = amount.dropLast(1)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -162,37 +162,18 @@ 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(
|
||||||
@ -205,6 +186,13 @@ 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),
|
||||||
@ -214,6 +202,7 @@ private fun AmountKeypad(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -248,46 +237,8 @@ private fun KeypadButton(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun formatAmount(value: String): String {
|
private fun formatAmount(value: String): String {
|
||||||
val normalized = value.ifEmpty { "0" }
|
val number = value.toLongOrNull() ?: 0L
|
||||||
val wholePart = normalized.substringBefore(".").ifEmpty { "0" }
|
return "%,d".format(number)
|
||||||
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,8 +25,7 @@ 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,
|
||||||
@ -45,10 +44,7 @@ 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(
|
MenuGrid(onNavigateAmount = onNavigateAmount)
|
||||||
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))
|
||||||
@ -61,8 +57,10 @@ 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) ) {
|
||||||
@ -166,8 +164,7 @@ 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)
|
||||||
@ -184,12 +181,7 @@ private fun MenuGrid(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
MenuCard(
|
MenuCard("Sign On", Icons.Default.Link, Modifier.weight(1f))
|
||||||
"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,9 +19,6 @@ 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
|
||||||
@ -49,62 +46,6 @@ 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -212,8 +153,8 @@ fun AppNavGraph(
|
|||||||
pinPadViewModel = pinPadViewModel,
|
pinPadViewModel = pinPadViewModel,
|
||||||
sharedViewModel = sharedViewModel,
|
sharedViewModel = sharedViewModel,
|
||||||
transProcessViewModel = transProcessViewModel,
|
transProcessViewModel = transProcessViewModel,
|
||||||
onNavigateSendingToHost = {
|
onNavigateTransactionResult = {
|
||||||
navController.navigate(Routes.SendingToHost.route) {
|
navController.navigate(Routes.TransactionResult.route) {
|
||||||
popUpTo(Routes.PinPad.route) {
|
popUpTo(Routes.PinPad.route) {
|
||||||
inclusive = true
|
inclusive = true
|
||||||
}
|
}
|
||||||
@ -224,19 +165,6 @@ 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,22 +1,13 @@
|
|||||||
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,
|
||||||
onNavigateSendingToHost: () -> Unit,
|
onNavigateTransactionResult: () -> 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()
|
||||||
onNavigateSendingToHost()
|
onNavigateTransactionResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
PinPadStatus.ON_CANCEL,
|
PinPadStatus.ON_CANCEL,
|
||||||
|
|||||||
@ -2,9 +2,6 @@ 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.*
|
||||||
@ -18,47 +15,40 @@ 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.graphicsLayer
|
import androidx.compose.ui.graphics.Color
|
||||||
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.Color
|
import com.mob.utsmyanmar.ui.theme.Primary
|
||||||
import com.utsmyanmar.paylibs.print.PrintReceipt
|
import com.mob.utsmyanmar.ui.theme.White
|
||||||
|
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 {
|
||||||
val scope = rememberCoroutineScope();
|
onDone()
|
||||||
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,
|
||||||
) {
|
) {
|
||||||
@ -67,9 +57,6 @@ 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))
|
||||||
@ -100,41 +87,18 @@ fun PrintReceiptScreen(
|
|||||||
.weight(1f)
|
.weight(1f)
|
||||||
.height(50.dp),
|
.height(50.dp),
|
||||||
colors = ButtonDefaults.buttonColors(
|
colors = ButtonDefaults.buttonColors(
|
||||||
containerColor = Color.LegacyRed,
|
containerColor = Primary,
|
||||||
contentColor = Color.White,
|
contentColor = White,
|
||||||
disabledContainerColor = Color.LegacyRed.copy(alpha = 0.5f),
|
disabledContainerColor = Primary,
|
||||||
disabledContentColor = Color.White.copy(alpha = 0.5f),
|
disabledContentColor = White,
|
||||||
),
|
),
|
||||||
shape = RoundedCornerShape(12.dp),
|
shape = RoundedCornerShape(12.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
// onPrint()
|
onPrint()
|
||||||
try {
|
try {
|
||||||
PrintReceipt.getInstance().printNow()
|
NewPrintReceipt.getInstance().testPrint()
|
||||||
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")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
@ -152,7 +116,6 @@ fun PrintReceiptScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ReceiptPreview(
|
fun ReceiptPreview(
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
@ -164,26 +127,32 @@ fun ReceiptPreview(
|
|||||||
.background(Color.White)
|
.background(Color.White)
|
||||||
.border(
|
.border(
|
||||||
width = 1.dp,
|
width = 1.dp,
|
||||||
color = Color.Gray,
|
color = Color.LightGray,
|
||||||
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")
|
||||||
@ -194,8 +163,11 @@ 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,
|
||||||
@ -228,7 +200,7 @@ fun ReceiptRow(
|
|||||||
text = label,
|
text = label,
|
||||||
fontSize = 13.sp,
|
fontSize = 13.sp,
|
||||||
fontFamily = FontFamily.Monospace,
|
fontFamily = FontFamily.Monospace,
|
||||||
color = Color.Gray
|
color = Color.DarkGray
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
@ -1,19 +0,0 @@
|
|||||||
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()
|
|
||||||
}
|
|
||||||
@ -1,87 +0,0 @@
|
|||||||
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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,262 +0,0 @@
|
|||||||
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,90 +0,0 @@
|
|||||||
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