MPU card reading data
This commit is contained in:
parent
37a1a2e38d
commit
d44163b601
@ -1,6 +1,8 @@
|
|||||||
package com.mob.utsmyanmar.ui.navigation
|
package com.mob.utsmyanmar.ui.navigation
|
||||||
|
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
@ -8,17 +10,26 @@ import androidx.navigation.NavType
|
|||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.navArgument
|
import androidx.navigation.navArgument
|
||||||
|
import com.mob.utsmyanmar.model.ProcessCode
|
||||||
import com.mob.utsmyanmar.ui.amount.AmountScreen
|
import com.mob.utsmyanmar.ui.amount.AmountScreen
|
||||||
import com.mob.utsmyanmar.ui.cardwaiting.CardWaitingScreen
|
import com.mob.utsmyanmar.ui.cardwaiting.CardWaitingScreen
|
||||||
import com.mob.utsmyanmar.ui.cardwaiting.CardWaitingViewModel
|
import com.mob.utsmyanmar.ui.cardwaiting.CardWaitingViewModel
|
||||||
import com.mob.utsmyanmar.ui.dashboard.DashboardScreen
|
import com.mob.utsmyanmar.ui.dashboard.DashboardScreen
|
||||||
|
import com.mob.utsmyanmar.ui.processing_card.ProcessingCardRoute
|
||||||
|
import com.mob.utsmyanmar.ui.processing_card.ProcessingCardViewModel
|
||||||
import com.mob.utsmyanmar.viewmodel.CardReaderViewModel
|
import com.mob.utsmyanmar.viewmodel.CardReaderViewModel
|
||||||
|
import com.mob.utsmyanmar.viewmodel.EmvTransactionProcessViewModel
|
||||||
|
import com.mob.utsmyanmar.viewmodel.PinPadViewModel
|
||||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||||
|
import com.mob.utsmyanmar.viewmodel.TransProcessViewModel
|
||||||
|
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AppNavGraph(
|
fun AppNavGraph(
|
||||||
navController: NavHostController
|
navController: NavHostController
|
||||||
) {
|
) {
|
||||||
|
val activity = LocalContext.current as ComponentActivity
|
||||||
|
|
||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
startDestination = Routes.Dashboard.route
|
startDestination = Routes.Dashboard.route
|
||||||
@ -46,19 +57,29 @@ fun AppNavGraph(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
) { backStackEntry ->
|
) { backStackEntry ->
|
||||||
|
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||||
|
|
||||||
AmountScreen(
|
AmountScreen(
|
||||||
action = backStackEntry.arguments?.getString("action").orEmpty(),
|
action = backStackEntry.arguments?.getString("action").orEmpty(),
|
||||||
onBackClick = { navController.popBackStack() },
|
onBackClick = { navController.popBackStack() },
|
||||||
onCancelClick = { navController.popBackStack() },
|
onCancelClick = { navController.popBackStack() },
|
||||||
onNextClick = {
|
onNextClick = { amount ->
|
||||||
|
sharedViewModel.amount.value = amount
|
||||||
|
sharedViewModel.setAmountExist(true)
|
||||||
|
sharedViewModel.setCardDataExist(false)
|
||||||
|
sharedViewModel.setTransMenu(null)
|
||||||
|
sharedViewModel.transactionsType.value = TransactionsType.SALE
|
||||||
|
sharedViewModel.processCode.value =
|
||||||
|
ProcessCode.SALE_PURCHASE + ProcessCode.SMART + ProcessCode.TO_ACCOUNT
|
||||||
|
|
||||||
navController.navigate(Routes.CardWaiting.route)
|
navController.navigate(Routes.CardWaiting.route)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(Routes.CardWaiting.route) {
|
composable(Routes.CardWaiting.route) {
|
||||||
val sharedViewModel: SharedViewModel = hiltViewModel()
|
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||||
val cardReaderViewModel: CardReaderViewModel = hiltViewModel()
|
val cardReaderViewModel: CardReaderViewModel = hiltViewModel(activity)
|
||||||
val cardWaitingViewModel: CardWaitingViewModel = viewModel(
|
val cardWaitingViewModel: CardWaitingViewModel = viewModel(
|
||||||
factory = CardWaitingViewModel.provideFactory(
|
factory = CardWaitingViewModel.provideFactory(
|
||||||
cardReadViewModel = cardReaderViewModel,
|
cardReadViewModel = cardReaderViewModel,
|
||||||
@ -69,7 +90,9 @@ fun AppNavGraph(
|
|||||||
CardWaitingScreen(
|
CardWaitingScreen(
|
||||||
viewModel = cardWaitingViewModel,
|
viewModel = cardWaitingViewModel,
|
||||||
onManualEntry = {},
|
onManualEntry = {},
|
||||||
onProcessingCard = {},
|
onProcessingCard = {
|
||||||
|
navController.navigate(Routes.ProcessingCard.route)
|
||||||
|
},
|
||||||
onTimeout = { navController.popBackStack() },
|
onTimeout = { navController.popBackStack() },
|
||||||
onBack = { navController.popBackStack() },
|
onBack = { navController.popBackStack() },
|
||||||
onMain = {
|
onMain = {
|
||||||
@ -82,5 +105,33 @@ fun AppNavGraph(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
composable(Routes.ProcessingCard.route) {
|
||||||
|
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||||
|
val cardReaderViewModel: CardReaderViewModel = hiltViewModel(activity)
|
||||||
|
val transProcessViewModel: TransProcessViewModel = hiltViewModel(activity)
|
||||||
|
val pinPadViewModel: PinPadViewModel = hiltViewModel(activity)
|
||||||
|
val emvTransactionViewModel: EmvTransactionProcessViewModel = hiltViewModel(activity)
|
||||||
|
val processingCardViewModel: ProcessingCardViewModel = viewModel(
|
||||||
|
factory = ProcessingCardViewModel.provideFactory(
|
||||||
|
cardReadViewModel = cardReaderViewModel,
|
||||||
|
sharedViewModel = sharedViewModel,
|
||||||
|
transProcessViewModel = transProcessViewModel,
|
||||||
|
pinPadViewModel = pinPadViewModel,
|
||||||
|
emvTransactionViewModel = emvTransactionViewModel
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
ProcessingCardRoute(
|
||||||
|
viewModel = processingCardViewModel,
|
||||||
|
onNavigatePinPad = {},
|
||||||
|
onNavigateInputAmount = { navController.popBackStack(Routes.Amount.route, false) },
|
||||||
|
onNavigateProcessing = {},
|
||||||
|
onNavigateEmvTransaction = {},
|
||||||
|
onNavigateError = {},
|
||||||
|
onBack = { navController.popBackStack() },
|
||||||
|
onShowDecline = {}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,4 +6,5 @@ sealed class Routes(val route: String) {
|
|||||||
fun createRoute(action: String): String = "amount/$action"
|
fun createRoute(action: String): String = "amount/$action"
|
||||||
}
|
}
|
||||||
data object CardWaiting : Routes("card_waiting")
|
data object CardWaiting : Routes("card_waiting")
|
||||||
|
data object ProcessingCard : Routes("processing_card")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,13 +2,12 @@ package com.mob.utsmyanmar.ui.processing_card
|
|||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ProcessingCardRoute(
|
fun ProcessingCardRoute(
|
||||||
viewModel: ProcessingCardViewModel = hiltViewModel(),
|
viewModel: ProcessingCardViewModel,
|
||||||
onNavigatePinPad: () -> Unit,
|
onNavigatePinPad: () -> Unit,
|
||||||
onNavigateInputAmount: () -> Unit,
|
onNavigateInputAmount: () -> Unit,
|
||||||
onNavigateProcessing: () -> Unit,
|
onNavigateProcessing: () -> Unit,
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package com.mob.utsmyanmar.ui.processing_card
|
|||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.mob.utsmyanmar.model.CardTransactionType
|
import com.mob.utsmyanmar.model.CardTransactionType
|
||||||
import com.mob.utsmyanmar.utils.TransactionUtil
|
import com.mob.utsmyanmar.utils.TransactionUtil
|
||||||
@ -24,17 +25,14 @@ import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
|
|||||||
import com.utsmyanmar.paylibs.utils.enums.TransMenu
|
import com.utsmyanmar.paylibs.utils.enums.TransMenu
|
||||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType
|
||||||
import com.utsmyanmar.paylibs.utils.params.Params
|
import com.utsmyanmar.paylibs.utils.params.Params
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.receiveAsFlow
|
import kotlinx.coroutines.flow.receiveAsFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import sunmi.sunmiui.utils.LogUtil
|
import sunmi.sunmiui.utils.LogUtil
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@HiltViewModel
|
class ProcessingCardViewModel(
|
||||||
class ProcessingCardViewModel @Inject constructor(
|
|
||||||
private val cardReadViewModel: CardReaderViewModel,
|
private val cardReadViewModel: CardReaderViewModel,
|
||||||
private val sharedViewModel: SharedViewModel,
|
private val sharedViewModel: SharedViewModel,
|
||||||
private val transProcessViewModel: TransProcessViewModel,
|
private val transProcessViewModel: TransProcessViewModel,
|
||||||
@ -42,6 +40,31 @@ class ProcessingCardViewModel @Inject constructor(
|
|||||||
private val emvTransactionViewModel: EmvTransactionProcessViewModel
|
private val emvTransactionViewModel: EmvTransactionProcessViewModel
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val TAG = ProcessingCardViewModel::class.java.simpleName
|
||||||
|
|
||||||
|
fun provideFactory(
|
||||||
|
cardReadViewModel: CardReaderViewModel,
|
||||||
|
sharedViewModel: SharedViewModel,
|
||||||
|
transProcessViewModel: TransProcessViewModel,
|
||||||
|
pinPadViewModel: PinPadViewModel,
|
||||||
|
emvTransactionViewModel: EmvTransactionProcessViewModel
|
||||||
|
): ViewModelProvider.Factory {
|
||||||
|
return object : ViewModelProvider.Factory {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||||
|
return ProcessingCardViewModel(
|
||||||
|
cardReadViewModel = cardReadViewModel,
|
||||||
|
sharedViewModel = sharedViewModel,
|
||||||
|
transProcessViewModel = transProcessViewModel,
|
||||||
|
pinPadViewModel = pinPadViewModel,
|
||||||
|
emvTransactionViewModel = emvTransactionViewModel
|
||||||
|
) as T
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val _state = MutableStateFlow(ProcessingCardState())
|
private val _state = MutableStateFlow(ProcessingCardState())
|
||||||
val state = _state.asStateFlow()
|
val state = _state.asStateFlow()
|
||||||
|
|
||||||
@ -259,7 +282,4 @@ class ProcessingCardViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val TAG = ProcessingCardViewModel::class.java.simpleName
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user