优化扫码枪支付

This commit is contained in:
mazengfei
2026-03-10 14:44:34 +08:00
parent 39c0ca7d72
commit 8a1630f2a4
8 changed files with 193 additions and 154 deletions
@@ -1,5 +1,7 @@
package com.sw.dualscreen.activity
import android.view.KeyEvent
import androidx.activity.OnBackPressedCallback
import androidx.activity.viewModels
import androidx.fragment.app.Fragment
import com.sw.dualscreen.GlobalKey
@@ -15,6 +17,7 @@ import com.sw.dualscreen.model.response.FoodInfo
import com.sw.dualscreen.model.response.MemberInfo
import com.sw.dualscreen.model.response.PaySuccessEvent
import com.sw.dualscreen.presentation.pay.PayPresentation
import com.sw.dualscreen.utils.Debouncer
import com.sw.dualscreen.utils.SPUtil
import com.sw.dualscreen.utils.SoundPoolUtil
import com.sw.dualscreen.viewmodel.BaseViewModel
@@ -81,7 +84,8 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
override fun initialize() {
super.initialize()
presentation.show()
registerKeyEvent()
addBackEventListener()
val soundMap = hashMapOf<String, Int>()
soundMap[PAY_SUCCESS] = R.raw.pay_success
SoundPoolUtil.getInstance().loadR(this, soundMap)
@@ -196,11 +200,15 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
presentation?.loadQrCodeImage(qrCodeUrl)
}
private var debouncer = Debouncer(5000)
fun showPaySuccess(isVip: Boolean) {
playSoundOnPaySuccess()
EventBus.getDefault().post(PaySuccessEvent())
showPayInfo(type = 2, isVip = isVip, memberInfo = memberInfo)
hidePayTab()
debouncer.debounce {
playSoundOnPaySuccess()
EventBus.getDefault().post(PaySuccessEvent())
showPayInfo(type = 2, isVip = isVip, memberInfo = memberInfo)
hidePayTab()
}
}
fun getQrCodeImg(
@@ -286,10 +294,11 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
}
}
override fun scanGunKeyEventCallback(scanInfo: String) {
super.scanGunKeyEventCallback(scanInfo)
fun qrCodePay(scanInfo: String) {
showWaitingDialog("支付中……")
userViewModel.qrCodePay(scanInfo, foodOrderId) { payState, backData ->
Timber.d("qrCodePay支付返回数据:state=$payState,backData=$backData")
hideWaitingDialog()
if (payState) {
showPaySuccess(false)
}
@@ -340,4 +349,12 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
// }
// }
// }
fun addBackEventListener() {
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
}
})
}
}