animation
This commit is contained in:
parent
782dde479a
commit
887af67ae7
@ -18,7 +18,7 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.mob.utsmyanmar"
|
||||
minSdk = 23
|
||||
minSdk = 25
|
||||
//noinspection OldTargetApi
|
||||
targetSdk = 36
|
||||
versionCode = 1
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
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.*
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
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.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
@ -20,8 +25,10 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@ -32,15 +39,19 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.mob.utsmyanmar.ui.components.appbar.AppBar
|
||||
import com.mob.utsmyanmar.ui.theme.Color
|
||||
import com.mob.utsmyanmar.ui.transaction_result.TransactionResultEvent
|
||||
import com.mob.utsmyanmar.ui.transaction_result.TransactionResultState
|
||||
import com.mob.utsmyanmar.ui.transaction_result.TransactionResultViewModel
|
||||
import com.mob.utsmyanmar.viewmodel.SharedViewModel
|
||||
import com.utsmyanmar.paylibs.print.PrintReceipt
|
||||
import com.utsmyanmar.paylibs.utils.POSUtil
|
||||
|
||||
import com.utsmyanmar.paylibs.utils.PrintStatus
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
private enum class ReceiptCopy(val label: String) {
|
||||
MERCHANT("MERCHANT COPY"),
|
||||
CUSTOMER("CUSTOMER COPY")
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PrintReceiptScreen(
|
||||
@ -50,12 +61,51 @@ fun PrintReceiptScreen(
|
||||
onDone: () -> Unit
|
||||
) {
|
||||
val state by transactionResultViewModel.state.collectAsStateWithLifecycle()
|
||||
val scope = rememberCoroutineScope();
|
||||
val receiptOffsetY = remember {
|
||||
Animatable(0f);
|
||||
}
|
||||
val animationDuration = 3000;
|
||||
val scope = rememberCoroutineScope()
|
||||
val receiptOffsetY = remember { Animatable(0f) }
|
||||
val animationDuration = 5000
|
||||
val isReprint = sharedViewModel.isReprint.value == true
|
||||
val merchant_copy_autoprint = true
|
||||
val customer_copy_autoprint = false
|
||||
var currentCopy by remember { mutableStateOf(if (isReprint) ReceiptCopy.CUSTOMER else ReceiptCopy.MERCHANT) }
|
||||
var nextCopy by remember { mutableStateOf(if (isReprint) ReceiptCopy.CUSTOMER else ReceiptCopy.CUSTOMER) }
|
||||
var isPrinting by remember { mutableStateOf(false) }
|
||||
|
||||
suspend fun animatePrint() {
|
||||
receiptOffsetY.animateTo(
|
||||
targetValue = -1500f,
|
||||
animationSpec = tween(durationMillis = animationDuration, easing = FastOutSlowInEasing)
|
||||
)
|
||||
delay(1000.milliseconds)
|
||||
receiptOffsetY.animateTo(
|
||||
targetValue = 0f,
|
||||
animationSpec = tween(durationMillis = 0, easing = FastOutSlowInEasing)
|
||||
)
|
||||
}
|
||||
|
||||
fun doPrint(copy: ReceiptCopy, onFinished: () -> Unit) {
|
||||
val actualCopy = if (isReprint && copy == ReceiptCopy.MERCHANT) ReceiptCopy.CUSTOMER else copy
|
||||
currentCopy = actualCopy
|
||||
sharedViewModel.setPrintStatus(
|
||||
if (actualCopy == ReceiptCopy.MERCHANT) PrintStatus.FIRST_PRINT else PrintStatus.SECOND_PRINT
|
||||
)
|
||||
onPrint()
|
||||
scope.launch {
|
||||
isPrinting = true
|
||||
animatePrint()
|
||||
isPrinting = false
|
||||
nextCopy = if (isReprint) ReceiptCopy.CUSTOMER
|
||||
else if (actualCopy == ReceiptCopy.MERCHANT) ReceiptCopy.CUSTOMER else ReceiptCopy.MERCHANT
|
||||
onFinished()
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
when {
|
||||
merchant_copy_autoprint && !isReprint -> doPrint(ReceiptCopy.MERCHANT) { }
|
||||
customer_copy_autoprint -> doPrint(ReceiptCopy.CUSTOMER) { }
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@ -74,10 +124,11 @@ fun PrintReceiptScreen(
|
||||
|
||||
ReceiptPreview(
|
||||
state = state,
|
||||
copyLabel = currentCopy.label,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.graphicsLayer{
|
||||
.graphicsLayer {
|
||||
translationY = receiptOffsetY.value
|
||||
}
|
||||
)
|
||||
@ -106,6 +157,7 @@ fun PrintReceiptScreen(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.height(50.dp),
|
||||
enabled = !isPrinting,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.LegacyRed,
|
||||
contentColor = Color.White,
|
||||
@ -114,35 +166,7 @@ fun PrintReceiptScreen(
|
||||
),
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
onClick = {
|
||||
onPrint()
|
||||
// try {
|
||||
// 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")
|
||||
//
|
||||
// }
|
||||
doPrint(nextCopy) { }
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
@ -160,6 +184,7 @@ fun PrintReceiptScreen(
|
||||
@Composable
|
||||
fun ReceiptPreview(
|
||||
state: TransactionResultState,
|
||||
copyLabel: String,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
@ -184,6 +209,12 @@ fun ReceiptPreview(
|
||||
text = "Transaction Receipt",
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(
|
||||
text = copyLabel,
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = Color.Gray
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ReceiptDivider()
|
||||
ReceiptRow("Merchant", state.payDetail?.merchantName.toString() )
|
||||
@ -224,16 +255,16 @@ fun ReceiptRow(
|
||||
.padding(vertical = 6.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = Color.Gray
|
||||
)
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = Color.Gray
|
||||
)
|
||||
|
||||
Text(
|
||||
text = value,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
Text(
|
||||
text = value,
|
||||
style = MaterialTheme.typography.titleSmall
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,4 +290,4 @@ fun PreviewPrintReceiptScreen() {
|
||||
onDone = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,7 @@ android {
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 23
|
||||
minSdk = 25
|
||||
//noinspection ExpiredTargetSdkVersion
|
||||
targetSdk = 30
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ android {
|
||||
compileSdk = 34
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 23
|
||||
minSdk = 25
|
||||
//noinspection ExpiredTargetSdkVersion
|
||||
targetSdk = 30
|
||||
|
||||
|
||||
@ -7,8 +7,8 @@ android {
|
||||
compileSdk = 34
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 23
|
||||
targetSdk = 30
|
||||
minSdk = 25
|
||||
targetSdk = 36
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
|
||||
@ -7,8 +7,8 @@ android {
|
||||
compileSdk = 34
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 23
|
||||
targetSdk = 30
|
||||
minSdk = 25
|
||||
targetSdk = 36
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
|
||||
@ -7,7 +7,7 @@ android {
|
||||
compileSdk = 34
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 23
|
||||
minSdk = 25
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles("consumer-rules.pro")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user