fix navigation to reset goback
This commit is contained in:
parent
35600bda29
commit
ee2f9df351
@ -12,8 +12,11 @@ fun AmountRoute(
|
||||
onBack: () -> Unit,
|
||||
onNavigateCardWaiting: () -> Unit
|
||||
) {
|
||||
val canGoBack = !action.equals("Sale", ignoreCase = true)
|
||||
|
||||
AmountScreen(
|
||||
action = action,
|
||||
canGoBack = canGoBack,
|
||||
onBackClick = onBack,
|
||||
onCancelClick = onBack,
|
||||
onNextClick = { amount ->
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -40,7 +40,12 @@ fun AppNavGraph(
|
||||
composable(Routes.Dashboard.route) {
|
||||
DashboardRoute(
|
||||
onNavigateAmount = { action ->
|
||||
navController.navigate(Routes.Amount.createRoute(action))
|
||||
navController.navigate(Routes.Amount.createRoute(action)) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
inclusive = false
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
settlementEnabled = true,
|
||||
wavePayEnabled = true
|
||||
@ -61,7 +66,14 @@ fun AppNavGraph(
|
||||
action = backStackEntry.arguments?.getString("action").orEmpty(),
|
||||
sharedViewModel = sharedViewModel,
|
||||
onBack = { navController.popBackStack() },
|
||||
onNavigateCardWaiting = { navController.navigate(Routes.CardWaiting.route) }
|
||||
onNavigateCardWaiting = {
|
||||
navController.navigate(Routes.CardWaiting.route) {
|
||||
popUpTo(Routes.Amount.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@ -79,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() },
|
||||
@ -113,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 = {},
|
||||
@ -135,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
|
||||
}
|
||||
|
||||
@ -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,6 +1,7 @@
|
||||
package com.mob.utsmyanmar.ui.print_receipt
|
||||
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.*
|
||||
@ -8,7 +9,6 @@ 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.ButtonColors
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
@ -28,13 +28,16 @@ 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
|
||||
import com.utsmyanmar.paylibs.print.PrintReceipt
|
||||
|
||||
@Composable
|
||||
fun PrintReceiptScreen(
|
||||
onPrint: () -> Unit,
|
||||
onDone: () -> Unit
|
||||
) {
|
||||
BackHandler {
|
||||
onDone()
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AppBar(title = "Receipt")
|
||||
@ -64,7 +67,7 @@ fun PrintReceiptScreen(
|
||||
) {
|
||||
|
||||
OutlinedButton(
|
||||
onClick = {},
|
||||
onClick = onDone,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(50.dp),
|
||||
@ -90,11 +93,14 @@ fun PrintReceiptScreen(
|
||||
disabledContentColor = White,
|
||||
),
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
onClick = { try {
|
||||
NewPrintReceipt.getInstance().testPrint()
|
||||
}catch (e: Exception){
|
||||
Log.d("PrintReceipt", "error with $e")
|
||||
} }
|
||||
onClick = {
|
||||
onPrint()
|
||||
try {
|
||||
NewPrintReceipt.getInstance().testPrint()
|
||||
} catch (e: Exception) {
|
||||
Log.d("PrintReceipt", "error with $e")
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "Print",
|
||||
|
||||
@ -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 = {}
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user