增加支付接口相关逻辑

This commit is contained in:
2025-12-05 18:03:31 +08:00
parent 8899cae323
commit 04e318f47b
38 changed files with 830 additions and 316 deletions
@@ -21,6 +21,7 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import com.arcsoft.face.ErrorInfo
import com.sw.dualscreen.GlobalKey
import com.sw.dualscreen.MyApp
import com.sw.dualscreen.R
import com.sw.dualscreen.activity.MainActivity
import com.sw.dualscreen.databinding.PresentationMainScreenBinding
@@ -33,6 +34,7 @@ import com.sw.dualscreen.ext.visible
import com.sw.dualscreen.model.request.UserNutritionParam
import com.sw.dualscreen.model.response.DinnerType
import com.sw.dualscreen.model.response.FoodInfo
import com.sw.dualscreen.model.response.UserNutrition
import com.sw.dualscreen.model.response.UserNutritionData
import com.sw.dualscreen.utils.Debouncer
import com.sw.dualscreen.utils.SPUtil
@@ -90,7 +92,9 @@ class MainScreenPresentation(
private var detectWeight = 0.0 //识别菜品时的重量
private var lastWeight = 0.0 // 上一次的计算热量结果
private var userNutritionData: UserNutritionData? = null
// private var userNutritionData: UserNutritionData? = null
private var userNutrition: UserNutrition? = null
private var dinnerTypeInfo: DinnerType? = null
private val debouncer = Debouncer(500)
private var recognitionTime: Long = 0L // 人脸识别时的时间
@@ -140,7 +144,8 @@ class MainScreenPresentation(
return
}
if (userNutritionData == null) {
//if (userNutritionData == null) {
if (userNutrition == null) {
Timber.tag(TAG).e("updateWeight userNutritionData is null")
return
}
@@ -206,17 +211,17 @@ class MainScreenPresentation(
}
}
}
activity.lifecycleScope.launch {
userViewModel.nutritionData.collect {
Timber.tag(TAG).d("registerDataChange nutritionData = $it")
userNutritionData = it
if (it == null) return@collect
// step3ShowRecognizeResult()
// activity.lifecycleScope.launch {
// userViewModel.nutritionData.collect {
// Timber.tag(TAG).d("registerDataChange nutritionData = $it")
// userNutritionData = it
// if (it == null) return@collect
//// step3ShowRecognizeResult()
// //binding.nutritionInclude.tvUserName.text = it.userName.maskName()
// //binding.nutritionInclude.tvRecommendHeat.text = "推荐热量:${it.recommendMin}-${it.recommendMax}"
// //updateWeight(lastWeight / 1000)
}
}
//// //updateWeight(lastWeight / 1000)
// }
// }
activity.lifecycleScope.launch {
userViewModel.dinnerTypeInfo.drop(1).collect {
Timber.tag(TAG).d("registerDataChange dinnerTypeInfo = $it")
@@ -291,16 +296,16 @@ class MainScreenPresentation(
// Timber.tag(TAG).d("loadBilledMode${GsonUtils.toJson(it)}")
// }
currentFood?.let {
val specPrice = it.specPrice?:0.0
val vipPrice = it.vipPrice?:0.0
val specPrice = it.specPrice ?: 0.0
val vipPrice = it.vipPrice ?: 0.0
binding.tvNormalPrice.text = "${specPrice.format2String(2)} 元/份"
binding.tvVipPrice.text = "${vipPrice.format2String(2)} 元/份"
var calorie = getIntNutritionValue(it.calorie)
calorie = max(calorie, 0)
val fat = getIntNutritionValue(it.fat)
val protein = getIntNutritionValue(it.protein)
val carbohydrate = getIntNutritionValue(it.carbohydrate)
val fat = getIntNutritionValue(it.fat)
val protein = getIntNutritionValue(it.protein)
val carbohydrate = getIntNutritionValue(it.carbohydrate)
val fatRate = getNutritionRate(fat, calorie)
val proteinRate = getNutritionRate(protein, calorie)
@@ -311,26 +316,33 @@ class MainScreenPresentation(
tvProteinRate.text = "$proteinRate%"
tvCarbohydrateRate.text = "$carbohydrateRate%"
viewFatLine.updateLayoutParams { height = (fatRate/100.0*84).roundToInt()*1.dp }
viewProteinLine.updateLayoutParams { height = (proteinRate/100.0*84).roundToInt()*1.dp }
viewCarbohydrateLine.updateLayoutParams { height = (carbohydrateRate/100.0*84).roundToInt()*1.dp }
viewFatLine.updateLayoutParams {
height = (fatRate / 100.0 * 84).roundToInt() * 1.dp
}
viewProteinLine.updateLayoutParams {
height = (proteinRate / 100.0 * 84).roundToInt() * 1.dp
}
viewCarbohydrateLine.updateLayoutParams {
height = (carbohydrateRate / 100.0 * 84).roundToInt() * 1.dp
}
}
}
}
private fun getNutritionRate(value: Int, total: Int): Int{
private fun getNutritionRate(value: Int, total: Int): Int {
if (value == 0 || total == 0) return 0
return (100.0 * value / total).roundToInt()
}
private fun getIntNutritionValue(text: String?): Int {
return if (text.isNullOrBlank()) 0 else text.toFloat().roundToInt() }
private fun getIntNutritionValue(num: Double?): Int {
return num?.roundToInt() ?: 0
}
/**
* 餐品识别成功,不计费模式
*/
fun loadUnbilledMode() {
fun loadUnbilledMode(nutrition: UserNutrition) {
binding.calorieInclude.root.gone()
binding.nutritionInclude.root.visible()
@@ -342,12 +354,13 @@ class MainScreenPresentation(
//binding.ivRecImage.gone()
//updateFoodInfo(foodInfo)
userNutritionData?.let {
binding.nutritionInclude.tvUserName.text = it.userName.maskName()
binding.nutritionInclude.tvRecommendHeat.text =
"推荐热量:${it.recommendMin}-${it.recommendMax}kcal"
updateWeight(lastWeight / 1000)
}
binding.nutritionInclude.tvUserName.text = nutrition.name.maskName()
binding.nutritionInclude.tvRecommendHeat.text =
"推荐热量:${nutrition.recommendEnergy ?: 0}kcal"
//updateWeight(lastWeight / 1000)
// -------------------------------------------------
// 删除userNutritionData,改为userNutrition
calculateNutrition(recognitionWeight - lastWeight)
}
/**
@@ -370,7 +383,8 @@ class MainScreenPresentation(
dinnerTypeInfo = null
currentFood = null
userNutritionData = null
// userNutritionData = null
userNutrition = null
recognitionWeight = 0.0
stepChangeCallback(currentStep)
@@ -434,7 +448,8 @@ class MainScreenPresentation(
binding.ivPreviewImage.gone()
dinnerTypeInfo = null
userNutritionData = null
// userNutritionData = null
userNutrition = null
recognitionWeight = 0.0
stepChangeCallback(currentStep)
@@ -457,7 +472,8 @@ class MainScreenPresentation(
binding.ivPreviewImage.gone()
binding.ivRecImage.let {
it.visible()
val imageUrl = if (foodInfo.foodImg.isNullOrBlank()) foodInfo.photoUri else foodInfo.foodImg
val imageUrl =
if (foodInfo.foodImg.isNullOrBlank()) foodInfo.photoUri else foodInfo.foodImg
it.load(imageUrl)
}
val mode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
@@ -506,11 +522,12 @@ class MainScreenPresentation(
Timber.tag(TAG)
.d("calculateNutrition weight = $weight, recognitionWeight = $recognitionWeight")
val dinnerType = dinnerTypeInfo!!.dinnerType!!
Timber.tag(TAG)
.d("calculateNutrition foodName = ${currentFood!!.foodName}, dinnerType = $dinnerType, userId = ${userNutritionData!!.userId}")
val calcResultInfo = UserNutritionUtils.calculateNutrition(
// Timber.tag(TAG)
// .d("calculateNutrition foodName = ${currentFood!!.foodName}, dinnerType = $dinnerType, userId = ${userNutritionData!!.userId}")
val calcResultInfo = UserNutritionUtils.calculateNutrition2(
currentFood!!,
userNutritionData!!,
// userNutritionData!!,
userNutrition!!,
weight,
dinnerType = dinnerType
)
@@ -701,6 +718,7 @@ class MainScreenPresentation(
val faceEntity = compareResult.faceEntity
val userId = faceEntity.userName
if (userId == null) return@Observer
ToastUtils.showToast("人脸识别成功,userId = $userId")
if (currentFood == null) {
currentFood = activity.checkedItem
}
@@ -710,17 +728,19 @@ class MainScreenPresentation(
return@runOnUiThread
}
}
// TODO: ------------------人脸识别成功
//-------------------------------------------------
// TODO: ------------------人脸识别成功
step3ShowRecognizeResult()
//根据接口数据更新热量数据--------------------------
loadUnbilledMode()
// userViewModel.getUserNutritionData(
// userId = userId,
// foodId = currentFood!!.foodId!!
// )
userViewModel.getUserNutritionData(userId = userId) { nutrition ->
activity.runOnUiThread {
if (nutrition == null) {
ToastUtils.showToast("未查询到营养数据")
return@runOnUiThread
}
this@MainScreenPresentation.userNutrition = nutrition
loadUnbilledMode(nutrition)
// -------------------------------
}
}
})
recognizeViewModel.drawRectInfoText.observe(activity, Observer { info ->
@@ -1013,7 +1033,8 @@ class MainScreenPresentation(
}
val listIsEmpty = facePreviewInfoList.isEmpty()
val listFirstTrackId = if (listIsEmpty.not()) facePreviewInfoList[0]!!.trackId else null
Timber.tag(TAG).d("listIsEmpty=$listIsEmpty,lastFaceTrackId=$lastFaceTrackId,listFirstTrackId=$listFirstTrackId")
Timber.tag(TAG)
.d("listIsEmpty=$listIsEmpty,lastFaceTrackId=$lastFaceTrackId,listFirstTrackId=$listFirstTrackId")
if (listIsEmpty || (lastFaceTrackId != listFirstTrackId)) {
if (lastFaceTrackId != -1) {
mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
@@ -1032,9 +1053,9 @@ class MainScreenPresentation(
fun postUserData() {
Timber.tag(TAG).d("postUserData")
if (userNutritionData == null || currentFood == null) {
if (userNutrition == null || currentFood == null) {
Timber.tag(TAG)
.d("postUserData userNutritionData = ${userNutritionData == null}, currentFood = ${currentFood == null}")
.d("postUserData userNutritionData = ${userNutrition == null}, currentFood = ${currentFood == null}")
return
}
var eatWeight = 0.0
@@ -1044,14 +1065,23 @@ class MainScreenPresentation(
} else {
recognitionWeight - lastWeight
}
val userNutritionParam = UserNutritionParam(
userId = userNutritionData?.userId!!,
foodId = currentFood?.foodId!!,
faceTime = recognitionTime,
faceEndTime = System.currentTimeMillis(),
eatWeight = eatWeight,//lastWeight
foodWeight = lastWeight
)
userViewModel.postUserNutritionData(listOf(userNutritionParam))
//val userNutritionParam = UserNutritionParam(
// userId = userNutritionData?.userId!!,
// foodId = currentFood?.foodId!!,
// faceTime = recognitionTime,
// faceEndTime = System.currentTimeMillis(),
// eatWeight = eatWeight,//lastWeight
// foodWeight = lastWeight
//)
//userViewModel.postUserNutritionData(listOf(userNutritionParam))
activity.createOrder(
foodInfo = currentFood!!,
foodWeight = lastWeight.roundToInt(),
eatWeight = eatWeight.roundToInt()
) {
if (MyApp.DEBUG) {
ToastUtils.showToast("订单已生成")
}
}
}
}
@@ -4,6 +4,7 @@ package com.sw.dualscreen.presentation
import android.text.TextUtils
import com.sw.dualscreen.ext.toSafeDouble
import com.sw.dualscreen.model.response.FoodInfo
import com.sw.dualscreen.model.response.UserNutrition
import com.sw.dualscreen.model.response.UserNutritionData
import timber.log.Timber
import kotlin.math.max
@@ -16,62 +17,109 @@ object UserNutritionUtils {
/**
* 计算热量信息
*/
fun calculateNutrition(
fun calculateNutrition2(
foodInfo: FoodInfo,
userModel: UserNutritionData,
nutrition: UserNutrition,
weight: Double,
dinnerType: String
): CalcResultInfo {
// 初始化变量
var foodKcal = 0.0
var totalKcal = 0.0
var (vegetable, meat, fruits, grain) = List(4) { 0.0 }
var (calorie, grain, fruitsVegetables, meatEggs) = List(4) { 0.0 }
// 处理食物信息
foodKcal = calculateValue(foodInfo.stFoodInfoMaterial?.energyKcal, weight)
Timber.d("calculateNutrition foodKcal = ${foodKcal}, energyKcal = ${foodInfo.stFoodInfoMaterial?.energyKcal}, weight = $weight")
grain = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.grainValue(), weight)
fruits = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.fruitsValue(), weight)
vegetable = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.vegetableValue(), weight)
meat = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.meatValue(), weight)
calorie = calculateValue(foodInfo.calorie, weight)
grain = calculateValue(foodInfo.stapleFood, weight)
fruitsVegetables = calculateValue(foodInfo.fruitsVegetables, weight)
meatEggs = calculateValue(foodInfo.meatEggs, weight)
// 合并用户数据
grain += userModel.stFoodInfoPagoda?.grainValue() ?: 0.0
calorie += nutrition.calorie ?: 0.0
grain += nutrition.stapleFood ?: 0.0
fruitsVegetables += nutrition.fruitsVegetables ?: 0.0
meatEggs += nutrition.meatEggs ?: 0.0
fruits += userModel.stFoodInfoPagoda?.fruitsValue() ?: 0.0
vegetable = vegetable.plus(userModel.stFoodInfoPagoda?.vegetableValue() ?: 0.0)
meat += userModel.stFoodInfoPagoda?.meatValue() ?: 0.0
totalKcal = foodKcal + userModel.energyValue()
Timber.d("calculateNutrition totalKcal = ${totalKcal}, energyValue = ${userModel.energyValue()}")
if (totalKcal < 0){
totalKcal = 0.0
}
totalKcal = max(calorie, 0.0)
// 判断当餐最大热量
val maxKcal =
userModel.totalEnergyCalculateScoreValue() * calculateDinnerTypeRatio(dinnerType) / 10
Timber.d("calculateNutrition maxKcal = ${maxKcal}, CalculateScoreValue = ${userModel.totalEnergyCalculateScoreValue()}")
val pagoda = userModel.stFoodInfoPagoda
val fruitsInfo = parseRecommend(pagoda?.fruitsRecommend, fruits)
val vegetableInfo = parseRecommend(pagoda?.vegetableRecommend, vegetable)
//val maxKcal = userModel.totalEnergyCalculateScoreValue() * calculateDinnerTypeRatio(dinnerType) / 10
//Timber.d("calculateNutrition maxKcal = ${maxKcal}, CalculateScoreValue = ${userModel.totalEnergyCalculateScoreValue()}")
// TODO: 测试数据-------------------------------
val rate = calculateDinnerTypeRatio(dinnerType) / 10.0
val maxKcal = totalKcal/ 0.26 / rate
val grainRecommend = "0-100"
val meatRecommend = "0-100"
val fruitsRecommend = "0-100"
// TODO: 测试数据-------------------------------
val calcResult = CalcResultInfo(
totalKcal = CalcInfo(
max = maxKcal,
min = 0.0,
current = totalKcal
),
grain = parseRecommend(pagoda?.grainRecommend, grain),
fruits = CalcInfo( // 果蔬 = 水果+蔬菜
max = fruitsInfo.max + vegetableInfo.max,
min = fruitsInfo.min + vegetableInfo.min,
current = fruitsInfo.current + vegetableInfo.current
),
meat = parseRecommend(pagoda?.meatRecommend, meat)
grain = parseRecommend(grainRecommend, grain),
fruits = parseRecommend(fruitsRecommend, fruitsVegetables),
meat = parseRecommend(meatRecommend, meatEggs)
)
return calcResult
}
// fun calculateNutrition(
// foodInfo: FoodInfo,
// userModel: UserNutritionData,
//// userModel: UserNutrition,
// weight: Double,
// dinnerType: String
// ): CalcResultInfo {
//
// // 初始化变量
// var foodKcal = 0.0
// var totalKcal = 0.0
// var (vegetable, meat, fruits, grain) = List(4) { 0.0 }
//
// // 处理食物信息
// foodKcal = calculateValue(foodInfo.stFoodInfoMaterial?.energyKcal, weight)
// Timber.d("calculateNutrition foodKcal = ${foodKcal}, energyKcal = ${foodInfo.stFoodInfoMaterial?.energyKcal}, weight = $weight")
// grain = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.grainValue(), weight)
// fruits = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.fruitsValue(), weight)
// vegetable = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.vegetableValue(), weight)
// meat = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.meatValue(), weight)
//
// // 合并用户数据
// grain += userModel.stFoodInfoPagoda?.grainValue() ?: 0.0
//
// fruits += userModel.stFoodInfoPagoda?.fruitsValue() ?: 0.0
// vegetable = vegetable.plus(userModel.stFoodInfoPagoda?.vegetableValue() ?: 0.0)
// meat += userModel.stFoodInfoPagoda?.meatValue() ?: 0.0
//
// totalKcal = foodKcal + userModel.energyValue()
// Timber.d("calculateNutrition totalKcal = ${totalKcal}, energyValue = ${userModel.energyValue()}")
// if (totalKcal < 0) {
// totalKcal = 0.0
// }
// // 判断当餐最大热量
// val maxKcal =
// userModel.totalEnergyCalculateScoreValue() * calculateDinnerTypeRatio(dinnerType) / 10
// Timber.d("calculateNutrition maxKcal = ${maxKcal}, CalculateScoreValue = ${userModel.totalEnergyCalculateScoreValue()}")
// val pagoda = userModel.stFoodInfoPagoda
// val fruitsInfo = parseRecommend(pagoda?.fruitsRecommend, fruits)
// val vegetableInfo = parseRecommend(pagoda?.vegetableRecommend, vegetable)
// val calcResult = CalcResultInfo(
// totalKcal = CalcInfo(
// max = maxKcal,
// min = 0.0,
// current = totalKcal
// ),
// grain = parseRecommend(pagoda?.grainRecommend, grain),
// fruits = CalcInfo( // 果蔬 = 水果+蔬菜
// max = fruitsInfo.max + vegetableInfo.max,
// min = fruitsInfo.min + vegetableInfo.min,
// current = fruitsInfo.current + vegetableInfo.current
// ),
// meat = parseRecommend(pagoda?.meatRecommend, meat)
// )
// return calcResult
// }
fun parseRecommend(recommend: String?, current: Double): CalcInfo {
var newCurrent = if (current < 0) 0.0 else current
if (TextUtils.isEmpty(recommend) || !recommend!!.contains("-")) {
@@ -29,8 +29,12 @@ import com.arcsoft.face.ErrorInfo
import com.sw.dualscreen.R
import com.sw.dualscreen.activity.PayActivity
import com.sw.dualscreen.databinding.PresentationFacePayBinding
import com.sw.dualscreen.ext.format2String
import com.sw.dualscreen.ext.load
import com.sw.dualscreen.model.response.MemberInfo
import com.sw.dualscreen.model.response.TextBean
import com.sw.dualscreen.utils.GsonUtils
import com.sw.dualscreen.utils.SpannedUtils
import com.sw.dualscreen.view.CustomDialog
import com.sw.dualscreen.viewmodel.UserViewModel
import com.sw.plate.utils.ToastUtils
@@ -57,7 +61,7 @@ class FacePayPresentation(
val recognizeViewModel: RecognizeViewModel,
// val //parentTextureView: TextureView,
private val onDismissListener: () -> Unit = {}
) : Presentation(activity, display) , ViewTreeObserver.OnGlobalLayoutListener {
) : Presentation(activity, display), ViewTreeObserver.OnGlobalLayoutListener {
companion object {
private const val TAG = "FacePayPresentation"
@@ -99,7 +103,12 @@ class FacePayPresentation(
var payAmount: String? = null
private fun initView() {
binding.tvFoodName.text = foodName
binding.tvRealAmount.text = getAmountText(payAmount ?: "")
binding.tvRealAmount.text = SpannedUtils.getAmountText(
listOf(
TextBean(text = "¥", textSize = 32),
TextBean(text = payAmount ?: "", textSize = 48),
)
)
// binding.ivPreviewImage.let {
// it.outlineProvider = object : ViewOutlineProvider() {
// override fun getOutline(view: View, outline: Outline) {
@@ -110,19 +119,13 @@ class FacePayPresentation(
// }
}
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)
}
}
override fun onGlobalLayout() {
Timber.tag(TAG).d("onGlobalLayout")
binding.dualCameraTexturePreviewRgb.getViewTreeObserver().removeOnGlobalLayoutListener(this)
//parentTextureView.getViewTreeObserver().removeOnGlobalLayoutListener(this)
openCamera()
}
private fun openCamera() {
Timber.tag(TAG).d("openCamera")
if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) !=
@@ -168,33 +171,13 @@ class FacePayPresentation(
}
}
}
// activity.lifecycleScope.launch {
// userViewModel.nutritionData.collect {
// Timber.tag(TAG).d("registerDataChange nutritionData = $it")
// userNutritionData = it
// if (it == null) return@collect
// step3ShowRecognizeResult()
// //binding.nutritionInclude.tvUserName.text = it.userName.maskName()
// //binding.nutritionInclude.tvRecommendHeat.text = "推荐热量:${it.recommendMin}-${it.recommendMax}"
// //updateWeight(lastWeight / 1000)
// }
// }
// activity.lifecycleScope.launch {
// userViewModel.dinnerTypeInfo.drop(1).collect {
// Timber.tag(TAG).d("registerDataChange dinnerTypeInfo = $it")
// dinnerTypeInfo = it
// }
// }
}
override fun onStop() {
if (rgbCameraHelper != null) {
rgbCameraHelper!!.release()
rgbCameraHelper = null
}
if (irCameraHelper != null) {
irCameraHelper!!.release()
irCameraHelper = null
}
rgbCameraHelper?.release()
rgbCameraHelper = null
irCameraHelper?.release()
irCameraHelper = null
recognizeViewModel.destroy()
super.onStop()
}
@@ -202,8 +185,8 @@ class FacePayPresentation(
fun resumeCamera() {
Timber.tag(TAG).d("resumeCamera isRecognition = $isRecognition")
isRecognition = true
if (rgbCameraHelper != null && rgbCameraHelper!!.isStopped) {
rgbCameraHelper!!.start()
if (rgbCameraHelper?.isStopped == true) {
rgbCameraHelper?.start()
}
}
@@ -249,7 +232,8 @@ class FacePayPresentation(
recognizeViewModel.recognizeConfiguration
.observe(activity, Observer { recognizeConfiguration: RecognizeConfiguration? ->
Timber.tag(TAG).i("recognizeConfiguration: observe = ${recognizeConfiguration.toString()}")
Timber.tag(TAG)
.i("recognizeConfiguration: observe = ${recognizeConfiguration.toString()}")
})
recognizeViewModel.recognizeNotice.observe(activity, Observer { notice: String? ->
Timber.tag(TAG).i("recognizeNotice observe notice = $notice")
@@ -258,45 +242,15 @@ class FacePayPresentation(
recognizeViewModel.recognizeUserId.observe(
activity,
Observer { compareResult: CompareResult ->
Timber.tag(TAG).i("recognizeUserId observe compareResult = ${compareResult.trackId}, userId = ${compareResult.faceEntity.userName}")
Timber.tag(TAG)
.i("recognizeUserId observe compareResult = ${compareResult.trackId}, userId = ${compareResult.faceEntity.userName}")
// recognitionTime = System.currentTimeMillis()
// recognitionWeight = lastWeight
lastFaceTrackId = compareResult.trackId
val faceEntity = compareResult.faceEntity
val userId = faceEntity.userName
if (userId == null ) return@Observer
activity.runOnUiThread {
//ToastUtils.showToast("用户人脸识别成功,挑战支付页面")
showWaitingDialog("刷脸支付中,请稍后……")
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,
// foodId = currentFood!!.id!!
// )
if (userId == null) return@Observer
faceRecSuccess(userId)
})
recognizeViewModel.drawRectInfoText.observe(activity, Observer { info ->
@@ -388,7 +342,8 @@ class FacePayPresentation(
displayOrientation: Int,
isMirror: Boolean
) {
Timber.tag(TAG).d("initRgbCamera Rgb onCameraOpened: cameraId = $cameraId, displayOrientation = $displayOrientation")
Timber.tag(TAG)
.d("initRgbCamera Rgb onCameraOpened: cameraId = $cameraId, displayOrientation = $displayOrientation")
activity.runOnUiThread({
val previewSizeRgb = camera.getParameters().getPreviewSize()
val layoutParams = adjustPreviewViewSize(
@@ -397,8 +352,10 @@ class FacePayPresentation(
previewSizeRgb, displayOrientation, 0.6F
)
Timber.tag(TAG).d("initRgbCamera previewSizeRgb = ${previewSizeRgb.width}-${previewSizeRgb.height}")
Timber.tag(TAG).d("initRgbCamera layoutParams = ${layoutParams.width}-${layoutParams.height}")
Timber.tag(TAG)
.d("initRgbCamera previewSizeRgb = ${previewSizeRgb.width}-${previewSizeRgb.height}")
Timber.tag(TAG)
.d("initRgbCamera layoutParams = ${layoutParams.width}-${layoutParams.height}")
Timber.tag(TAG).d(
"initRgbCamera isMirror = ${isMirror}, isDrawRgbRectHorizontalMirror = ${
ConfigUtil.isDrawRgbRectHorizontalMirror(
@@ -454,16 +411,19 @@ class FacePayPresentation(
}
override fun onCameraConfigurationChanged(cameraID: Int, displayOrientation: Int) {
Timber.tag(TAG).i("initRgbCamera onCameraConfigurationChanged: threadName = ${Thread.currentThread().name}")
Timber.tag(TAG)
.i("initRgbCamera onCameraConfigurationChanged: threadName = ${Thread.currentThread().name}")
if (rgbFaceRectTransformer != null) {
rgbFaceRectTransformer!!.cameraDisplayOrientation = displayOrientation
}
Timber.tag(TAG).i("initRgbCamera onCameraConfigurationChanged: $cameraID $displayOrientation")
Timber.tag(TAG)
.i("initRgbCamera onCameraConfigurationChanged: $cameraID $displayOrientation")
}
}
val measuredWidth = binding.dualCameraTexturePreviewRgb.measuredWidth
val measuredHeight = binding.dualCameraTexturePreviewRgb.measuredHeight
Timber.tag(TAG).i("initRgbCamera measuredWidth=$measuredWidthmeasuredHeight=$measuredHeight")
val measuredHeight = binding.dualCameraTexturePreviewRgb.measuredHeight
Timber.tag(TAG)
.i("initRgbCamera measuredWidth=$measuredWidthmeasuredHeight=$measuredHeight")
val previewConfig: PreviewConfig = recognizeViewModel.previewConfig
rgbCameraHelper = DualCameraHelper.Builder()
@@ -498,7 +458,8 @@ class FacePayPresentation(
displayOrientation: Int,
isMirror: Boolean
) {
Timber.tag(TAG).d("initIrCamera IR onCameraOpened: cameraId = $cameraId, displayOrientation = $displayOrientation")
Timber.tag(TAG)
.d("initIrCamera IR onCameraOpened: cameraId = $cameraId, displayOrientation = $displayOrientation")
val previewSizeIr = camera.getParameters().getPreviewSize()
val layoutParams = adjustPreviewViewSize(
binding.dualCameraTexturePreviewRgb,
@@ -539,7 +500,8 @@ class FacePayPresentation(
if (irFaceRectTransformer != null) {
irFaceRectTransformer!!.cameraDisplayOrientation = displayOrientation
}
Timber.tag(TAG).i("initIrCamera onCameraConfigurationChanged: cameraID = $cameraID, displayOrientation = $displayOrientation")
Timber.tag(TAG)
.i("initIrCamera onCameraConfigurationChanged: cameraID = $cameraID, displayOrientation = $displayOrientation")
}
}
@@ -586,22 +548,24 @@ class FacePayPresentation(
if (facePreviewInfoList.isEmpty() || (lastFaceTrackId != facePreviewInfoList[0]!!.trackId)) {
if (lastFaceTrackId != -1) {
// mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
// Timber.tag(TAG).i("$lastFaceTrackId 用户离开")
// lastFaceTrackId = -1
// postUserData()
// if (mealPickupMode == 0) {
// step1FoodRecognizing()
// } else {
// step2FaceRecognizing(currentFood!!)
// }
// mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
// Timber.tag(TAG).i("$lastFaceTrackId 用户离开")
// lastFaceTrackId = -1
// postUserData()
// if (mealPickupMode == 0) {
// step1FoodRecognizing()
// } else {
// step2FaceRecognizing(currentFood!!)
// }
resumeCamera()
}
}
}
private var lastFaceTrackId: Int = -1 // 上一次的人脸信息
private var mDialogWaiting:CustomDialog?=null
private var mDialogWaiting: CustomDialog? = null
/**
* 显示等待提示框
*/
@@ -627,4 +591,49 @@ class FacePayPresentation(
super.onDisplayRemoved()
onDismissListener()
}
private fun faceRecSuccess(userId: String) {
activity.runOnUiThread {
showWaitingDialog("加载中,请稍后……")
}
getMemberInfo(userId) { memberInfo ->
bindOrder(userId) {
binding.root.postDelayed({
hideWaitingDialog()
activity.showPayInfo(type = 1, isVip = true, memberInfo = memberInfo)
binding.root.postDelayed({
dismiss()
}, 500)
}, 1500)
}
}
}
private fun bindOrder(userId:String, block:()-> Unit) {
userViewModel.bindOrder(userId, activity.foodOrderId) { bindResult ->
activity.runOnUiThread {
if (bindResult.not()) {
hideWaitingDialog()
ToastUtils.showToast("订单绑定失败")
return@runOnUiThread
}
block()
}
}
}
private fun getMemberInfo(userId: String, block:(MemberInfo)-> Unit) {
userViewModel.getMemberInfo(memberId = userId) { memberInfo ->
activity.runOnUiThread {
if (memberInfo == null) {
hideWaitingDialog()
ToastUtils.showToast("查询会员信息失败,请稍后重试")
return@runOnUiThread
}
block(memberInfo)
}
}
}
}