From a286a8258cd5d14bbd858052594b5909b76989e2 Mon Sep 17 00:00:00 2001 From: moon <56061215+MgKyawLay@users.noreply.github.com> Date: Tue, 16 Jun 2026 15:53:41 +0630 Subject: [PATCH] last sync caller --- .../ui/dashboard/DashboardScreen.kt | 233 +++++++++++++++--- .../utsmyanmar/ui/navigation/AppNavGraph.kt | 6 +- .../ui/tms_setup/TmsSetupViewModel.kt | 21 -- 3 files changed, 204 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/com/mob/utsmyanmar/ui/dashboard/DashboardScreen.kt b/app/src/main/java/com/mob/utsmyanmar/ui/dashboard/DashboardScreen.kt index be5b139..f570653 100644 --- a/app/src/main/java/com/mob/utsmyanmar/ui/dashboard/DashboardScreen.kt +++ b/app/src/main/java/com/mob/utsmyanmar/ui/dashboard/DashboardScreen.kt @@ -102,7 +102,8 @@ fun DashboardScreen2( onNavigateAction: (String) -> Unit = {}, onNavigateNotifications: () -> Unit = {}, dashboardUiState: DashboardUiState = DashboardUiState(), - deviceInfo: DeviceInfoUiState = DeviceInfoUiState() + deviceInfo: DeviceInfoUiState = DeviceInfoUiState(), + onClickLastSync: () -> Unit = {}, ) { val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed) @@ -112,7 +113,13 @@ fun DashboardScreen2( var activeHostAction by remember { mutableStateOf("Log-On") } var isHostActionRunning by remember { mutableStateOf(false) } var dialogMessage by remember { mutableStateOf("") } - var reversalEnabled by remember { mutableStateOf(runCatching { SystemParamsOperation.getInstance().isReversalOn }.getOrDefault(false)) } + var reversalEnabled by remember { + mutableStateOf( + runCatching { SystemParamsOperation.getInstance().isReversalOn }.getOrDefault( + false + ) + ) + } val isOnline = true @@ -322,7 +329,9 @@ fun DashboardScreen2( title = "Reversal", subTitle = "Enable / Disable Reversal", onClick = { reversalEnabled = !reversalEnabled - runCatching { SystemParamsOperation.getInstance().setReversalFlag(reversalEnabled) } + runCatching { + SystemParamsOperation.getInstance().setReversalFlag(reversalEnabled) + } }, leadingIcon = { Icon( @@ -336,7 +345,9 @@ fun DashboardScreen2( checked = reversalEnabled, onCheckedChange = { isChecked -> reversalEnabled = isChecked - runCatching { SystemParamsOperation.getInstance().setReversalFlag(isChecked) } + runCatching { + SystemParamsOperation.getInstance().setReversalFlag(isChecked) + } } ) }, @@ -429,7 +440,9 @@ fun DashboardScreen2( .fillMaxWidth(), contentAlignment = Alignment.Center ) { - SummaryCard() + SummaryCard( + onClickLastSync + ) } //pager section Box( @@ -499,13 +512,15 @@ private fun AdvertisingArea() { } @Composable -private fun SummaryCard() { +private fun SummaryCard( + onClickLastSync: () -> Unit +) { var isRotating by remember { mutableStateOf(false) } val rotation by animateFloatAsState( - targetValue = if(isRotating) 360f else 0f, + targetValue = if (isRotating) 360f else 0f, animationSpec = tween(durationMillis = 3000, easing = LinearEasing), label = "sync rotating", - finishedListener = {isRotating = false} + finishedListener = { isRotating = false } ) Card( modifier = Modifier @@ -559,18 +574,21 @@ private fun SummaryCard() { .clip(CircleShape) .background(Color.CrimsonRed.copy(alpha = 0.1f)) .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = null - ){ - if(!isRotating) isRotating = true - }, - contentAlignment = Alignment.Center - ){ + interactionSource = remember { MutableInteractionSource() }, + indication = null + ) { + if (!isRotating) isRotating = true + onClickLastSync() + }, + contentAlignment = Alignment.Center, + ) { Icon( imageVector = Icons.Default.Sync, contentDescription = null, - tint = Color.LegacyRed, - modifier = Modifier.size(22.dp).rotate(rotation) + tint = Color.CrimsonRed, + modifier = Modifier + .size(22.dp) + .rotate(rotation) ) } } @@ -643,18 +661,125 @@ private fun buildMenuItems( onNavigateSettlement: () -> Unit, onNavigateAction: (String) -> Unit ): List = listOf( - DashboardMenuItem("Sale", { Icon(painterResource(R.drawable.ic_terminal), contentDescription = null, modifier = Modifier.size(40.dp), tint = Color.LegacyRed) }) { onNavigateAmount("Sale") }, - DashboardMenuItem("MMQR", { Image(painter = painterResource(R.drawable.ic_mmqr_logo), contentDescription = null, modifier = Modifier.height(48.dp)) }) { }, - DashboardMenuItem("History", { Icon(painterResource(R.drawable.ic_history), contentDescription = null, modifier = Modifier.size(32.dp), tint = Color.LegacyRed) }) { }, - DashboardMenuItem("Sign On", { Icon(painterResource(R.drawable.ic_sign_on), contentDescription = null, modifier = Modifier.size(32.dp), tint = Color.LegacyRed) }) { onNavigateSignOn() }, - DashboardMenuItem("Settlement", { Icon(painterResource(R.drawable.ic_settlement), contentDescription = null, modifier = Modifier.size(32.dp), tint = Color.LegacyRed) }) { onNavigateSettlement() }, - DashboardMenuItem("Void", { Icon(Icons.Default.Lock, contentDescription = null, modifier = Modifier.size(32.dp), tint = Color.LegacyRed) }) { onNavigateAction("Void") }, - DashboardMenuItem("Refund", { Icon(Icons.Default.Replay, contentDescription = null, modifier = Modifier.size(32.dp), tint = Color.LegacyRed) }) { onNavigateAction("Refund") }, - DashboardMenuItem("Pre-Auth", { Icon(Icons.Default.Lock, contentDescription = null, modifier = Modifier.size(32.dp), tint = Color.LegacyRed) }) { onNavigateAction("Pre-Auth") }, - DashboardMenuItem("Pre-Auth Void", { Icon(Icons.Default.LockOpen, contentDescription = null, modifier = Modifier.size(32.dp), tint = Color.LegacyRed) }) { onNavigateAction("Pre-Auth Void") }, - DashboardMenuItem("Pre-Auth Complete", { Icon(Icons.Default.CreditCard, contentDescription = null, modifier = Modifier.size(32.dp), tint = Color.LegacyRed) }) { onNavigateAction("Pre-Auth Complete") }, - DashboardMenuItem("Pre-Auth Complete Void", { Icon(Icons.Default.SwapHoriz, contentDescription = null, modifier = Modifier.size(32.dp), tint = Color.LegacyRed) }) { onNavigateAction("Pre-Auth Complete Void") }, - DashboardMenuItem("Cash Out", { Icon(Icons.Default.AccountBalanceWallet, contentDescription = null, modifier = Modifier.size(32.dp), tint = Color.LegacyRed) }) { onNavigateAction("Cash Out") }, + DashboardMenuItem( + "Sale", + { + Icon( + painterResource(R.drawable.ic_terminal), + contentDescription = null, + modifier = Modifier.size(40.dp), + tint = Color.LegacyRed + ) + }) { onNavigateAmount("Sale") }, + DashboardMenuItem( + "MMQR", + { + Image( + painter = painterResource(R.drawable.ic_mmqr_logo), + contentDescription = null, + modifier = Modifier.height(48.dp) + ) + }) { }, + DashboardMenuItem( + "History", + { + Icon( + painterResource(R.drawable.ic_history), + contentDescription = null, + modifier = Modifier.size(32.dp), + tint = Color.LegacyRed + ) + }) { }, + DashboardMenuItem( + "Sign On", + { + Icon( + painterResource(R.drawable.ic_sign_on), + contentDescription = null, + modifier = Modifier.size(32.dp), + tint = Color.LegacyRed + ) + }) { onNavigateSignOn() }, + DashboardMenuItem( + "Settlement", + { + Icon( + painterResource(R.drawable.ic_settlement), + contentDescription = null, + modifier = Modifier.size(32.dp), + tint = Color.LegacyRed + ) + }) { onNavigateSettlement() }, + DashboardMenuItem( + "Void", + { + Icon( + Icons.Default.Lock, + contentDescription = null, + modifier = Modifier.size(32.dp), + tint = Color.LegacyRed + ) + }) { onNavigateAction("Void") }, + DashboardMenuItem( + "Refund", + { + Icon( + Icons.Default.Replay, + contentDescription = null, + modifier = Modifier.size(32.dp), + tint = Color.LegacyRed + ) + }) { onNavigateAction("Refund") }, + DashboardMenuItem( + "Pre-Auth", + { + Icon( + Icons.Default.Lock, + contentDescription = null, + modifier = Modifier.size(32.dp), + tint = Color.LegacyRed + ) + }) { onNavigateAction("Pre-Auth") }, + DashboardMenuItem( + "Pre-Auth Void", + { + Icon( + Icons.Default.LockOpen, + contentDescription = null, + modifier = Modifier.size(32.dp), + tint = Color.LegacyRed + ) + }) { onNavigateAction("Pre-Auth Void") }, + DashboardMenuItem( + "Pre-Auth Complete", + { + Icon( + Icons.Default.CreditCard, + contentDescription = null, + modifier = Modifier.size(32.dp), + tint = Color.LegacyRed + ) + }) { onNavigateAction("Pre-Auth Complete") }, + DashboardMenuItem( + "Pre-Auth Complete Void", + { + Icon( + Icons.Default.SwapHoriz, + contentDescription = null, + modifier = Modifier.size(32.dp), + tint = Color.LegacyRed + ) + }) { onNavigateAction("Pre-Auth Complete Void") }, + DashboardMenuItem( + "Cash Out", + { + Icon( + Icons.Default.AccountBalanceWallet, + contentDescription = null, + modifier = Modifier.size(32.dp), + tint = Color.LegacyRed + ) + }) { onNavigateAction("Cash Out") }, ) @Composable @@ -877,11 +1002,51 @@ private fun TrnxRow(record: TrnxRecord) { } private val previewTransactions = listOf( - TrnxRecord(1L, "Sale", "MMK 10,000", "**** 1234", "06/10 14:32", isVoided = false, isApproved = true), - TrnxRecord(2L, "Void", "MMK 5,500", "**** 5678", "06/10 13:10", isVoided = true, isApproved = false), - TrnxRecord(3L, "Refund", "MMK 2,000", "**** 9012", "06/09 09:45", isVoided = false, isApproved = true), - TrnxRecord(4L, "Sale", "MMK 30,000", "**** 3456", "06/09 08:00", isVoided = false, isApproved = true), - TrnxRecord(5L, "Settlement", "MMK 0", "----", "06/08 18:00", isVoided = false, isApproved = true), + TrnxRecord( + 1L, + "Sale", + "MMK 10,000", + "**** 1234", + "06/10 14:32", + isVoided = false, + isApproved = true + ), + TrnxRecord( + 2L, + "Void", + "MMK 5,500", + "**** 5678", + "06/10 13:10", + isVoided = true, + isApproved = false + ), + TrnxRecord( + 3L, + "Refund", + "MMK 2,000", + "**** 9012", + "06/09 09:45", + isVoided = false, + isApproved = true + ), + TrnxRecord( + 4L, + "Sale", + "MMK 30,000", + "**** 3456", + "06/09 08:00", + isVoided = false, + isApproved = true + ), + TrnxRecord( + 5L, + "Settlement", + "MMK 0", + "----", + "06/08 18:00", + isVoided = false, + isApproved = true + ), ) @P3Preview diff --git a/app/src/main/java/com/mob/utsmyanmar/ui/navigation/AppNavGraph.kt b/app/src/main/java/com/mob/utsmyanmar/ui/navigation/AppNavGraph.kt index c9620f2..7deac01 100644 --- a/app/src/main/java/com/mob/utsmyanmar/ui/navigation/AppNavGraph.kt +++ b/app/src/main/java/com/mob/utsmyanmar/ui/navigation/AppNavGraph.kt @@ -20,6 +20,7 @@ import com.mob.utsmyanmar.ui.cardwaiting.CardWaitingViewModel import com.mob.utsmyanmar.ui.dashboard.DashboardScreen2 import com.mob.utsmyanmar.ui.dashboard.DashboardViewModel import com.mob.utsmyanmar.ui.device_info.DeviceInfoViewModel +import com.mob.utsmyanmar.ui.disable.DisableScreen import com.mob.utsmyanmar.ui.functions.FunctionsScreen import com.mob.utsmyanmar.ui.input_amount.AmountRoute import com.mob.utsmyanmar.ui.notification.NotificationDetailScreen @@ -41,7 +42,6 @@ import com.mob.utsmyanmar.ui.settlement.SettlementScreen import com.mob.utsmyanmar.ui.settlement.SettlementViewModel import com.mob.utsmyanmar.ui.sign_on.SignOnResultScreen import com.mob.utsmyanmar.ui.sign_on.SignOnRoute -import com.mob.utsmyanmar.ui.disable.DisableScreen import com.mob.utsmyanmar.ui.tms_setup.TmsSetupRoute import com.mob.utsmyanmar.ui.tms_setup.TmsSetupViewModel import com.mob.utsmyanmar.ui.transaction_result.TransactionResultEvent @@ -108,6 +108,7 @@ fun AppNavGraph( val dashboardUiState by dashboardViewModel.uiState.collectAsStateWithLifecycle() val deviceInfoViewModel: DeviceInfoViewModel = hiltViewModel() val deviceInfo by deviceInfoViewModel.uiState.collectAsStateWithLifecycle() + val tmsSetupViewModel: TmsSetupViewModel = hiltViewModel() androidx.compose.runtime.LaunchedEffect(Unit) { deviceInfoViewModel.loadDeviceInfo() } DashboardScreen2( dashboardUiState = dashboardUiState, @@ -148,6 +149,9 @@ fun AppNavGraph( }, onNavigateNotifications = { navController.navigate(Routes.NotificationList.route) { launchSingleTop = true } + }, + onClickLastSync = { + tmsSetupViewModel.downloadConfigs() } ) } diff --git a/app/src/main/java/com/mob/utsmyanmar/ui/tms_setup/TmsSetupViewModel.kt b/app/src/main/java/com/mob/utsmyanmar/ui/tms_setup/TmsSetupViewModel.kt index c463169..3706629 100644 --- a/app/src/main/java/com/mob/utsmyanmar/ui/tms_setup/TmsSetupViewModel.kt +++ b/app/src/main/java/com/mob/utsmyanmar/ui/tms_setup/TmsSetupViewModel.kt @@ -150,27 +150,6 @@ class TmsSetupViewModel @Inject constructor( viewModelScope.launch { _navigateToDashboard.emit(Unit) } } -// private fun formatNetworkError(error: Throwable): String { -// return when (error) { -// is javax.net.ssl.SSLHandshakeException -> -// "SSL handshake failed: ${error.message ?: "Certificate or protocol mismatch"}" -// is javax.net.ssl.SSLException -> -// "SSL/TLS error: ${error.message ?: "Secure connection could not be established"}" -// is java.security.cert.CertificateException -> -// "Server certificate error: ${error.message ?: "Certificate is invalid or untrusted"}" -// is java.net.UnknownHostException -> -// "Host not found: ${error.message ?: "Check server URL and network connection"}" -// is java.net.ConnectException -> -// "Connection refused: ${error.message ?: "Server is unreachable"}" -// is java.net.SocketTimeoutException -> -// "Connection timed out: ${error.message ?: "Server did not respond in time"}" -// is retrofit2.HttpException -> -// "HTTP ${error.code()} ${error.message()}" -// else -> -// error.message ?: "Unknown network error" -// } -// } - @SuppressLint("MissingPermission") private fun buildRequest(): SiriusRequest { return try {