animation added
This commit is contained in:
parent
ff2858d484
commit
f4fc2fa730
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@
|
||||
.cxx
|
||||
local.properties
|
||||
/.idea
|
||||
/.idea
|
||||
|
||||
@ -57,5 +57,6 @@
|
||||
<option name="composableFile" value="true" />
|
||||
<option name="previewFile" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="UsePropertyAccessSyntax" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
@ -19,6 +19,7 @@ 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.sending_to_host.SendingToHostRoute
|
||||
import com.mob.utsmyanmar.ui.transaction_result.TransactionResultRoute
|
||||
import com.mob.utsmyanmar.viewmodel.CardReaderViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.EmvTransactionProcessViewModel
|
||||
@ -153,8 +154,8 @@ fun AppNavGraph(
|
||||
pinPadViewModel = pinPadViewModel,
|
||||
sharedViewModel = sharedViewModel,
|
||||
transProcessViewModel = transProcessViewModel,
|
||||
onNavigateTransactionResult = {
|
||||
navController.navigate(Routes.TransactionResult.route) {
|
||||
onNavigateSendingToHost = {
|
||||
navController.navigate(Routes.SendingToHost.route) {
|
||||
popUpTo(Routes.PinPad.route) {
|
||||
inclusive = true
|
||||
}
|
||||
@ -165,6 +166,19 @@ fun AppNavGraph(
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.SendingToHost.route) {
|
||||
SendingToHostRoute(
|
||||
onNavigateTransactionResult = {
|
||||
navController.navigate(Routes.TransactionResult.route) {
|
||||
popUpTo(Routes.SendingToHost.route) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
composable(Routes.TransactionResult.route) {
|
||||
val sharedViewModel: SharedViewModel = hiltViewModel(activity)
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ sealed class Routes(val route: String) {
|
||||
data object CardWaiting : Routes("card_waiting")
|
||||
data object ProcessingCard : Routes("processing_card")
|
||||
data object PinPad : Routes("pin_pad")
|
||||
data object SendingToHost : Routes("sending_to_host")
|
||||
data object TransactionResult : Routes("transaction_result")
|
||||
data object PrintReceipt : Routes("print_receipt")
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ fun PinPadRoute(
|
||||
pinPadViewModel: PinPadViewModel,
|
||||
sharedViewModel: SharedViewModel,
|
||||
transProcessViewModel: TransProcessViewModel,
|
||||
onNavigateTransactionResult: () -> Unit,
|
||||
onNavigateSendingToHost: () -> Unit,
|
||||
onBack: () -> Unit
|
||||
) {
|
||||
val pinText by pinPadViewModel.pinText.collectAsStateWithLifecycle()
|
||||
@ -37,7 +37,7 @@ fun PinPadRoute(
|
||||
payDetail?.tradeAnswerCode = Constant.ANSWER_CODE_APPROVED
|
||||
sharedViewModel.payDetail.value = payDetail
|
||||
transProcessViewModel.resetTransactionStatus()
|
||||
onNavigateTransactionResult()
|
||||
onNavigateSendingToHost()
|
||||
}
|
||||
|
||||
PinPadStatus.ON_CANCEL,
|
||||
|
||||
@ -2,6 +2,9 @@ package com.mob.utsmyanmar.ui.print_receipt
|
||||
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.core.Animatable
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.*
|
||||
@ -15,40 +18,47 @@ import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
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
|
||||
import com.mob.utsmyanmar.ui.theme.Primary
|
||||
import com.mob.utsmyanmar.ui.theme.White
|
||||
import com.utsmyanmar.paylibs.print.NewPrintReceipt
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
import com.utsmyanmar.paylibs.print.PrintReceipt
|
||||
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun PrintReceiptScreen(
|
||||
onPrint: () -> Unit,
|
||||
onDone: () -> Unit
|
||||
) {
|
||||
BackHandler {
|
||||
onDone()
|
||||
|
||||
val scope = rememberCoroutineScope();
|
||||
val receiptOffsetY = remember {
|
||||
Animatable(0f);
|
||||
}
|
||||
val animationDuration = 3000;
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AppBar(title = "Receipt")
|
||||
}
|
||||
},
|
||||
containerColor = Color.IvoryBeige
|
||||
) { paddingValues ->
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(paddingValues)
|
||||
.fillMaxSize()
|
||||
.background(Color(0xFFF5F5F5))
|
||||
.padding(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
@ -57,6 +67,9 @@ fun PrintReceiptScreen(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.graphicsLayer{
|
||||
translationY = receiptOffsetY.value
|
||||
}
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
@ -87,18 +100,41 @@ fun PrintReceiptScreen(
|
||||
.weight(1f)
|
||||
.height(50.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Primary,
|
||||
contentColor = White,
|
||||
disabledContainerColor = Primary,
|
||||
disabledContentColor = White,
|
||||
containerColor = Color.LegacyRed,
|
||||
contentColor = Color.White,
|
||||
disabledContainerColor = Color.LegacyRed.copy(alpha = 0.5f),
|
||||
disabledContentColor = Color.White.copy(alpha = 0.5f),
|
||||
),
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
onClick = {
|
||||
onPrint()
|
||||
// onPrint()
|
||||
try {
|
||||
NewPrintReceipt.getInstance().testPrint()
|
||||
PrintReceipt.getInstance().printNow()
|
||||
scope.launch {
|
||||
launch {
|
||||
receiptOffsetY.animateTo(
|
||||
targetValue = -1500f,
|
||||
animationSpec = tween(
|
||||
durationMillis = animationDuration,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
)
|
||||
}
|
||||
delay(5000)
|
||||
launch {
|
||||
receiptOffsetY.animateTo(
|
||||
targetValue = 0f,
|
||||
animationSpec = tween(
|
||||
durationMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
||||
Log.d("PrintReceipt", "error with $e")
|
||||
|
||||
}
|
||||
}
|
||||
) {
|
||||
@ -116,6 +152,7 @@ fun PrintReceiptScreen(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun ReceiptPreview(
|
||||
modifier: Modifier = Modifier
|
||||
@ -127,32 +164,26 @@ fun ReceiptPreview(
|
||||
.background(Color.White)
|
||||
.border(
|
||||
width = 1.dp,
|
||||
color = Color.LightGray,
|
||||
color = Color.Gray,
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
)
|
||||
.padding(20.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
Text(
|
||||
text = "MOB POS",
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontFamily = FontFamily.Monospace
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Text(
|
||||
text = "Transaction Receipt",
|
||||
fontSize = 14.sp,
|
||||
fontFamily = FontFamily.Monospace
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
ReceiptDivider()
|
||||
|
||||
ReceiptRow("Merchant", "MOB UTS Myanmar")
|
||||
ReceiptRow("Terminal ID", "POS001")
|
||||
ReceiptRow("Transaction", "SALE")
|
||||
@ -163,11 +194,8 @@ fun ReceiptPreview(
|
||||
ReceiptRow("Date", "13/05/2026")
|
||||
ReceiptRow("Time", "14:30:22")
|
||||
ReceiptRow("Ref No", "REF123456789")
|
||||
|
||||
ReceiptDivider()
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Text(
|
||||
text = "Thank You",
|
||||
fontSize = 16.sp,
|
||||
@ -200,7 +228,7 @@ fun ReceiptRow(
|
||||
text = label,
|
||||
fontSize = 13.sp,
|
||||
fontFamily = FontFamily.Monospace,
|
||||
color = Color.DarkGray
|
||||
color = Color.Gray
|
||||
)
|
||||
|
||||
Text(
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
package com.mob.utsmyanmar.ui.sending_to_host
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
private const val MOCK_HOST_DELAY_MS = 2000L
|
||||
|
||||
@Composable
|
||||
fun SendingToHostRoute(
|
||||
onNavigateTransactionResult: () -> Unit
|
||||
) {
|
||||
LaunchedEffect(Unit) {
|
||||
delay(MOCK_HOST_DELAY_MS)
|
||||
onNavigateTransactionResult()
|
||||
}
|
||||
|
||||
SendingToHostScreen()
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
package com.mob.utsmyanmar.ui.sending_to_host
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
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.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.mob.utsmyanmar.ui.theme.Black
|
||||
import com.mob.utsmyanmar.ui.theme.Primary
|
||||
import com.mob.utsmyanmar.ui.theme.White
|
||||
|
||||
@Composable
|
||||
fun SendingToHostScreen() {
|
||||
Scaffold(
|
||||
containerColor = White
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.background(White)
|
||||
.padding(horizontal = 24.dp, vertical = 32.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
color = Primary,
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
.padding(horizontal = 24.dp, vertical = 32.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
CircularProgressIndicator(color = White)
|
||||
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
|
||||
Text(
|
||||
text = "Sending Data",
|
||||
color = White,
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(10.dp))
|
||||
|
||||
Text(
|
||||
text = "Please wait while we send transaction data to host.",
|
||||
color = White,
|
||||
fontSize = 15.sp,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
|
||||
Text(
|
||||
text = "Mock host communication in progress.",
|
||||
color = Black,
|
||||
fontSize = 14.sp,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user