支付页面统一副屏逻辑
This commit is contained in:
@@ -14,11 +14,10 @@ import com.sw.dualscreen.ext.gone
|
||||
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.ScanQrCodePayPresentation
|
||||
import com.sw.dualscreen.presentation.pay.PayPresentation
|
||||
import com.sw.dualscreen.utils.SPUtil
|
||||
import com.sw.dualscreen.viewmodel.BaseViewModel
|
||||
import com.sw.dualscreen.viewmodel.UserViewModel
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
@@ -62,9 +61,19 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
|
||||
var foodOrderId: String = ""
|
||||
var eatNum: Int = 1
|
||||
|
||||
val presentation by lazy {
|
||||
PayPresentation(
|
||||
activity = this@PayActivity,
|
||||
userViewModel = userViewModel,
|
||||
recognizeViewModel = recognizeViewModel,
|
||||
display = displays[1]
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
override fun initialize() {
|
||||
super.initialize()
|
||||
presentation.show()
|
||||
foodInfo = intent.getParcelableExtra(FOOD_INFO)
|
||||
foodOrderId = intent.getStringExtra(FOOD_ORDER_ID) ?: ""
|
||||
eatNum = intent.getIntExtra(FOOD_EAT_NUM, 1)
|
||||
@@ -101,7 +110,6 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
|
||||
}
|
||||
showFacePay()
|
||||
}
|
||||
|
||||
showScanQrCodePay()
|
||||
}
|
||||
|
||||
@@ -136,39 +144,43 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
qrCodePayFragment?.presentation?.dismiss()
|
||||
cashPayFragment?.presentation?.dismiss()
|
||||
numberPayFragment?.presentation?.dismiss()
|
||||
facePayFragment?.presentation?.dismiss()
|
||||
scanQrCodePayPresentation?.dismiss()
|
||||
presentation?.dismiss()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private var scanQrCodePayPresentation: ScanQrCodePayPresentation? = null
|
||||
var memberInfo: MemberInfo? = null
|
||||
fun showPayInfo(type: Int = 1, isVip: Boolean = false, memberInfo: MemberInfo? = null) {
|
||||
this.memberInfo = memberInfo
|
||||
payResultFragment = PayResultFragment.instance(type, memberInfo)
|
||||
showFragment(payResultFragment!!, TAG_PAY_RESULT)
|
||||
if (displays.size > 1) {
|
||||
scanQrCodePayPresentation = ScanQrCodePayPresentation(
|
||||
activity = this,
|
||||
display = displays[1],
|
||||
type = type
|
||||
) {
|
||||
scanQrCodePayPresentation?.dismiss()
|
||||
}.also {
|
||||
it.foodName = foodInfo?.foodName
|
||||
//确认使用vipPrice 还是 specPrice
|
||||
val onePrice = if (isVip) foodInfo?.vipPrice else foodInfo?.specPrice
|
||||
it.totalPrice = (onePrice ?: 0.0) * eatNum
|
||||
}
|
||||
scanQrCodePayPresentation?.show()
|
||||
// if (displays.size > 1) {
|
||||
// scanQrCodePayPresentation = ScanQrCodePayPresentation(
|
||||
// activity = this,
|
||||
// display = displays[1],
|
||||
// type = type
|
||||
// ) {
|
||||
// scanQrCodePayPresentation?.dismiss()
|
||||
// }.also {
|
||||
// it.foodName = foodInfo?.foodName
|
||||
// //确认使用vipPrice 还是 specPrice
|
||||
// val onePrice = if (isVip) foodInfo?.vipPrice else foodInfo?.specPrice
|
||||
// it.totalPrice = (onePrice ?: 0.0) * eatNum
|
||||
// }
|
||||
// scanQrCodePayPresentation?.show()
|
||||
// }
|
||||
presentation.let {
|
||||
it.type = type
|
||||
it.foodName = foodInfo?.foodName
|
||||
//确认使用vipPrice 还是 specPrice
|
||||
val onePrice = if (isVip) foodInfo?.vipPrice else foodInfo?.specPrice
|
||||
it.totalPrice = (onePrice ?: 0.0) * eatNum
|
||||
presentation.initView()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateQrCodeImage(qrCodeUrl: String?) {
|
||||
scanQrCodePayPresentation?.loadQrCodeImage(qrCodeUrl)
|
||||
// scanQrCodePayPresentation?.loadQrCodeImage(qrCodeUrl)
|
||||
presentation?.loadQrCodeImage(qrCodeUrl)
|
||||
}
|
||||
|
||||
fun showPaySuccess(isVip: Boolean) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.sw.dualscreen.activity.PayActivity
|
||||
import com.sw.dualscreen.activity.fragment.BaseFragment
|
||||
import com.sw.dualscreen.databinding.FragmentCashPayBinding
|
||||
import com.sw.dualscreen.ext.format2String
|
||||
import com.sw.dualscreen.presentation.pay.CashPayPresentation
|
||||
import com.sw.dualscreen.presentation.pay.PayPresentation
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
|
||||
class CashPayFragment : BaseFragment<FragmentCashPayBinding>() {
|
||||
@@ -17,8 +17,6 @@ class CashPayFragment : BaseFragment<FragmentCashPayBinding>() {
|
||||
private var foodName: String? = null
|
||||
private var payAmount: Double? = null
|
||||
|
||||
var presentation: CashPayPresentation? = null
|
||||
|
||||
override fun inflateViewBinding(): FragmentCashPayBinding {
|
||||
return FragmentCashPayBinding.inflate(layoutInflater)
|
||||
}
|
||||
@@ -27,63 +25,73 @@ class CashPayFragment : BaseFragment<FragmentCashPayBinding>() {
|
||||
payActivity = requireActivity() as PayActivity
|
||||
payActivity.foodInfo?.let {
|
||||
foodName = it.foodName
|
||||
payAmount = (it.specPrice?:0.0) * payActivity.eatNum
|
||||
payAmount = (it.specPrice ?: 0.0) * payActivity.eatNum
|
||||
}
|
||||
binding.tvRealAmount.text = getAmountText(payAmount.format2String(2))
|
||||
|
||||
binding.btnConfirmPayFinish.setOnClickListener {
|
||||
payActivity.cashPay(hashMapOf(
|
||||
//标价金额(单位为元)
|
||||
"totalFee" to payAmount.format2String(2),
|
||||
//订单类型(0付款1会员充值)
|
||||
"orderType" to "0",
|
||||
//商户订单号
|
||||
"orderNo" to payActivity.foodOrderId,
|
||||
//支付来源:0线下收款 、3:线上纯会员支付 101:支付宝主动、102:支付宝被动、201:微信主动、202:微信被动
|
||||
"paySource" to "0"
|
||||
)) { paySuccess ->
|
||||
payActivity.cashPay(
|
||||
hashMapOf(
|
||||
//标价金额(单位为元)
|
||||
"totalFee" to payAmount.format2String(2),
|
||||
//订单类型(0付款1会员充值)
|
||||
"orderType" to "0",
|
||||
//商户订单号
|
||||
"orderNo" to payActivity.foodOrderId,
|
||||
//支付来源:0线下收款 、3:线上纯会员支付 101:支付宝主动、102:支付宝被动、201:微信主动、202:微信被动
|
||||
"paySource" to "0"
|
||||
)
|
||||
) { paySuccess ->
|
||||
if (paySuccess.not()) {
|
||||
ToastUtils.showToast("接口调用失败")
|
||||
return@cashPay
|
||||
}
|
||||
payActivity.showPaySuccess( false)
|
||||
payActivity.showPaySuccess(false)
|
||||
}
|
||||
}
|
||||
showSubScreen()
|
||||
}
|
||||
override fun onHiddenChanged(hidden: Boolean) {
|
||||
super.onHiddenChanged(hidden)
|
||||
if (hidden) {
|
||||
dismissSubScreen()
|
||||
return
|
||||
}
|
||||
//showSubScreen()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
dismissSubScreen()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun dismissSubScreen() {
|
||||
presentation?.let {
|
||||
if (it.isShowing) {
|
||||
it.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
// override fun onHiddenChanged(hidden: Boolean) {
|
||||
// super.onHiddenChanged(hidden)
|
||||
// if (hidden) {
|
||||
// dismissSubScreen()
|
||||
// return
|
||||
// }
|
||||
// //showSubScreen()
|
||||
// }
|
||||
//
|
||||
// override fun onDestroy() {
|
||||
// dismissSubScreen()
|
||||
// super.onDestroy()
|
||||
// }
|
||||
//
|
||||
// private fun dismissSubScreen() {
|
||||
// }
|
||||
|
||||
private fun showSubScreen() {
|
||||
// 查找副屏(通常索引为1)
|
||||
if (displays.size > 1) {
|
||||
dismissSubScreen()
|
||||
presentation = CashPayPresentation(activity = payActivity, display = displays[1]) {
|
||||
presentation?.dismiss()
|
||||
}.also {
|
||||
it.foodName = foodName
|
||||
it.payAmount = payAmount.format2String(2)
|
||||
}
|
||||
presentation?.show()
|
||||
// // 查找副屏(通常索引为1)
|
||||
// if (displays.size > 1) {
|
||||
// dismissSubScreen()
|
||||
// presentation = PayPresentation(
|
||||
// activity = payActivity,
|
||||
// pageType = PayPresentation.CASH_PAY,
|
||||
// userViewModel = payActivity.userViewModel,
|
||||
// recognizeViewModel = payActivity.recognizeViewModel,
|
||||
// display = displays[1]
|
||||
// ) {
|
||||
// presentation?.dismiss()
|
||||
// }.also {
|
||||
// it.foodName = foodName
|
||||
// it.payAmount = payAmount.format2String(2)
|
||||
// }
|
||||
// presentation?.show()
|
||||
// }
|
||||
payActivity.presentation.let {
|
||||
it.pageType = PayPresentation.CASH_PAY
|
||||
it.foodName = foodName
|
||||
it.payAmount = payAmount.format2String(2)
|
||||
it.initView()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,13 @@ import com.sw.dualscreen.activity.PayActivity
|
||||
import com.sw.dualscreen.activity.fragment.BaseFragment
|
||||
import com.sw.dualscreen.databinding.FragmentFacePayBinding
|
||||
import com.sw.dualscreen.ext.format2String
|
||||
import com.sw.dualscreen.presentation.pay.FacePayPresentation
|
||||
import com.sw.dualscreen.presentation.pay.PayPresentation
|
||||
|
||||
class FacePayFragment : BaseFragment<FragmentFacePayBinding>() {
|
||||
|
||||
private lateinit var payActivity: PayActivity
|
||||
private var foodName: String? = null
|
||||
private var payAmount: Double? = null
|
||||
var presentation: FacePayPresentation? = null
|
||||
override fun inflateViewBinding(): FragmentFacePayBinding {
|
||||
return FragmentFacePayBinding.inflate(layoutInflater)
|
||||
}
|
||||
@@ -32,24 +31,26 @@ class FacePayFragment : BaseFragment<FragmentFacePayBinding>() {
|
||||
override fun onHiddenChanged(hidden: Boolean) {
|
||||
super.onHiddenChanged(hidden)
|
||||
if (hidden) {
|
||||
dismissSubScreen()
|
||||
// dismissSubScreen()
|
||||
payActivity.presentation.pauseCamera()
|
||||
return
|
||||
}
|
||||
payActivity.presentation.resumeCamera()
|
||||
//showSubScreen()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
dismissSubScreen()
|
||||
super.onDestroy()
|
||||
}
|
||||
// override fun onDestroy() {
|
||||
// dismissSubScreen()
|
||||
// super.onDestroy()
|
||||
// }
|
||||
|
||||
private fun dismissSubScreen() {
|
||||
presentation?.let {
|
||||
if (it.isShowing) {
|
||||
it.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
// private fun dismissSubScreen() {
|
||||
// presentation?.let {
|
||||
// if (it.isShowing) {
|
||||
// it.dismiss()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
fun loadBitmap(frame: Bitmap) {
|
||||
binding.ivFaceImage.setImageBitmap(frame)
|
||||
@@ -57,21 +58,28 @@ class FacePayFragment : BaseFragment<FragmentFacePayBinding>() {
|
||||
|
||||
private fun showSubScreen() {
|
||||
// 查找副屏(通常索引为1)
|
||||
if (displays.size > 1) {
|
||||
dismissSubScreen()
|
||||
presentation = FacePayPresentation(
|
||||
activity = payActivity,
|
||||
display = displays[1],
|
||||
userViewModel = payActivity.userViewModel,
|
||||
recognizeViewModel = payActivity.recognizeViewModel,
|
||||
// parentTextureView = binding.parentTextureView,
|
||||
) {
|
||||
presentation?.dismiss()
|
||||
}.also {
|
||||
it.foodName = foodName
|
||||
it.payAmount = payAmount.format2String(2)
|
||||
}
|
||||
presentation?.show()
|
||||
// if (displays.size > 1) {
|
||||
// dismissSubScreen()
|
||||
// presentation = PayPresentation(
|
||||
// activity = payActivity,
|
||||
// pageType = PayPresentation.FACE_PAY,
|
||||
// userViewModel = payActivity.userViewModel,
|
||||
// recognizeViewModel = payActivity.recognizeViewModel,
|
||||
// display = displays[1]
|
||||
// ) {
|
||||
// presentation?.dismiss()
|
||||
// }.also {
|
||||
// it.foodName = foodName
|
||||
// it.payAmount = payAmount.format2String(2)
|
||||
// }
|
||||
// presentation?.show()
|
||||
// }
|
||||
payActivity.presentation.let {
|
||||
it.pageType = PayPresentation.FACE_PAY
|
||||
it.foodName = foodName
|
||||
it.payAmount = payAmount.format2String(2)
|
||||
it.initView()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import com.sw.dualscreen.activity.fragment.BaseFragment
|
||||
import com.sw.dualscreen.databinding.FragmentNumberPayBinding
|
||||
import com.sw.dualscreen.ext.format2String
|
||||
import com.sw.dualscreen.ext.hideKeyboard
|
||||
import com.sw.dualscreen.presentation.pay.CashPayPresentation
|
||||
import com.sw.dualscreen.presentation.pay.PayPresentation
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
|
||||
class NumberPayFragment : BaseFragment<FragmentNumberPayBinding>() {
|
||||
@@ -13,7 +13,6 @@ class NumberPayFragment : BaseFragment<FragmentNumberPayBinding>() {
|
||||
private lateinit var payActivity: PayActivity
|
||||
private var foodName: String? = null
|
||||
private var payAmount: Double? = null
|
||||
var presentation: CashPayPresentation? = null
|
||||
override fun inflateViewBinding(): FragmentNumberPayBinding {
|
||||
return FragmentNumberPayBinding.inflate(layoutInflater)
|
||||
}
|
||||
@@ -79,39 +78,49 @@ class NumberPayFragment : BaseFragment<FragmentNumberPayBinding>() {
|
||||
showSubScreen()
|
||||
}
|
||||
|
||||
override fun onHiddenChanged(hidden: Boolean) {
|
||||
super.onHiddenChanged(hidden)
|
||||
if (hidden) {
|
||||
dismissSubScreen()
|
||||
return
|
||||
}
|
||||
//showSubScreen()
|
||||
}
|
||||
// override fun onHiddenChanged(hidden: Boolean) {
|
||||
// super.onHiddenChanged(hidden)
|
||||
// if (hidden) {
|
||||
// dismissSubScreen()
|
||||
// return
|
||||
// }
|
||||
// //showSubScreen()
|
||||
// }
|
||||
//
|
||||
// override fun onDestroy() {
|
||||
// dismissSubScreen()
|
||||
// super.onDestroy()
|
||||
// }
|
||||
|
||||
override fun onDestroy() {
|
||||
dismissSubScreen()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun dismissSubScreen() {
|
||||
presentation?.let {
|
||||
if (it.isShowing) {
|
||||
it.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
// private fun dismissSubScreen() {
|
||||
// presentation?.let {
|
||||
// if (it.isShowing) {
|
||||
// it.dismiss()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private fun showSubScreen() {
|
||||
// 查找副屏(通常索引为1)
|
||||
if (displays.size > 1) {
|
||||
dismissSubScreen()
|
||||
presentation = CashPayPresentation(activity = payActivity, display = displays[1]) {
|
||||
presentation?.dismiss()
|
||||
}.also {
|
||||
it.foodName = foodName
|
||||
it.payAmount = payAmount.format2String(2)
|
||||
}
|
||||
presentation?.show()
|
||||
// if (displays.size > 1) {
|
||||
// dismissSubScreen()
|
||||
// presentation = PayPresentation(
|
||||
// activity = payActivity,
|
||||
// pageType = PayPresentation.CASH_PAY,
|
||||
// userViewModel = payActivity.userViewModel,
|
||||
// recognizeViewModel = payActivity.recognizeViewModel,
|
||||
// display = displays[1]
|
||||
// ).also {
|
||||
// it.foodName = foodName
|
||||
// it.payAmount = payAmount.format2String(2)
|
||||
// }
|
||||
// presentation?.show()
|
||||
// }
|
||||
payActivity.presentation.let {
|
||||
it.pageType = PayPresentation.CASH_PAY
|
||||
it.foodName = foodName
|
||||
it.payAmount = payAmount.format2String(2)
|
||||
it.initView()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+31
-25
@@ -8,11 +8,11 @@ import androidx.lifecycle.lifecycleScope
|
||||
import com.sw.dualscreen.activity.PayActivity
|
||||
import com.sw.dualscreen.activity.fragment.BaseFragment
|
||||
import com.sw.dualscreen.ext.load
|
||||
import com.sw.dualscreen.presentation.pay.ScanQrCodePayPresentation
|
||||
import com.sw.dualscreen.utils.countDownByFlow
|
||||
import kotlinx.coroutines.Job
|
||||
import com.sw.dualscreen.databinding.FragmentScanQrcodePayBinding
|
||||
import com.sw.dualscreen.ext.format2String
|
||||
import com.sw.dualscreen.presentation.pay.PayPresentation
|
||||
import com.sw.dualscreen.utils.IntervalExecutor
|
||||
|
||||
class ScanQrCodePayFragment : BaseFragment<FragmentScanQrcodePayBinding>() {
|
||||
@@ -25,7 +25,6 @@ class ScanQrCodePayFragment : BaseFragment<FragmentScanQrcodePayBinding>() {
|
||||
private var foodName: String? = null
|
||||
private var payAmount: Double? = null
|
||||
private var payQrCodePic: String? = null
|
||||
var presentation: ScanQrCodePayPresentation? = null
|
||||
private var countDownJob: Job? = null
|
||||
|
||||
override fun inflateViewBinding(): FragmentScanQrcodePayBinding {
|
||||
@@ -37,7 +36,7 @@ class ScanQrCodePayFragment : BaseFragment<FragmentScanQrcodePayBinding>() {
|
||||
|
||||
payActivity.foodInfo?.let {
|
||||
foodName = it.foodName
|
||||
payAmount = (it.specPrice?:0.0)*payActivity.eatNum
|
||||
payAmount = (it.specPrice ?: 0.0) * payActivity.eatNum
|
||||
}
|
||||
binding.tvRealAmount.text = getAmountText(payAmount.format2String(2))
|
||||
//不需要绑定会员id
|
||||
@@ -60,41 +59,48 @@ class ScanQrCodePayFragment : BaseFragment<FragmentScanQrcodePayBinding>() {
|
||||
|
||||
override fun onHiddenChanged(hidden: Boolean) {
|
||||
super.onHiddenChanged(hidden)
|
||||
if (hidden) {
|
||||
dismissSubScreen()
|
||||
return
|
||||
}
|
||||
// if (hidden) {
|
||||
//// dismissSubScreen()
|
||||
// return
|
||||
// }
|
||||
//showSubScreen()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
dismissSubScreen()
|
||||
// dismissSubScreen()
|
||||
countDownJob?.cancel() // 自动取消订阅,防止内存泄漏
|
||||
payTaskJob?.cancel()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun dismissSubScreen() {
|
||||
presentation?.let {
|
||||
if (it.isShowing) {
|
||||
it.dismiss()
|
||||
}
|
||||
}
|
||||
// presentation?.let {
|
||||
// if (it.isShowing) {
|
||||
// it.dismiss()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private fun showSubScreen() {
|
||||
// 查找副屏(通常索引为1)
|
||||
if (displays.size > 1) {
|
||||
dismissSubScreen()
|
||||
presentation =
|
||||
ScanQrCodePayPresentation(activity = payActivity, type = 0, display = displays[1]) {
|
||||
presentation?.dismiss()
|
||||
}.also {
|
||||
it.foodName = foodName
|
||||
it.totalPrice = payAmount ?: 0.0
|
||||
it.payQrCodePic = payQrCodePic
|
||||
}
|
||||
presentation?.show()
|
||||
// // 查找副屏(通常索引为1)
|
||||
// if (displays.size > 1) {
|
||||
// dismissSubScreen()
|
||||
// presentation =
|
||||
// ScanQrCodePayPresentation(activity = payActivity, type = 0, display = displays[1]) {
|
||||
// presentation?.dismiss()
|
||||
// }.also {
|
||||
// it.foodName = foodName
|
||||
// it.totalPrice = payAmount ?: 0.0
|
||||
// it.payQrCodePic = payQrCodePic
|
||||
// }
|
||||
// presentation?.show()
|
||||
// }
|
||||
payActivity.presentation.let {
|
||||
it.pageType = PayPresentation.QR_CODE_PAY
|
||||
it.foodName = foodName
|
||||
it.totalPrice = payAmount ?: 0.0
|
||||
it.payQrCodePic = payQrCodePic
|
||||
it.initView()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user