optimize webview
This commit is contained in:
@@ -24,7 +24,10 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.PSP"
|
||||
android:usesCleartextTraffic="true">
|
||||
android:usesCleartextTraffic="true"
|
||||
android:hardwareAccelerated="true"
|
||||
|
||||
>
|
||||
<uses-library android:name="android.device" android:required="false" />
|
||||
|
||||
<activity
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package com.example.tis_app
|
||||
|
||||
import android.app.Application
|
||||
import com.example.design_system.util.WebViewManager
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
|
||||
@HiltAndroidApp
|
||||
class PspApplication : Application()
|
||||
class PspApplication : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
WebViewManager.preload(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -15,9 +17,10 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.example.core.getAndroidId
|
||||
import com.example.core.getDeviceName
|
||||
import com.example.design_system.PspWebView
|
||||
import com.example.design_system.util.WebViewManager
|
||||
import com.example.tis_app.viewmodel.WebViewModel
|
||||
|
||||
private const val tisIp = "194.59.214.243:8090"
|
||||
private const val tisWebUrl = "https://tis.shift-am.ir"
|
||||
|
||||
@Composable
|
||||
fun TisWebViewScreen(
|
||||
@@ -26,8 +29,19 @@ fun TisWebViewScreen(
|
||||
) {
|
||||
|
||||
val context = LocalContext.current
|
||||
var webView: WebView? by remember { mutableStateOf(null) }
|
||||
var webView: WebView by remember { mutableStateOf(WebViewManager.getWebView(context)) }
|
||||
var currentPaymentId by rememberSaveable { mutableStateOf<String?>(null) }
|
||||
var isPaymentProcessing by rememberSaveable { mutableStateOf(false) }
|
||||
var isPrinting by rememberSaveable { mutableStateOf(false) }
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val deviceInfo by remember {
|
||||
mutableStateOf(
|
||||
viewModel.deviceInfoJson(
|
||||
androidId = getAndroidId(context),
|
||||
getDeviceName()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// launcher to handle POS app result
|
||||
val posLauncher = rememberLauncherForActivityResult(
|
||||
@@ -38,34 +52,40 @@ fun TisWebViewScreen(
|
||||
activityResult = result
|
||||
|
||||
)
|
||||
webView?.post {
|
||||
webView?.evaluateJavascript(
|
||||
|
||||
webView.post {
|
||||
webView.evaluateJavascript(
|
||||
viewModel.postPaymentResult(paymentResultEntity = paymentResultEntity),
|
||||
null
|
||||
)
|
||||
}
|
||||
isPaymentProcessing = false
|
||||
|
||||
}
|
||||
|
||||
PspWebView(
|
||||
url = tisIp,
|
||||
webView = webView,
|
||||
url = tisWebUrl,
|
||||
modifier = modifier,
|
||||
onWebView = { updatedWebView -> webView = updatedWebView },
|
||||
onPayClick = { amount: Long, id: String? ->
|
||||
if (isPaymentProcessing) return@PspWebView
|
||||
isPaymentProcessing = true
|
||||
currentPaymentId = id
|
||||
viewModel.pay(amount)
|
||||
.also(posLauncher::launch)
|
||||
},
|
||||
onPrintClick = { printEntities ->
|
||||
viewModel.print(printEntities)
|
||||
|
||||
if (isPrinting) return@PspWebView
|
||||
isPrinting = true
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
viewModel.print(printEntities)
|
||||
} finally {
|
||||
isPrinting = false
|
||||
}
|
||||
}
|
||||
},
|
||||
onDeviceInfo = {
|
||||
viewModel.deviceInfoJson(
|
||||
androidId = getAndroidId(context),
|
||||
getDeviceName()
|
||||
)
|
||||
deviceInfo
|
||||
}
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user