refresh last sync
This commit is contained in:
parent
d011b46345
commit
752693c8f3
@ -11,7 +11,6 @@
|
||||
|
||||
### version 3.4
|
||||
* disable display always on
|
||||
|
||||
* auto-settlement
|
||||
* show expiry date as "`**`/`**`"
|
||||
* align the customer name, in paper slip
|
||||
|
||||
@ -746,10 +746,15 @@ fun AppNavGraph(
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
val transProcessViewModel: TransProcessViewModel = hiltViewModel(activity)
|
||||
val settlementViewModel: SettlementViewModel = hiltViewModel(activity)
|
||||
val tmsSetupViewModel: TmsSetupViewModel = hiltViewModel(activity)
|
||||
val dashboardViewModel: DashboardViewModel = hiltViewModel(activity)
|
||||
ProcessingRoute(
|
||||
sharedViewModel = sharedViewModel,
|
||||
transProcessViewModel = transProcessViewModel,
|
||||
settlementViewModel = settlementViewModel,
|
||||
onTransactionFinished = {
|
||||
tmsSetupViewModel.downloadConfigs(dashboardViewModel::refreshLastSyncTime)
|
||||
},
|
||||
onNavigateTransactionResult = {
|
||||
navController.navigate(Routes.TransactionResult.route) {
|
||||
popUpTo(Routes.Processing.route) {
|
||||
@ -808,14 +813,10 @@ fun AppNavGraph(
|
||||
composable(Routes.TransactionResult.route) {
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
val transResultViewModel: TransactionResultViewModel = hiltViewModel(activity)
|
||||
val tmsSetupViewModel: TmsSetupViewModel = hiltViewModel(activity)
|
||||
val dashboardViewModel: DashboardViewModel = hiltViewModel(activity)
|
||||
|
||||
TransactionResultRoute(
|
||||
viewModel = transResultViewModel,
|
||||
sharedViewModel = sharedViewModel,
|
||||
tmsSetupViewModel = tmsSetupViewModel,
|
||||
dashboardViewModel = dashboardViewModel,
|
||||
onNavigateMain = {
|
||||
navController.navigate(Routes.Dashboard.route) {
|
||||
popUpTo(Routes.Dashboard.route) {
|
||||
|
||||
@ -21,7 +21,8 @@ fun ProcessingRoute(
|
||||
settlementViewModel: SettlementViewModel,
|
||||
onNavigateTransactionResult: () -> Unit,
|
||||
onNavigateSignature: () -> Unit,
|
||||
onNavigateError: (Boolean, String) -> Unit
|
||||
onNavigateError: (Boolean, String) -> Unit,
|
||||
onTransactionFinished: () -> Unit
|
||||
) {
|
||||
|
||||
val transStatus by transProcessViewModel.transResultStatus.collectAsStateWithLifecycle()
|
||||
@ -39,6 +40,7 @@ fun ProcessingRoute(
|
||||
when(settlementStatus.status) {
|
||||
TransactionStatus.ON_ERROR,
|
||||
TransactionStatus.ON_SUCCESS -> {
|
||||
onTransactionFinished()
|
||||
sharedViewModel.payDetail.value = settlementViewModel.getPayDetail()
|
||||
onNavigateTransactionResult()
|
||||
}
|
||||
@ -54,6 +56,7 @@ fun ProcessingRoute(
|
||||
LaunchedEffect(transStatus) {
|
||||
when(transStatus) {
|
||||
TransResultStatus.SUCCESS -> {
|
||||
onTransactionFinished()
|
||||
sharedViewModel.payDetail.value = transProcessViewModel.payDetailResult.value
|
||||
if (requiresSignature(sharedViewModel.transactionsType.value, sharedViewModel.payDetail.value)) {
|
||||
onNavigateSignature()
|
||||
@ -63,18 +66,22 @@ fun ProcessingRoute(
|
||||
}
|
||||
|
||||
TransResultStatus.FAIL -> {
|
||||
onTransactionFinished()
|
||||
sharedViewModel.payDetail.value = transProcessViewModel.payDetailResult.value
|
||||
onNavigateTransactionResult()
|
||||
}
|
||||
TransResultStatus.REVERSAL_SUCCESS -> {
|
||||
onTransactionFinished()
|
||||
onNavigateError(true,"Reversal success")
|
||||
}
|
||||
|
||||
TransResultStatus.REVERSAL_FAIL -> {
|
||||
onTransactionFinished()
|
||||
onNavigateError(false,"Reversal failed")
|
||||
}
|
||||
|
||||
TransResultStatus.ERROR -> {
|
||||
onTransactionFinished()
|
||||
onNavigateError(false,
|
||||
transProcessViewModel.errorMessage.value?.takeIf { it.isNotBlank() }
|
||||
?: "Something went wrong. Please try again."
|
||||
|
||||
@ -74,7 +74,7 @@ class TmsSetupViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun downloadConfigs() {
|
||||
fun downloadConfigs(onSuccess: () -> Unit = {}) {
|
||||
_uiState.update {
|
||||
it.copy(isLoading = true, isError = false, statusText = "Connecting to TMS server...")
|
||||
}
|
||||
@ -99,7 +99,7 @@ class TmsSetupViewModel @Inject constructor(
|
||||
)
|
||||
|
||||
tmsSetups.initParams(appResponse, TMSUpdate.UPDATE, emvParamOperation)
|
||||
onConfigApplied()
|
||||
onConfigApplied(onSuccess)
|
||||
},
|
||||
{ error ->
|
||||
val errorMessage = if (error is retrofit2.HttpException) {
|
||||
@ -141,7 +141,7 @@ class TmsSetupViewModel @Inject constructor(
|
||||
|
||||
}
|
||||
|
||||
private fun onConfigApplied() {
|
||||
private fun onConfigApplied(onSuccess: () -> Unit) {
|
||||
val ops = SystemParamsOperation.getInstance()
|
||||
|
||||
if (!ops.isActive) {
|
||||
@ -166,6 +166,7 @@ class TmsSetupViewModel @Inject constructor(
|
||||
.edit {
|
||||
putLong("last_sync_time", System.currentTimeMillis())
|
||||
}
|
||||
onSuccess()
|
||||
_uiState.update { it.copy(isLoading = false, statusText = "Ready.") }
|
||||
viewModelScope.launch {
|
||||
_onSyncCompleted.emit(Unit)
|
||||
|
||||
@ -5,8 +5,6 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.mob.utsmyanmar.ui.dashboard.DashboardViewModel
|
||||
import com.mob.utsmyanmar.ui.tms_setup.TmsSetupViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||
|
||||
@ -18,9 +16,7 @@ fun TransactionResultRoute(
|
||||
onNavigatePrintReceipt: () -> Unit,
|
||||
onShowError: (String) -> Unit,
|
||||
onShowSuccess: (String) -> Unit,
|
||||
onShowPrinterDialog: (String) -> Unit,
|
||||
tmsSetupViewModel: TmsSetupViewModel,
|
||||
dashboardViewModel: DashboardViewModel,
|
||||
onShowPrinterDialog: (String) -> Unit
|
||||
) {
|
||||
val state by viewModel.state.collectAsStateWithLifecycle()
|
||||
val canGoBack = sharedViewModel.transactionsType.value != TransactionsType.SALE
|
||||
@ -30,8 +26,6 @@ fun TransactionResultRoute(
|
||||
TransactionResultEvent.Start,
|
||||
sharedViewModel
|
||||
)
|
||||
dashboardViewModel.refreshLastSyncTime()
|
||||
tmsSetupViewModel.downloadConfigs()
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user