Compare commits
2 Commits
44c0fa20af
...
ee2f9df351
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee2f9df351 | ||
|
|
35600bda29 |
@ -0,0 +1,34 @@
|
||||
package com.mob.utsmyanmar.ui.amount
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import com.mob.utsmyanmar.model.ProcessCode
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
|
||||
@Composable
|
||||
fun AmountRoute(
|
||||
action: String,
|
||||
sharedViewModel: SharedViewModel,
|
||||
onBack: () -> Unit,
|
||||
onNavigateCardWaiting: () -> Unit
|
||||
) {
|
||||
val canGoBack = !action.equals("Sale", ignoreCase = true)
|
||||
|
||||
AmountScreen(
|
||||
action = action,
|
||||
canGoBack = canGoBack,
|
||||
onBackClick = onBack,
|
||||
onCancelClick = onBack,
|
||||
onNextClick = { amount ->
|
||||
sharedViewModel.amount.value = amount
|
||||
sharedViewModel.setAmountExist(true)
|
||||
sharedViewModel.setCardDataExist(false)
|
||||
sharedViewModel.setTransMenu(null)
|
||||
sharedViewModel.transactionsType.value = TransactionsType.SALE
|
||||
sharedViewModel.processCode.value =
|
||||
ProcessCode.SALE_PURCHASE + ProcessCode.SMART + ProcessCode.TO_ACCOUNT
|
||||
|
||||
onNavigateCardWaiting()
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package com.mob.utsmyanmar.ui.amount
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
@ -32,10 +33,14 @@ import com.mob.utsmyanmar.R
|
||||
@Composable
|
||||
fun AmountScreen(
|
||||
action: String,
|
||||
canGoBack: Boolean = true,
|
||||
onBackClick: () -> Unit,
|
||||
onCancelClick: () -> Unit = {},
|
||||
onNextClick: (String) -> Unit = {}
|
||||
) {
|
||||
BackHandler(enabled = canGoBack) {
|
||||
onBackClick()
|
||||
}
|
||||
|
||||
var amount by remember {
|
||||
mutableStateOf("0")
|
||||
@ -53,13 +58,15 @@ fun AmountScreen(
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBackClick) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_left_arrow),
|
||||
contentDescription = "Back",
|
||||
modifier = Modifier.size(24.dp),
|
||||
tint = White
|
||||
)
|
||||
if (canGoBack) {
|
||||
IconButton(onClick = onBackClick) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_left_arrow),
|
||||
contentDescription = "Back",
|
||||
modifier = Modifier.size(24.dp),
|
||||
tint = White
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
@ -104,31 +111,12 @@ fun AmountScreen(
|
||||
horizontalArrangement = Arrangement.spacedBy(14.dp)
|
||||
) {
|
||||
|
||||
Button(
|
||||
onClick = onCancelClick,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(68.dp),
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = White,
|
||||
contentColor = Primary
|
||||
),
|
||||
border = ButtonDefaults.outlinedButtonBorder
|
||||
) {
|
||||
Text(
|
||||
text = "Cancel",
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
onNextClick(normalizeAmount(amount))
|
||||
},
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.weight(if (canGoBack) 1f else 2f)
|
||||
.height(68.dp),
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
@ -142,6 +130,27 @@ fun AmountScreen(
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
|
||||
if (canGoBack) {
|
||||
Button(
|
||||
onClick = onCancelClick,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(68.dp),
|
||||
shape = RoundedCornerShape(18.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = White,
|
||||
contentColor = Primary
|
||||
),
|
||||
border = ButtonDefaults.outlinedButtonBorder
|
||||
) {
|
||||
Text(
|
||||
text = "Cancel",
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
@ -356,6 +365,7 @@ private fun AmountScreenPreview() {
|
||||
|
||||
AmountScreen(
|
||||
action = "Amount",
|
||||
canGoBack = true,
|
||||
onBackClick = {}
|
||||
)
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ fun CardWaitingScreen(
|
||||
}
|
||||
}
|
||||
|
||||
BackHandler {
|
||||
BackHandler(enabled = uiState.canGoBack) {
|
||||
viewModel.onBackPressed()
|
||||
}
|
||||
|
||||
@ -90,12 +90,14 @@ fun CardWaitingScreen(
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_left_arrow),
|
||||
contentDescription = "Back",
|
||||
tint = White
|
||||
)
|
||||
if (uiState.canGoBack) {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_left_arrow),
|
||||
contentDescription = "Back",
|
||||
tint = White
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
|
||||
@ -3,5 +3,6 @@ package com.mob.utsmyanmar.ui.cardwaiting
|
||||
data class CardWaitingUiState(
|
||||
val alertMessage: String = "Please insert, tap, or swipe card",
|
||||
val isLoading: Boolean = false,
|
||||
val isFallback: Boolean = false
|
||||
)
|
||||
val isFallback: Boolean = false,
|
||||
val canGoBack: Boolean = true
|
||||
)
|
||||
|
||||
@ -61,6 +61,11 @@ class CardWaitingViewModel(
|
||||
retryCounter = 0
|
||||
fallbackCounter = SystemParamsOperation.getInstance().fallbackCounter
|
||||
fallbackEnabled = SystemParamsOperation.getInstance().fallbackEnabled
|
||||
val isSaleTransaction = sharedViewModel.transactionsType.value == TransactionsType.SALE
|
||||
|
||||
_uiState.update {
|
||||
it.copy(canGoBack = !isSaleTransaction)
|
||||
}
|
||||
|
||||
if (sharedViewModel.transactionsType.value == TransactionsType.REFUND) {
|
||||
sharedViewModel.enableCardStatusIcon(false, false, false, false)
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package com.mob.utsmyanmar.ui.dashboard
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
fun DashboardRoute(
|
||||
onNavigateAmount: (String) -> Unit,
|
||||
settlementEnabled: Boolean,
|
||||
wavePayEnabled: Boolean,
|
||||
) {
|
||||
DashboardScreen(
|
||||
settlementEnabled = settlementEnabled,
|
||||
wavePayEnabled = wavePayEnabled,
|
||||
onNavigateAmount = onNavigateAmount
|
||||
)
|
||||
}
|
||||
@ -29,17 +29,11 @@ import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
fun DashboardScreen(
|
||||
settlementEnabled: Boolean,
|
||||
wavePayEnabled: Boolean,
|
||||
onAmountClick: (String) -> Unit,
|
||||
onTransactionClick: () -> Unit,
|
||||
onSettlementClick: () -> Unit,
|
||||
onHistoryClick: () -> Unit,
|
||||
onCardClick: () -> Unit,
|
||||
onWavePayClick: () -> Unit
|
||||
onNavigateAmount: (String) -> Unit
|
||||
) {
|
||||
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
|
||||
ModalNavigationDrawer(
|
||||
drawerState = drawerState,
|
||||
drawerContent = {
|
||||
@ -71,7 +65,6 @@ fun DashboardScreen(
|
||||
.fillMaxWidth()
|
||||
.clickable {
|
||||
scope.launch { drawerState.close() }
|
||||
onTransactionClick()
|
||||
}
|
||||
.padding(horizontal = 24.dp, vertical = 14.dp),
|
||||
fontSize = 16.sp
|
||||
@ -82,7 +75,6 @@ fun DashboardScreen(
|
||||
.fillMaxWidth()
|
||||
.clickable {
|
||||
scope.launch { drawerState.close() }
|
||||
onHistoryClick()
|
||||
}
|
||||
.padding(horizontal = 24.dp, vertical = 14.dp),
|
||||
fontSize = 16.sp
|
||||
@ -93,7 +85,6 @@ fun DashboardScreen(
|
||||
.fillMaxWidth()
|
||||
.clickable(enabled = settlementEnabled) {
|
||||
scope.launch { drawerState.close() }
|
||||
onSettlementClick()
|
||||
}
|
||||
.padding(horizontal = 24.dp, vertical = 14.dp),
|
||||
color = if (settlementEnabled) Black else White,
|
||||
@ -105,7 +96,6 @@ fun DashboardScreen(
|
||||
.fillMaxWidth()
|
||||
.clickable(enabled = wavePayEnabled) {
|
||||
scope.launch { drawerState.close() }
|
||||
onWavePayClick()
|
||||
}
|
||||
.padding(horizontal = 24.dp, vertical = 14.dp),
|
||||
color = if (wavePayEnabled) Black else White,
|
||||
@ -176,7 +166,7 @@ fun DashboardScreen(
|
||||
contentColor = Primary,
|
||||
iconTint = Primary,
|
||||
border = null,
|
||||
onClick = { onAmountClick("Sale") },
|
||||
onClick = { onNavigateAmount("Sale") },
|
||||
)
|
||||
SquareButton(
|
||||
title = "Sign On",
|
||||
@ -186,7 +176,7 @@ fun DashboardScreen(
|
||||
contentColor = Primary,
|
||||
iconTint = Primary,
|
||||
border = null,
|
||||
onClick = { onAmountClick("Sign On") }
|
||||
onClick = { onNavigateAmount("Sign On") }
|
||||
)
|
||||
}
|
||||
|
||||
@ -203,7 +193,7 @@ fun DashboardScreen(
|
||||
contentColor = Primary,
|
||||
iconTint = Primary,
|
||||
border = null,
|
||||
onClick = onSettlementClick
|
||||
onClick = {}
|
||||
)
|
||||
SquareButton(
|
||||
title = "Others",
|
||||
@ -213,7 +203,7 @@ fun DashboardScreen(
|
||||
contentColor = Primary,
|
||||
iconTint = Primary,
|
||||
border = null,
|
||||
onClick = onCardClick
|
||||
onClick = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -230,12 +220,7 @@ private fun DashboardScreenPreview() {
|
||||
DashboardScreen(
|
||||
settlementEnabled = true,
|
||||
wavePayEnabled = true,
|
||||
onAmountClick = {},
|
||||
onTransactionClick = {},
|
||||
onSettlementClick = {},
|
||||
onHistoryClick = {},
|
||||
onCardClick = {},
|
||||
onWavePayClick = {}
|
||||
onNavigateAmount = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.mob.utsmyanmar.ui.navigation
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@ -10,11 +11,10 @@ import androidx.navigation.NavType
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.navArgument
|
||||
import com.mob.utsmyanmar.model.ProcessCode
|
||||
import com.mob.utsmyanmar.ui.amount.AmountScreen
|
||||
import com.mob.utsmyanmar.ui.amount.AmountRoute
|
||||
import com.mob.utsmyanmar.ui.cardwaiting.CardWaitingScreen
|
||||
import com.mob.utsmyanmar.ui.cardwaiting.CardWaitingViewModel
|
||||
import com.mob.utsmyanmar.ui.dashboard.DashboardScreen
|
||||
import com.mob.utsmyanmar.ui.dashboard.DashboardRoute
|
||||
import com.mob.utsmyanmar.ui.pinpad.PinPadRoute
|
||||
import com.mob.utsmyanmar.ui.processing_card.ProcessingCardRoute
|
||||
import com.mob.utsmyanmar.ui.processing_card.ProcessingCardViewModel
|
||||
@ -25,8 +25,8 @@ import com.mob.utsmyanmar.viewmodel.EmvTransactionProcessViewModel
|
||||
import com.mob.utsmyanmar.ui.pinpad.PinPadViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.TransProcessViewModel
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
|
||||
@SuppressLint("ContextCastToActivity")
|
||||
@Composable
|
||||
fun AppNavGraph(
|
||||
navController: NavHostController
|
||||
@ -38,17 +38,17 @@ fun AppNavGraph(
|
||||
startDestination = Routes.Dashboard.route
|
||||
) {
|
||||
composable(Routes.Dashboard.route) {
|
||||
DashboardScreen(
|
||||
settlementEnabled = true,
|
||||
wavePayEnabled = true,
|
||||
onAmountClick = { action ->
|
||||
navController.navigate(Routes.Amount.createRoute(action))
|
||||
DashboardRoute(
|
||||
onNavigateAmount = { action ->
|
||||
navController.navigate(Routes.Amount.createRoute(action)) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
inclusive = false
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onTransactionClick = {},
|
||||
onSettlementClick = {},
|
||||
onHistoryClick = {},
|
||||
onCardClick = {},
|
||||
onWavePayClick = {}
|
||||
settlementEnabled = true,
|
||||
wavePayEnabled = true
|
||||
)
|
||||
}
|
||||
|
||||
@ -62,20 +62,17 @@ fun AppNavGraph(
|
||||
) { backStackEntry ->
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
|
||||
AmountScreen(
|
||||
AmountRoute(
|
||||
action = backStackEntry.arguments?.getString("action").orEmpty(),
|
||||
onBackClick = { navController.popBackStack() },
|
||||
onCancelClick = { navController.popBackStack() },
|
||||
onNextClick = { amount ->
|
||||
sharedViewModel.amount.value = amount
|
||||
sharedViewModel.setAmountExist(true)
|
||||
sharedViewModel.setCardDataExist(false)
|
||||
sharedViewModel.setTransMenu(null)
|
||||
sharedViewModel.transactionsType.value = TransactionsType.SALE
|
||||
sharedViewModel.processCode.value =
|
||||
ProcessCode.SALE_PURCHASE + ProcessCode.SMART + ProcessCode.TO_ACCOUNT
|
||||
|
||||
navController.navigate(Routes.CardWaiting.route)
|
||||
sharedViewModel = sharedViewModel,
|
||||
onBack = { navController.popBackStack() },
|
||||
onNavigateCardWaiting = {
|
||||
navController.navigate(Routes.CardWaiting.route) {
|
||||
popUpTo(Routes.Amount.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -94,7 +91,12 @@ fun AppNavGraph(
|
||||
viewModel = cardWaitingViewModel,
|
||||
onManualEntry = {},
|
||||
onProcessingCard = {
|
||||
navController.navigate(Routes.ProcessingCard.route)
|
||||
navController.navigate(Routes.ProcessingCard.route) {
|
||||
popUpTo(Routes.CardWaiting.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onTimeout = { navController.popBackStack() },
|
||||
onBack = { navController.popBackStack() },
|
||||
@ -128,7 +130,12 @@ fun AppNavGraph(
|
||||
ProcessingCardRoute(
|
||||
viewModel = processingCardViewModel,
|
||||
onNavigatePinPad = {
|
||||
navController.navigate(Routes.PinPad.route)
|
||||
navController.navigate(Routes.PinPad.route) {
|
||||
popUpTo(Routes.ProcessingCard.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
onNavigateInputAmount = { navController.popBackStack(Routes.Amount.route, false) },
|
||||
onNavigateProcessing = {},
|
||||
@ -150,8 +157,8 @@ fun AppNavGraph(
|
||||
transProcessViewModel = transProcessViewModel,
|
||||
onNavigateTransactionResult = {
|
||||
navController.navigate(Routes.TransactionResult.route) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
inclusive = false
|
||||
popUpTo(Routes.PinPad.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
@ -189,6 +196,7 @@ fun AppNavGraph(
|
||||
|
||||
composable(Routes.PrintReceipt.route) {
|
||||
PrintReceiptScreen(
|
||||
onPrint = {},
|
||||
onDone = {
|
||||
navController.navigate(Routes.Dashboard.route) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.mob.utsmyanmar.ui.pinpad
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
@ -9,6 +10,7 @@ import com.mob.utsmyanmar.model.PinPadStatus
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.TransProcessViewModel
|
||||
import com.utsmyanmar.paylibs.Constant
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
|
||||
@Composable
|
||||
fun PinPadRoute(
|
||||
@ -21,6 +23,11 @@ fun PinPadRoute(
|
||||
val pinText by pinPadViewModel.pinText.collectAsStateWithLifecycle()
|
||||
val alertMsg by pinPadViewModel.alertMsg.collectAsStateWithLifecycle()
|
||||
val pinStatus by pinPadViewModel.pinStatus.collectAsStateWithLifecycle()
|
||||
val canGoBack = sharedViewModel.transactionsType.value != TransactionsType.SALE
|
||||
|
||||
BackHandler(enabled = canGoBack) {
|
||||
onBack()
|
||||
}
|
||||
|
||||
LaunchedEffect(pinStatus) {
|
||||
when (pinStatus) {
|
||||
@ -52,6 +59,7 @@ fun PinPadRoute(
|
||||
PinPadScreen(
|
||||
pinText = pinText,
|
||||
alertMessage = alertMsg,
|
||||
canGoBack = canGoBack,
|
||||
onBack = onBack,
|
||||
onKeyboardReady = { keyboard ->
|
||||
pinPadViewModel.startPinPadProcess(keyboard)
|
||||
|
||||
@ -42,6 +42,7 @@ import com.utsmyanmar.baselib.ui.CustomPinPadKeyboard
|
||||
fun PinPadScreen(
|
||||
pinText: String,
|
||||
alertMessage: String?,
|
||||
canGoBack: Boolean,
|
||||
onBack: () -> Unit,
|
||||
onKeyboardReady: (CustomPinPadKeyboard) -> Unit
|
||||
) {
|
||||
@ -68,12 +69,14 @@ fun PinPadScreen(
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_left_arrow),
|
||||
contentDescription = "Back",
|
||||
tint = White
|
||||
)
|
||||
if (canGoBack) {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_left_arrow),
|
||||
contentDescription = "Back",
|
||||
tint = White
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
@ -163,7 +166,11 @@ fun PinPadScreen(
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Cancel on device or use back to exit.",
|
||||
text = if (canGoBack) {
|
||||
"Cancel on device or use back to exit."
|
||||
} else {
|
||||
"Cancel on device to exit."
|
||||
},
|
||||
color = Black,
|
||||
fontSize = 14.sp,
|
||||
textAlign = TextAlign.Center
|
||||
|
||||
@ -1,63 +1,236 @@
|
||||
package com.mob.utsmyanmar.ui.print_receipt
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
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.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.mob.utsmyanmar.ui.theme.Primary
|
||||
import com.mob.utsmyanmar.ui.theme.White
|
||||
import com.utsmyanmar.paylibs.print.NewPrintReceipt
|
||||
|
||||
@Composable
|
||||
fun PrintReceiptScreen(
|
||||
onPrint: () -> Unit,
|
||||
onDone: () -> Unit
|
||||
) {
|
||||
BackHandler {
|
||||
onDone()
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AppBar(title = "Print Receipt")
|
||||
AppBar(title = "Receipt")
|
||||
}
|
||||
) { paddingValues ->
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(paddingValues)
|
||||
.fillMaxSize()
|
||||
.background(Color(0xFFF5F5F5))
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Text(
|
||||
text = "Print Receipt",
|
||||
style = MaterialTheme.typography.titleLarge.copy(
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
|
||||
ReceiptPreview(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.verticalScroll(rememberScrollState())
|
||||
)
|
||||
|
||||
Button(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 24.dp),
|
||||
onClick = onDone
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Text(text = "Back to Dashboard")
|
||||
|
||||
OutlinedButton(
|
||||
onClick = onDone,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(50.dp),
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Cancel",
|
||||
style = MaterialTheme.typography.bodyLarge.copy(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(50.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Primary,
|
||||
contentColor = White,
|
||||
disabledContainerColor = Primary,
|
||||
disabledContentColor = White,
|
||||
),
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
onClick = {
|
||||
onPrint()
|
||||
try {
|
||||
NewPrintReceipt.getInstance().testPrint()
|
||||
} catch (e: Exception) {
|
||||
Log.d("PrintReceipt", "error with $e")
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "Print",
|
||||
style = MaterialTheme.typography.bodyLarge.copy(
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ReceiptPreview(
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(Color.White)
|
||||
.border(
|
||||
width = 1.dp,
|
||||
color = Color.LightGray,
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
)
|
||||
.padding(20.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "MOB POS",
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontFamily = FontFamily.Monospace
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Text(
|
||||
text = "Transaction Receipt",
|
||||
fontSize = 14.sp,
|
||||
fontFamily = FontFamily.Monospace
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
ReceiptDivider()
|
||||
|
||||
ReceiptRow("Merchant", "MOB UTS Myanmar")
|
||||
ReceiptRow("Terminal ID", "POS001")
|
||||
ReceiptRow("Transaction", "SALE")
|
||||
ReceiptRow("Amount", "500.00 MMK")
|
||||
ReceiptRow("Card Type", "MPU")
|
||||
ReceiptRow("Card No", "1234 **** **** 5678")
|
||||
ReceiptRow("Status", "SUCCESS")
|
||||
ReceiptRow("Date", "13/05/2026")
|
||||
ReceiptRow("Time", "14:30:22")
|
||||
ReceiptRow("Ref No", "REF123456789")
|
||||
|
||||
ReceiptDivider()
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Text(
|
||||
text = "Thank You",
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
fontFamily = FontFamily.Monospace
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
Text(
|
||||
text = "Please keep this receipt",
|
||||
fontSize = 12.sp,
|
||||
fontFamily = FontFamily.Monospace
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ReceiptRow(
|
||||
label: String,
|
||||
value: String
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 6.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
fontSize = 13.sp,
|
||||
fontFamily = FontFamily.Monospace,
|
||||
color = Color.DarkGray
|
||||
)
|
||||
|
||||
Text(
|
||||
text = value,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
fontFamily = FontFamily.Monospace
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ReceiptDivider() {
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 10.dp),
|
||||
text = "--------------------------------",
|
||||
fontFamily = FontFamily.Monospace,
|
||||
color = Color.Gray
|
||||
)
|
||||
}
|
||||
|
||||
@Preview(showBackground = true, showSystemUi = true)
|
||||
@Composable
|
||||
fun PreviewPrintReceiptScreen() {
|
||||
PrintReceiptScreen { }
|
||||
MaterialTheme {
|
||||
PrintReceiptScreen(
|
||||
onPrint = {},
|
||||
onDone = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
|
||||
@Composable
|
||||
fun TransactionResultRoute(
|
||||
@ -19,6 +20,7 @@ fun TransactionResultRoute(
|
||||
onShowPrinterDialog: (String) -> Unit
|
||||
) {
|
||||
val state by viewModel.state.collectAsStateWithLifecycle()
|
||||
val canGoBack = sharedViewModel.transactionsType.value != TransactionsType.SALE
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.onEvent(
|
||||
@ -41,6 +43,7 @@ fun TransactionResultRoute(
|
||||
|
||||
TransactionResultScreen(
|
||||
state = state,
|
||||
canGoBack = canGoBack,
|
||||
onEvent = {
|
||||
viewModel.onEvent(it, sharedViewModel)
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.mob.utsmyanmar.ui.transaction_result
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@ -46,14 +47,21 @@ import com.mob.utsmyanmar.ui.theme.White
|
||||
@Composable
|
||||
fun TransactionResultScreen(
|
||||
state: TransactionResultState,
|
||||
canGoBack: Boolean,
|
||||
onEvent: (TransactionResultEvent) -> Unit,
|
||||
) {
|
||||
BackHandler(enabled = !canGoBack) {}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AppBar(
|
||||
title = "Transaction Results",
|
||||
icon = Icons.Default.ChevronLeft,
|
||||
onIconClick = { TransactionResultEvent.BackClick }
|
||||
icon = if (canGoBack) Icons.Default.ChevronLeft else null,
|
||||
onIconClick = if (canGoBack) {
|
||||
{ onEvent(TransactionResultEvent.BackClick) }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
@ -254,6 +262,7 @@ fun TransactionResultScreenPreview() {
|
||||
message = "Transaction Approved",
|
||||
isLoading = false
|
||||
),
|
||||
canGoBack = true,
|
||||
onEvent = {}
|
||||
)
|
||||
}
|
||||
|
||||
@ -75,6 +75,7 @@ dependencies {
|
||||
implementation project(path: ':sunmiui-lib')
|
||||
// implementation 'com.sunmi:printerlibrary:1.0.9'
|
||||
implementation 'com.sunmi:printerlibrary:1.0.23'
|
||||
implementation 'com.sunmi:printerx:1.0.17'
|
||||
|
||||
//RxJava
|
||||
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
|
||||
|
||||
@ -98,7 +98,7 @@ public class BaseApplication extends Application {
|
||||
mPinPadOptV2 = sunmiPayKernel.mPinPadOptV2;
|
||||
mReadCardOptV2 = sunmiPayKernel.mReadCardOptV2;
|
||||
mSecurityOptV2 = sunmiPayKernel.mSecurityOptV2;
|
||||
|
||||
PayLibsUtils.getInstance().initPrinterX();
|
||||
PayLibsUtils.getInstance().initLib(mSecurityOptV2,mEMVOptV2,securityOpt,mReadCardOptV2);
|
||||
SunmiSDK.getInstance().initSDK(mReadCardOptV2,basicOptV2);
|
||||
|
||||
|
||||
@ -66,6 +66,7 @@ dependencies {
|
||||
|
||||
// implementation 'com.sunmi:printerlibrary:1.0.9'
|
||||
implementation 'com.sunmi:printerlibrary:1.0.24'
|
||||
implementation 'com.sunmi:printerx:1.0.17'
|
||||
//paySDK
|
||||
// implementation project(path:':PayLib-release-1.4.58')
|
||||
implementation project(path: ':sunmiui-lib')
|
||||
|
||||
@ -7,6 +7,12 @@ import com.sunmi.pay.hardware.aidlv2.emv.EMVOptV2;
|
||||
import com.sunmi.pay.hardware.aidlv2.readcard.ReadCardOptV2;
|
||||
import com.sunmi.pay.hardware.aidlv2.security.SecurityOptV2;
|
||||
import com.sunmi.peripheral.printer.SunmiPrinterService;
|
||||
import com.sunmi.printerx.PrinterSdk;
|
||||
import com.sunmi.printerx.SdkException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import sunmi.sunmiui.utils.LogUtil;
|
||||
|
||||
public class PayLibsUtils {
|
||||
|
||||
@ -23,6 +29,8 @@ public class PayLibsUtils {
|
||||
public SecurityOpt securityOpt;
|
||||
|
||||
public ReadCardOptV2 readCardOptV2;
|
||||
|
||||
public PrinterSdk.Printer printer;
|
||||
|
||||
private PayLibsUtils(){}
|
||||
|
||||
@ -49,8 +57,21 @@ public class PayLibsUtils {
|
||||
this.readCardOptV2 = readCardOptV2;
|
||||
}
|
||||
|
||||
public void initPrinterX() throws SdkException {
|
||||
PrinterSdk.getInstance().getPrinter(
|
||||
context,
|
||||
new PrinterSdk.PrinterListen() {
|
||||
@Override
|
||||
public void onDefPrinter(PrinterSdk.Printer defPrinter) {
|
||||
LogUtil.d("PayLibsUtils", "init printer : " + defPrinter);
|
||||
printer = defPrinter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrinters(List<PrinterSdk.Printer> list) {
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
package com.utsmyanmar.paylibs.print;
|
||||
|
||||
import com.sunmi.printerx.PrinterSdk;
|
||||
import com.sunmi.printerx.SdkException;
|
||||
import com.sunmi.printerx.style.TextStyle;
|
||||
|
||||
public class NewPrintReceipt {
|
||||
|
||||
private static NewPrintReceipt instance;
|
||||
|
||||
private PrinterSdk.Printer printer;
|
||||
|
||||
private NewPrintReceipt() {}
|
||||
|
||||
public static synchronized NewPrintReceipt getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new NewPrintReceipt();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void setPrinter(PrinterSdk.Printer printer) {
|
||||
this.printer = printer;
|
||||
}
|
||||
|
||||
public void testPrint() throws SdkException {
|
||||
|
||||
if (printer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
printer.lineApi().addText("testing", TextStyle.getStyle());
|
||||
printer.lineApi().autoOut();
|
||||
}
|
||||
}
|
||||
@ -75,6 +75,8 @@ public class PrintReceipt {
|
||||
bitmap = BitmapFactory.decodeResource(resources, R.drawable.primary_print_logo_yoma_bank, opts);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void clearQueue() throws RemoteException {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user