dialog box in last sync
This commit is contained in:
parent
f08702125c
commit
c3faee2eb0
@ -23,6 +23,9 @@ import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.material.icons.filled.Notifications
|
||||
import androidx.compose.material.icons.filled.Sync
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.DrawerValue
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
@ -47,6 +50,7 @@ import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import com.mob.utsmyanmar.R
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.mob.utsmyanmar.ui.device_info.DeviceInfoUiState
|
||||
@ -176,6 +180,29 @@ fun DashboardScreen2(
|
||||
)
|
||||
}
|
||||
|
||||
if (dashboardUiState.isSyncing) {
|
||||
Dialog(onDismissRequest = {}) {
|
||||
Card(
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||
elevation = CardDefaults.cardElevation(8.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(32.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
CircularProgressIndicator(color = Color.LegacyRed)
|
||||
Spacer(Modifier.height(16.dp))
|
||||
Text(
|
||||
text = dashboardUiState.syncStatusText,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = Color.Black
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ModalNavigationDrawer(
|
||||
drawerState = drawerState,
|
||||
drawerContent = {
|
||||
|
||||
@ -17,5 +17,7 @@ data class DashboardUiState(
|
||||
val totalSaleCount: Int = 0,
|
||||
val totalSaleAmount: Long = 0L,
|
||||
val settlementStatusText: String = "Pending",
|
||||
val settlementDateTimeText: String = "--/-- --:--"
|
||||
val settlementDateTimeText: String = "--/-- --:--",
|
||||
val isSyncing: Boolean = false,
|
||||
val syncStatusText: String = "Connecting to TMS server..."
|
||||
)
|
||||
|
||||
@ -72,6 +72,18 @@ class DashboardViewModel @Inject constructor(
|
||||
.takeIf { it > 0L }
|
||||
_uiState.update { it.copy(lastSyncTime = time) }
|
||||
}
|
||||
|
||||
fun startSync() {
|
||||
_uiState.update { it.copy(isSyncing = true, syncStatusText = "Connecting to TMS server...") }
|
||||
}
|
||||
|
||||
fun finishSync(message: String) {
|
||||
_uiState.update { it.copy(syncStatusText = message) }
|
||||
viewModelScope.launch {
|
||||
kotlinx.coroutines.delay(1500)
|
||||
_uiState.update { it.copy(isSyncing = false) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun PayDetail.toRecord(): TrnxRecord {
|
||||
|
||||
@ -125,6 +125,15 @@ fun AppNavGraph(
|
||||
LaunchedEffect(tmsSetupViewModel) {
|
||||
tmsSetupViewModel.onSyncCompleted.collect {
|
||||
dashboardViewModel.refreshLastSyncTime()
|
||||
dashboardViewModel.finishSync("Sync completed")
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(tmsSetupUiState.isLoading, tmsSetupUiState.isError) {
|
||||
if (dashboardUiState.isSyncing && !tmsSetupUiState.isLoading) {
|
||||
if (tmsSetupUiState.isError) {
|
||||
dashboardViewModel.finishSync(tmsSetupUiState.statusText.ifBlank { "Download failed!" })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,6 +153,7 @@ fun AppNavGraph(
|
||||
dashboardUiState = dashboardUiState,
|
||||
deviceInfo = deviceInfoUiState,
|
||||
onClickLastSync = {
|
||||
dashboardViewModel.startSync()
|
||||
tmsSetupViewModel.downloadConfigs()
|
||||
},
|
||||
onNavigateRecentTransaction = { record ->
|
||||
|
||||
Loading…
Reference in New Issue
Block a user