优化扫码枪支付
This commit is contained in:
@@ -59,7 +59,7 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
keyEventHelper?.onDestroy()
|
||||
keyEventHelper?.release()
|
||||
EventBus.getDefault().unregister(this)
|
||||
super.onDestroy()
|
||||
}
|
||||
@@ -153,7 +153,7 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
*/
|
||||
fun registerKeyEvent() {
|
||||
keyEventHelper =
|
||||
ScanGunKeyEventHelper(context, object : ScanGunKeyEventHelper.OnScanSuccessListener {
|
||||
ScanGunKeyEventHelper( object : ScanGunKeyEventHelper.OnScanSuccessListener {
|
||||
override fun onScanSuccess(barcode: String?) {
|
||||
Timber.d("onScanSuccess barcode = $barcode")
|
||||
if (barcode == null) return
|
||||
@@ -166,10 +166,13 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
/**
|
||||
* 处理扫描枪数据
|
||||
*/
|
||||
open fun scanGunKeyEventCallback(scanInfo: String) {
|
||||
Timber.tag("TAG").d("handleScanKeyInfo: $scanInfo")
|
||||
fun scanGunKeyEventCallback(scanInfo: String){
|
||||
if (this is PayActivity) {
|
||||
qrCodePay(scanInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
||||
if (keyEventHelper != null) {
|
||||
if (keyEventHelper!!.isScanGunEvent(event)) {
|
||||
|
||||
@@ -158,7 +158,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
}
|
||||
setupCamera()
|
||||
initData()
|
||||
registerKeyEvent()
|
||||
}
|
||||
|
||||
private fun initData() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -220,12 +220,10 @@ interface ApiService {
|
||||
* 二维码支付
|
||||
* @param orderType 0付款 1会员充值
|
||||
*/
|
||||
@GET
|
||||
@POST
|
||||
suspend fun qrCodePay(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/pay/app/qrCodePay",
|
||||
@Query("authCode") authCode: String,
|
||||
@Query("outTradeNo") orderNo: String,
|
||||
@Query("orderType") orderType:Int
|
||||
@Body param: HashMap<String, String>
|
||||
): ApiResponse<String?>
|
||||
|
||||
/**
|
||||
|
||||
@@ -191,7 +191,13 @@ class RemoteRepository constructor(
|
||||
*/
|
||||
suspend fun qrCodePay(authCode: String,orderNo: String): ApiResponse<String?> {
|
||||
return safeApiCall {
|
||||
apiService.qrCodePay(authCode = authCode, orderNo=orderNo, orderType = 0)
|
||||
apiService.qrCodePay(
|
||||
param = hashMapOf(
|
||||
"authCode" to authCode,
|
||||
"outTradeNo" to orderNo,
|
||||
"orderType" to "0"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ class UserViewModel : BaseViewModel() {
|
||||
withContext(Dispatchers.Default) {
|
||||
val list: List<UserFaceModel> = response.data ?: emptyList()
|
||||
if (pageNo == 1 && list.isEmpty()) {
|
||||
ToastUtils.showToast("查询人脸数据为空")
|
||||
//ToastUtils.showToast("查询人脸数据为空")
|
||||
return@withContext
|
||||
}
|
||||
//val item = list.map { it.member }
|
||||
|
||||
Reference in New Issue
Block a user