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