Modified AppBar and add routes
This commit is contained in:
parent
04549321fb
commit
44c0fa20af
@ -1,7 +1,11 @@
|
||||
package com.mob.utsmyanmar.ui.components.appbar
|
||||
|
||||
import android.graphics.drawable.Icon
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
@ -12,8 +16,8 @@ import com.mob.utsmyanmar.ui.theme.White
|
||||
@Composable
|
||||
fun AppBar(
|
||||
title: String,
|
||||
icon: ImageVector? = null,
|
||||
onIconClick: (() -> Unit)? = null,
|
||||
icon: ImageVector
|
||||
) {
|
||||
CenterAlignedTopAppBar(
|
||||
title = {
|
||||
@ -23,19 +27,21 @@ fun AppBar(
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
},
|
||||
|
||||
navigationIcon = {
|
||||
if (onIconClick != null) {
|
||||
if (icon != null && onIconClick != null) {
|
||||
IconButton(
|
||||
onClick = onIconClick
|
||||
) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
"Appbar icon",
|
||||
imageVector = icon,
|
||||
contentDescription = "App bar icon",
|
||||
tint = White
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = Primary
|
||||
)
|
||||
|
||||
@ -18,6 +18,7 @@ import com.mob.utsmyanmar.ui.dashboard.DashboardScreen
|
||||
import com.mob.utsmyanmar.ui.pinpad.PinPadRoute
|
||||
import com.mob.utsmyanmar.ui.processing_card.ProcessingCardRoute
|
||||
import com.mob.utsmyanmar.ui.processing_card.ProcessingCardViewModel
|
||||
import com.mob.utsmyanmar.ui.print_receipt.PrintReceiptScreen
|
||||
import com.mob.utsmyanmar.ui.transaction_result.TransactionResultRoute
|
||||
import com.mob.utsmyanmar.viewmodel.CardReaderViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.EmvTransactionProcessViewModel
|
||||
@ -173,8 +174,8 @@ fun AppNavGraph(
|
||||
}
|
||||
},
|
||||
onNavigatePrintReceipt = {
|
||||
navController.navigate(Routes.Dashboard.route) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
navController.navigate(Routes.PrintReceipt.route) {
|
||||
popUpTo(Routes.TransactionResult.route) {
|
||||
inclusive = false
|
||||
}
|
||||
launchSingleTop = true
|
||||
@ -185,5 +186,18 @@ fun AppNavGraph(
|
||||
onShowPrinterDialog = {}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.PrintReceipt.route) {
|
||||
PrintReceiptScreen(
|
||||
onDone = {
|
||||
navController.navigate(Routes.Dashboard.route) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
inclusive = false
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,4 +9,5 @@ sealed class Routes(val route: String) {
|
||||
data object ProcessingCard : Routes("processing_card")
|
||||
data object PinPad : Routes("pin_pad")
|
||||
data object TransactionResult : Routes("transaction_result")
|
||||
data object PrintReceipt : Routes("print_receipt")
|
||||
}
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
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 androidx.compose.material3.Button
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
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.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
|
||||
@Composable
|
||||
fun PrintReceiptScreen(
|
||||
onDone: () -> Unit
|
||||
) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AppBar(title = "Print Receipt")
|
||||
}
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(paddingValues)
|
||||
.fillMaxSize()
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
text = "Print Receipt",
|
||||
style = MaterialTheme.typography.titleLarge.copy(
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
)
|
||||
)
|
||||
|
||||
Button(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 24.dp),
|
||||
onClick = onDone
|
||||
) {
|
||||
Text(text = "Back to Dashboard")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true, showSystemUi = true)
|
||||
@Composable
|
||||
fun PreviewPrintReceiptScreen() {
|
||||
PrintReceiptScreen { }
|
||||
}
|
||||
|
||||
@ -27,6 +27,18 @@ fun TransactionResultRoute(
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.uiEvent.collect { event ->
|
||||
when (event) {
|
||||
TransactionResultUiEvent.NavigateMain -> onNavigateMain()
|
||||
TransactionResultUiEvent.NavigatePrintReceipt -> onNavigatePrintReceipt()
|
||||
is TransactionResultUiEvent.ShowError -> onShowError(event.message)
|
||||
is TransactionResultUiEvent.ShowSuccess -> onShowSuccess(event.message)
|
||||
is TransactionResultUiEvent.ShowPrinterDialog -> onShowPrinterDialog(event.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TransactionResultScreen(
|
||||
state = state,
|
||||
onEvent = {
|
||||
|
||||
@ -35,7 +35,7 @@ class TransactionResultViewModel @Inject constructor(
|
||||
|
||||
companion object {
|
||||
private const val TAG = "TransactionResultVM"
|
||||
private const val RESULT_TIMEOUT = 1000L
|
||||
private const val RESULT_TIMEOUT = 3000L
|
||||
}
|
||||
|
||||
private val _state = MutableStateFlow(TransactionResultState())
|
||||
@ -278,4 +278,4 @@ class TransactionResultViewModel @Inject constructor(
|
||||
_uiEvent.send(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user