接口调试、增加人脸识别后主副屏支付金额逻辑、其它优化
This commit is contained in:
@@ -30,6 +30,7 @@ import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.activity.PayActivity
|
||||
import com.sw.dualscreen.databinding.PresentationFacePayBinding
|
||||
import com.sw.dualscreen.ext.load
|
||||
import com.sw.dualscreen.utils.GsonUtils
|
||||
import com.sw.dualscreen.view.CustomDialog
|
||||
import com.sw.dualscreen.viewmodel.UserViewModel
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
@@ -267,13 +268,30 @@ class FacePayPresentation(
|
||||
activity.runOnUiThread {
|
||||
//ToastUtils.showToast("用户人脸识别成功,挑战支付页面")
|
||||
showWaitingDialog("刷脸支付中,请稍后……")
|
||||
binding.root.postDelayed({
|
||||
hideWaitingDialog()
|
||||
activity.paySuccess()
|
||||
binding.root.postDelayed({
|
||||
dismiss()
|
||||
},500)
|
||||
},1500)
|
||||
userViewModel.getMemberInfo(memberId = userId) { memberInfo ->
|
||||
activity.runOnUiThread {
|
||||
if (memberInfo == null) {
|
||||
ToastUtils.showToast("查询会员信息失败,请稍后重试")
|
||||
return@runOnUiThread
|
||||
}
|
||||
userViewModel.bindOrder(userId, activity.foodOrderId) { bindResult ->
|
||||
activity.runOnUiThread {
|
||||
if (bindResult.not()) {
|
||||
hideWaitingDialog()
|
||||
ToastUtils.showToast("订单绑定失败")
|
||||
return@runOnUiThread
|
||||
}
|
||||
binding.root.postDelayed({
|
||||
hideWaitingDialog()
|
||||
activity.showPayInfo(memberInfo)
|
||||
binding.root.postDelayed({
|
||||
dismiss()
|
||||
},500)
|
||||
},1500)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// userViewModel.getUserNutritionData(
|
||||
// userId = userId,
|
||||
@@ -577,6 +595,8 @@ class FacePayPresentation(
|
||||
// } else {
|
||||
// step2FaceRecognizing(currentFood!!)
|
||||
// }
|
||||
|
||||
resumeCamera()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+108
-44
@@ -2,24 +2,23 @@ package com.sw.dualscreen.presentation.pay
|
||||
|
||||
import android.app.Presentation
|
||||
import android.os.Bundle
|
||||
import android.text.Spanned
|
||||
import android.text.SpannedString
|
||||
import android.text.style.AbsoluteSizeSpan
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.view.Display
|
||||
import androidx.core.graphics.toColorInt
|
||||
import androidx.core.text.buildSpannedString
|
||||
import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.activity.PayActivity
|
||||
import com.sw.dualscreen.databinding.PresentationScanQrcodePayBinding
|
||||
import com.sw.dualscreen.ext.format2String
|
||||
import com.sw.dualscreen.ext.gone
|
||||
import com.sw.dualscreen.ext.invisible
|
||||
import com.sw.dualscreen.ext.load
|
||||
import com.sw.dualscreen.ext.visible
|
||||
import com.sw.dualscreen.model.response.MemberInfo
|
||||
import com.sw.dualscreen.model.response.TextBean
|
||||
import com.sw.dualscreen.utils.SpannedUtils
|
||||
|
||||
class ScanQrCodePayPresentation(
|
||||
val activity: PayActivity,
|
||||
display: Display,
|
||||
val type:Int,
|
||||
val type: Int,
|
||||
private val onDismissListener: () -> Unit = {}
|
||||
) : Presentation(activity, display) {
|
||||
|
||||
@@ -38,74 +37,139 @@ class ScanQrCodePayPresentation(
|
||||
}
|
||||
|
||||
var foodName: String? = null
|
||||
var payAmount: String? = null
|
||||
var payQrCodePic: Any? = null
|
||||
|
||||
//总价格
|
||||
var totalPrice = 0.0
|
||||
|
||||
//余额
|
||||
private var balance = 0.0
|
||||
|
||||
//实际支付金额
|
||||
private var realPayPrice = 0.0
|
||||
//扣除余额
|
||||
private var expensesBalance = 0.0
|
||||
|
||||
private fun initView() {
|
||||
when(type) {
|
||||
0->{
|
||||
when (type) {
|
||||
0 -> {
|
||||
binding.layoutVip.gone()
|
||||
binding.layoutPaySuccess.gone()
|
||||
binding.layoutScanQrCode.visible()
|
||||
|
||||
binding.tvPayTip.text = "请扫码支付或出示付款码"
|
||||
binding.tvFoodName.text = foodName
|
||||
binding.tvRealAmount.text = getAmountText(payAmount ?: "")
|
||||
binding.tvRealAmount.text = SpannedUtils.getAmountText(
|
||||
listOf(
|
||||
TextBean(text = "¥", textSize = 32),
|
||||
TextBean(text = totalPrice.format2String(2), textSize = 48),
|
||||
)
|
||||
)
|
||||
binding.ivPayQrCode.load(payQrCodePic)
|
||||
}
|
||||
1->{
|
||||
|
||||
1 -> {
|
||||
binding.layoutVip.visible()
|
||||
binding.layoutPaySuccess.gone()
|
||||
binding.layoutScanQrCode.visible()
|
||||
|
||||
val memberInfo = activity.memberInfo
|
||||
totalPrice = activity.foodInfo?.vipPrice ?: 0.0
|
||||
balance = (memberInfo?.topUpBalance ?: 0.0) + (memberInfo?.rewardBalance ?: 0.0)
|
||||
realPayPrice = if (balance >= totalPrice) 0.0 else totalPrice - balance
|
||||
expensesBalance = if (balance >= totalPrice) totalPrice else balance
|
||||
|
||||
memberInfo?.let { loadUserInfo(it) }
|
||||
binding.tvUserBalance.text = SpannedUtils.getAmountText(
|
||||
listOf(
|
||||
TextBean(text = "¥", textSize = 20),
|
||||
TextBean(text = balance.format2String(2), textSize = 32),
|
||||
)
|
||||
)
|
||||
|
||||
binding.tvFoodName.text = foodName
|
||||
binding.tvRealAmount.text = getAmountText(payAmount ?: "")
|
||||
binding.ivPayQrCode.load(payQrCodePic)
|
||||
binding.tvRealAmount.text = SpannedUtils.getAmountText(
|
||||
listOf(
|
||||
TextBean(text = "¥", textSize = 32),
|
||||
TextBean(text = totalPrice.format2String(2), textSize = 48),
|
||||
)
|
||||
)
|
||||
binding.ivPayQrCode.run {
|
||||
// load(payQrCodePic)
|
||||
if (balance >= totalPrice) invisible() else visible()
|
||||
}
|
||||
|
||||
binding.ivHeadPic.load(R.mipmap.ic_launcher)
|
||||
binding.tvUserName.text = "张三"
|
||||
binding.tvUserPhone.text = "132****5678"
|
||||
binding.tvUserBalance.text = getBalanceText("0.00")
|
||||
|
||||
binding.tvPayTip.text = getPayTip("-16.80", "22.00")
|
||||
binding.tvPayTip.text = SpannedUtils.getAmountText(getAmountList())
|
||||
}
|
||||
2->{
|
||||
|
||||
2 -> {
|
||||
binding.layoutVip.visible()
|
||||
binding.layoutPaySuccess.visible()
|
||||
binding.layoutScanQrCode.gone()
|
||||
|
||||
binding.ivHeadPic.load(R.mipmap.ic_launcher)
|
||||
binding.tvUserName.text = "张三"
|
||||
binding.tvUserPhone.text = "132****5678"
|
||||
binding.tvUserBalance.text = getBalanceText("0.00")
|
||||
val memberInfo = activity.memberInfo
|
||||
totalPrice = activity.foodInfo?.vipPrice ?: 0.0
|
||||
balance = (memberInfo?.topUpBalance ?: 0.0) + (memberInfo?.rewardBalance ?: 0.0)
|
||||
realPayPrice = if (balance >= totalPrice) 0.0 else totalPrice - balance
|
||||
expensesBalance = if (balance >= totalPrice) totalPrice else balance
|
||||
|
||||
binding.tvPayInfo.text = "余额扣除 16.80 元,在线支付 20.00 元"
|
||||
memberInfo?.let { loadUserInfo(it) }
|
||||
val remainBalance = if (balance >= totalPrice) balance - totalPrice else 0.0
|
||||
binding.tvUserBalance.text = SpannedUtils.getAmountText(
|
||||
listOf(
|
||||
TextBean(text = "¥", textSize = 24),
|
||||
TextBean(text = remainBalance.format2String(2), textSize = 36),
|
||||
)
|
||||
)
|
||||
|
||||
binding.tvPayInfo.text =
|
||||
"余额扣除 ${expensesBalance.format2String(2)} 元,在线支付 ${totalPrice.format2String(2)} 元"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPayTip(startAmount:String, endAmount: String): SpannedString {
|
||||
return buildSpannedString {
|
||||
append("余额扣除 ", ForegroundColorSpan("#FF5E7585".toColorInt()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
append(startAmount, ForegroundColorSpan("#FF0A1428".toColorInt()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
append(" 元,还需支付 ", ForegroundColorSpan("#FF5E7585".toColorInt()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
append(endAmount, ForegroundColorSpan("#FF0A1428".toColorInt()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
append(" 元", ForegroundColorSpan("#FF5E7585".toColorInt()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
private fun loadUserInfo(item: MemberInfo) {
|
||||
binding.ivHeadPic.load(R.mipmap.ic_launcher)
|
||||
binding.tvUserName.text = item.name
|
||||
|
||||
val phone = item.phone ?: ""
|
||||
binding.tvUserPhone.text =
|
||||
if (phone.length == 11)
|
||||
phone.replace(phone.substring(3, 7), "****")
|
||||
else
|
||||
phone
|
||||
}
|
||||
|
||||
private fun getBalanceText(amount: String): SpannedString {
|
||||
return buildSpannedString {
|
||||
append("¥", AbsoluteSizeSpan(20, true), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
append(amount, AbsoluteSizeSpan(32, true), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
}
|
||||
private fun getAmountList(): List<TextBean> {
|
||||
val list: MutableList<TextBean> = mutableListOf()
|
||||
|
||||
private fun getAmountText(amount: String): SpannedString {
|
||||
return buildSpannedString {
|
||||
append("¥", AbsoluteSizeSpan(32, true), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
append(amount, AbsoluteSizeSpan(48, true), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
list.add(TextBean(text = "余额扣除 ", textSize = 30, textColor = "#FF5E7585"))
|
||||
list.add(
|
||||
TextBean(
|
||||
text = "-${expensesBalance.format2String(2)}",
|
||||
textSize = 30,
|
||||
textColor = "#FF0A1428"
|
||||
)
|
||||
)
|
||||
|
||||
if (balance >= totalPrice) {
|
||||
//余额大于等于总价格,使用余额支付
|
||||
TextBean(text = " 元,扣除后可用余额 ", textSize = 30, textColor = "#FF5E7585")
|
||||
val remainingBalance = balance - totalPrice
|
||||
TextBean(
|
||||
text = remainingBalance.format2String(2),
|
||||
textSize = 30,
|
||||
textColor = "#FF0A1428"
|
||||
)
|
||||
} else {
|
||||
//余额小于总价格,使用余额+扫码支付
|
||||
//实际支付金额
|
||||
TextBean(text = " 元,还需支付 ", textSize = 30, textColor = "#FF5E7585")
|
||||
TextBean(text = realPayPrice.format2String(2), textSize = 30, textColor = "#FF0A1428")
|
||||
TextBean(text = " 元", textSize = 30, textColor = "#FF5E7585")
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
override fun onDisplayRemoved() {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.sw.dualscreen.presentation.pay
|
||||
|
||||
import android.view.TextureView
|
||||
import androidx.camera.lifecycle.ProcessCameraProvider
|
||||
import java.util.concurrent.ExecutorService
|
||||
|
||||
|
||||
|
||||
class TransmitScreen {
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user