支付完成倒计时3秒返回首页;秤默认置零取消,打开直接识别物品;人脸识别图片显示拉伸优化;设置页面切换是否收费模式首页逻辑处理;
This commit is contained in:
Generated
+2
-2
@@ -4,10 +4,10 @@
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2025-12-10T08:38:49.440422600Z">
|
||||
<DropdownSelection timestamp="2025-12-17T09:12:02.352767500Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="Default" identifier="serial=192.168.1.177:5555;connection=45709318" />
|
||||
<DeviceId pluginId="Default" identifier="serial=192.168.1.118:5555;connection=50c01ec0" />
|
||||
</handle>
|
||||
</Target>
|
||||
</DropdownSelection>
|
||||
|
||||
@@ -117,6 +117,7 @@ dependencies {
|
||||
|
||||
implementation(libs.androidx.recyclerview)
|
||||
|
||||
implementation("org.greenrobot:eventbus:3.2.0")
|
||||
}
|
||||
|
||||
apply(plugin = "io.objectbox")
|
||||
@@ -17,9 +17,13 @@ import androidx.lifecycle.lifecycleScope
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.model.IActivityResult
|
||||
import com.sw.dualscreen.model.response.PostEvent
|
||||
import com.sw.dualscreen.view.CustomDialog
|
||||
import com.sw.dualscreen.viewmodel.BaseViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import timber.log.Timber
|
||||
|
||||
|
||||
@@ -37,6 +41,7 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
EventBus.getDefault().register(this)
|
||||
enableEdgeToEdge()
|
||||
context = this
|
||||
|
||||
@@ -50,6 +55,11 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
registerDataChange()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
EventBus.getDefault().unregister(this)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
abstract fun getViewModel(): BaseViewModel
|
||||
|
||||
protected abstract fun inflateViewBinding(): VB
|
||||
@@ -122,4 +132,9 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
) { result: Boolean ->
|
||||
launchPermissionCallback?.callback(result)
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onPostEvent(event: PostEvent) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.text.TextUtils
|
||||
import android.view.Display
|
||||
import android.view.View
|
||||
import android.view.ViewOutlineProvider
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
@@ -30,8 +31,10 @@ import com.sw.dualscreen.ext.dp
|
||||
import com.sw.dualscreen.ext.gone
|
||||
import com.sw.dualscreen.ext.load
|
||||
import com.sw.dualscreen.ext.visible
|
||||
import com.sw.dualscreen.model.response.ChargeModeEvent
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
import com.sw.dualscreen.model.response.FoodOrder
|
||||
import com.sw.dualscreen.model.response.PaySuccessEvent
|
||||
import com.sw.dualscreen.objbox.FoodModule
|
||||
import com.sw.dualscreen.objbox.FoodModule.IdNameScore
|
||||
import com.sw.dualscreen.presentation.MainScreenPresentation
|
||||
@@ -47,6 +50,8 @@ import com.sw.dualscreen.viewmodel.UserViewModel
|
||||
import com.sw.plate.utils.LightManager
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.time.LocalDateTime
|
||||
@@ -55,6 +60,7 @@ import java.time.format.DateTimeFormatter
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.text.compareTo
|
||||
|
||||
/**
|
||||
* 服务员显示界面
|
||||
@@ -106,6 +112,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
private var lastPhotoUri: Uri? = null // 最后拍照的图片
|
||||
private var debouncer = Debouncer(2000)
|
||||
private var isRecognitionFood = true
|
||||
private var isFirstOpen = true
|
||||
|
||||
override fun getViewModel(): BaseViewModel {
|
||||
return viewModel
|
||||
@@ -120,18 +127,16 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
addBackEventListener()
|
||||
FoodModule.init(this)
|
||||
initView()
|
||||
setupSecondaryDisplay()
|
||||
viewModel.getUserFaceCache(pageNo = 1)
|
||||
//setupSecondaryDisplay()
|
||||
setupCamera()
|
||||
//presentation?.step1FoodRecognizing()
|
||||
initData()
|
||||
}
|
||||
|
||||
private fun initData() {
|
||||
// viewModel.getEquipmentToken()
|
||||
viewModel.getUserFaceCache(pageNo = 1)
|
||||
//viewModel.getUserFaceCache2()
|
||||
|
||||
// presentation?.step1()
|
||||
presentation?.step1FoodRecognizing()
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
@@ -146,7 +151,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
updateDateTime()
|
||||
binding.ivSetting.setOnClickListener {
|
||||
startActivity(Intent(this, SettingActivity::class.java))
|
||||
finish()
|
||||
//finish()
|
||||
}
|
||||
//binding.foodDisplayLayout.setOnClickListener {
|
||||
// val intent = Intent(this, FoodCollectionActivity::class.java)
|
||||
@@ -218,59 +223,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
// binding.tvRescan.setOnClickListener {
|
||||
// debouncer.debounce { recognizeFood() }
|
||||
// }
|
||||
binding.btnPay.let {
|
||||
it.run {
|
||||
val mode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
if (mode == 0) visible() else gone()
|
||||
}
|
||||
it.setOnClickListener { v ->
|
||||
if (checkedItem == null) {
|
||||
ToastUtils.showToast("暂无识别数据,请搜索选择")
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
//val realWeight = (lastWeight * 1000).roundToInt()
|
||||
val mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0) ?: 0
|
||||
var foodWeight = 0.0
|
||||
var eatWeight = 0.0
|
||||
if (chargeMode == 0) {
|
||||
//计费
|
||||
if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
eatWeight = lastWeight * 1000
|
||||
foodWeight = lastWeight * 1000
|
||||
} else {
|
||||
//余量计量
|
||||
eatWeight = (recognizeWeight - lastWeight) * 1000
|
||||
foodWeight = recognizeWeight * 1000
|
||||
}
|
||||
} else {
|
||||
//不计费
|
||||
foodWeight = recognizeWeight * 1000
|
||||
eatWeight = if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
recognizeWeight * 1000
|
||||
} else {
|
||||
//余量计量
|
||||
(recognizeWeight - lastWeight) * 1000
|
||||
}
|
||||
}
|
||||
val eatNum = getEatNum(eatWeight, checkedItem!!.specWeight)
|
||||
createOrder(
|
||||
foodInfo = checkedItem!!,
|
||||
foodWeight = foodWeight.roundToInt(),
|
||||
eatWeight = eatWeight.roundToInt(),
|
||||
eatNum = eatNum
|
||||
) {
|
||||
presentation?.dismiss()
|
||||
startActivity(Intent(this, PayActivity::class.java).apply {
|
||||
putExtra(PayActivity.FOOD_INFO, checkedItem!!)
|
||||
putExtra(PayActivity.FOOD_EAT_NUM, eatNum)
|
||||
putExtra(PayActivity.FOOD_ORDER_ID, foodOrderId)
|
||||
})
|
||||
}
|
||||
}
|
||||
binding.btnPay.setOnClickListener {
|
||||
clickPayButton()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,19 +242,22 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
recognizeWeight = lastWeight
|
||||
presentation?.updateFood(foodInfo)
|
||||
binding.tvFoodName.text = foodInfo.foodName
|
||||
binding.previewView.visibility = View.GONE
|
||||
binding.ivImg.visibility = View.VISIBLE
|
||||
binding.previewView.gone()
|
||||
binding.ivImg.visible()
|
||||
if (foodInfo.foodImg.isNullOrBlank()) {
|
||||
takePhoto { imgUri ->
|
||||
binding.ivImg.load(imgUri)
|
||||
presentation?.updateFood(foodInfo.copy(foodImg = imgUri.toString()))
|
||||
}
|
||||
} else {
|
||||
binding.ivImg.load(foodInfo.photoUri ?: foodInfo.foodImg)
|
||||
}
|
||||
binding.ivImg.load(foodInfo.foodImg ?: foodInfo.photoUri)
|
||||
//pauseAnalysis()
|
||||
}
|
||||
|
||||
fun updateImage(imgUrl: Any?) {
|
||||
binding.ivImg.load(imgUrl)
|
||||
}
|
||||
|
||||
override fun registerDataChange() {
|
||||
super.registerDataChange()
|
||||
//// lifecycleScope.launch {
|
||||
@@ -326,23 +283,30 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
|
||||
SensorScaleUtils.addWeightListener { weight ->
|
||||
Timber.d("registerDataChange weight = $weight")
|
||||
val isWeightChange = weight - lastWeight > 0.05
|
||||
recognizeByWeight(weight, isWeightChange)
|
||||
}
|
||||
}
|
||||
|
||||
private fun recognizeByWeight(weight: Double, isWeightChange: Boolean, block: () -> Unit = {}) {
|
||||
presentation?.updateWeight(weight)
|
||||
|
||||
if (weight <= 0.005) {//余量取餐,检测到秤上没有东西,重新启动识别菜品 && presentation?.mealPickupMode == 1
|
||||
isRecognitionFood = true
|
||||
}
|
||||
|
||||
if (weight - lastWeight > 0.05 && isRecognitionFood) { // 大于50g
|
||||
if (isWeightChange && isRecognitionFood) { // 大于50g
|
||||
if (presentation?.mealPickupMode == 1) {
|
||||
isRecognitionFood = false
|
||||
}
|
||||
debouncer.debounce {
|
||||
recognizeFood()
|
||||
}
|
||||
} else {
|
||||
block()
|
||||
}
|
||||
lastWeight = weight
|
||||
}
|
||||
}
|
||||
|
||||
fun recognizeFood() {
|
||||
LightManager.openRedLight()
|
||||
@@ -590,9 +554,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
|
||||
override fun onError(exception: ImageCaptureException) {
|
||||
Timber.e("拍照失败: ${exception.message}")
|
||||
runOnUiThread {
|
||||
ToastUtils.showToast("拍照失败: ${exception.message}")
|
||||
}
|
||||
//runOnUiThread {
|
||||
// ToastUtils.showToast("拍照失败: ${exception.message}")
|
||||
//}
|
||||
// 恢复图像分析
|
||||
isAnalyzing = true
|
||||
}
|
||||
@@ -600,13 +564,21 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
)
|
||||
}
|
||||
|
||||
private fun setupSecondaryDisplay() {
|
||||
private fun getSecondaryDisplay(): Display? {
|
||||
val displayManager = getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
|
||||
val displays = displayManager.displays
|
||||
|
||||
// 查找副屏(通常索引为1)
|
||||
if (displays.size > 1) {
|
||||
val secondaryDisplay = displays[1]
|
||||
if (displays.size > 1) return displays[1]
|
||||
return null
|
||||
}
|
||||
|
||||
private fun setupSecondaryDisplay() {
|
||||
val secondaryDisplay = getSecondaryDisplay()
|
||||
if (secondaryDisplay == null) {
|
||||
ToastUtils.showToast("获取副屏失败")
|
||||
return
|
||||
}
|
||||
// 创建副屏的Presentation
|
||||
presentation = MainScreenPresentation(
|
||||
activity = this,
|
||||
@@ -621,6 +593,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
bottomSheetDialog?.dismiss()
|
||||
}
|
||||
}
|
||||
show()
|
||||
}
|
||||
//SecondaryScreenPresentation(
|
||||
// activity = this,
|
||||
@@ -636,10 +609,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
// bottomSheetDialog?.dismiss()
|
||||
// }
|
||||
// }
|
||||
presentation!!.show()
|
||||
} else {
|
||||
ToastUtils.showToast("获取副屏失败")
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
@@ -651,7 +620,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
|
||||
override fun onDestroy() {
|
||||
//SensorScaleUtils.closeScale()
|
||||
presentation?.dismiss()
|
||||
presentation?.cancel()
|
||||
super.onDestroy()
|
||||
shutdownCamera()
|
||||
}
|
||||
@@ -664,16 +633,45 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
Timber.tag("onResume").d("=================onResume================")
|
||||
// 启动定时器
|
||||
handler.postDelayed(timeoutRunnable, TIME_OUT)
|
||||
|
||||
if (presentation?.isShowing == false) {
|
||||
if (isFirstOpen) {
|
||||
//首次
|
||||
setupSecondaryDisplay()
|
||||
presentation?.step1FoodRecognizing()
|
||||
isFirstOpen = false
|
||||
} else {
|
||||
//副屏未显示重新加载
|
||||
isRecognitionFood = true
|
||||
if (presentation == null || !presentation!!.isShowing) {
|
||||
lastWeight = 0.0
|
||||
setupSecondaryDisplay()
|
||||
presentation?.step1FoodRecognizing()
|
||||
} else {
|
||||
//已显示副屏,则进行更新
|
||||
val weight = lastWeight
|
||||
lastWeight = 0.0
|
||||
presentation?.hideRecImage()
|
||||
recognizeByWeight(weight, true)
|
||||
}
|
||||
val mode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0)
|
||||
presentation?.updateMealPickupMode(mode ?: 0)
|
||||
}
|
||||
|
||||
//根据付费模式确认是否显示按钮
|
||||
binding.btnPay.run {
|
||||
val mode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
if (mode == 0) visible() else gone()
|
||||
}
|
||||
}
|
||||
|
||||
// fun retry() {
|
||||
// val weight = lastWeight
|
||||
// lastWeight = 0.0
|
||||
// presentation?.hideRecImage()
|
||||
// recognizeByWeight(weight, true)
|
||||
// }
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
// 取消定时器
|
||||
@@ -712,12 +710,14 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
block: () -> Unit
|
||||
) {
|
||||
Timber.tag(TAG).d("foodWeight=$foodWeight,eatWeight=$eatWeight")
|
||||
val pickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
if (pickupMode == 0) {
|
||||
if (foodWeight <= 5 || eatWeight <= 5) {
|
||||
ToastUtils.showToast("请取走餐品")
|
||||
return
|
||||
}
|
||||
}
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
val pickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
val order = FoodOrder(
|
||||
deviceId = GlobalData.deviceId,
|
||||
foodId = foodInfo.foodId,
|
||||
@@ -768,4 +768,67 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
})
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onPaySuccessEvent(event: PaySuccessEvent) {
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)?:0
|
||||
presentation?.hideNutritionView(chargeMode)
|
||||
presentation?.cancel()
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onChargeModeEvent(event: ChargeModeEvent) {
|
||||
presentation?.hideNutritionView(event.chargeMode)
|
||||
// presentation?.cancel()
|
||||
}
|
||||
|
||||
private fun clickPayButton() {
|
||||
if (checkedItem == null) {
|
||||
ToastUtils.showToast("暂无识别数据,请搜索选择")
|
||||
return
|
||||
}
|
||||
|
||||
//val realWeight = (lastWeight * 1000).roundToInt()
|
||||
val mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0) ?: 0
|
||||
var foodWeight = 0.0
|
||||
var eatWeight = 0.0
|
||||
if (chargeMode == 0) {
|
||||
//计费
|
||||
if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
eatWeight = lastWeight * 1000
|
||||
foodWeight = lastWeight * 1000
|
||||
} else {
|
||||
//余量计量
|
||||
eatWeight = (recognizeWeight - lastWeight) * 1000
|
||||
foodWeight = recognizeWeight * 1000
|
||||
}
|
||||
} else {
|
||||
//不计费
|
||||
foodWeight = recognizeWeight * 1000
|
||||
eatWeight = if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
recognizeWeight * 1000
|
||||
} else {
|
||||
//余量计量
|
||||
(recognizeWeight - lastWeight) * 1000
|
||||
}
|
||||
}
|
||||
val eatNum = getEatNum(eatWeight, checkedItem!!.specWeight)
|
||||
createOrder(
|
||||
foodInfo = checkedItem!!,
|
||||
foodWeight = foodWeight.roundToInt(),
|
||||
eatWeight = eatWeight.roundToInt(),
|
||||
eatNum = eatNum
|
||||
) {
|
||||
// TODO: 暂不关闭首页副屏
|
||||
//presentation?.dismiss()
|
||||
startActivity(Intent(this, PayActivity::class.java).apply {
|
||||
putExtra(PayActivity.FOOD_INFO, checkedItem!!)
|
||||
putExtra(PayActivity.FOOD_EAT_NUM, eatNum)
|
||||
putExtra(PayActivity.FOOD_ORDER_ID, foodOrderId)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,12 +13,14 @@ import com.sw.dualscreen.databinding.ActivityPayBinding
|
||||
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.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
|
||||
|
||||
class PayActivity : BaseActivity<ActivityPayBinding>() {
|
||||
|
||||
@@ -170,6 +172,7 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
|
||||
}
|
||||
|
||||
fun showPaySuccess(isVip: Boolean) {
|
||||
EventBus.getDefault().post(PaySuccessEvent())
|
||||
showPayInfo(type = 2, isVip = isVip, memberInfo = memberInfo)
|
||||
hidePayTab()
|
||||
}
|
||||
@@ -256,6 +259,7 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fun bindOrder(userId: String, block: () -> Unit) {
|
||||
// val pickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0)
|
||||
// val mode = if (pickupMode == 1) 1 else 2
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.sw.dualscreen.activity
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.activity.viewModels
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.sw.dualscreen.R
|
||||
@@ -10,8 +9,6 @@ import com.sw.dualscreen.databinding.ActivitySettingBinding
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
import com.sw.dualscreen.viewmodel.BaseViewModel
|
||||
import com.sw.dualscreen.viewmodel.UserViewModel
|
||||
import kotlin.collections.get
|
||||
import kotlin.text.replace
|
||||
|
||||
class SettingActivity : BaseActivity<ActivitySettingBinding>() {
|
||||
|
||||
@@ -33,8 +30,8 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>() {
|
||||
super.initialize()
|
||||
binding.include.let {
|
||||
it.ivPageBack.setOnClickListener {
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
startActivity(intent)
|
||||
// val intent = Intent(this, MainActivity::class.java)
|
||||
// startActivity(intent)
|
||||
finish()
|
||||
}
|
||||
it.tvPageTitle.text = "设置"
|
||||
|
||||
@@ -9,6 +9,10 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.sw.dualscreen.model.response.PostEvent
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
||||
abstract class BaseFragment<VB : ViewBinding>: Fragment() {
|
||||
|
||||
@@ -36,4 +40,21 @@ abstract class BaseFragment<VB : ViewBinding>: Fragment() {
|
||||
initialize()
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onPostEvent(event: PostEvent) {
|
||||
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
EventBus.getDefault().register(this)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
EventBus.getDefault().unregister(this)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -4,9 +4,11 @@ import android.view.LayoutInflater
|
||||
import com.sw.dualscreen.GlobalKey
|
||||
import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.databinding.FragmentBusinessBinding
|
||||
import com.sw.dualscreen.model.response.ChargeModeEvent
|
||||
import com.sw.dualscreen.sdk.SensorScaleUtils
|
||||
import com.sw.dualscreen.utils.SPUtil
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class BusinessFragment: BaseFragment<FragmentBusinessBinding>() {
|
||||
@@ -44,13 +46,21 @@ class BusinessFragment: BaseFragment<FragmentBusinessBinding>() {
|
||||
ToastUtils.showToast("请设置取餐模式")
|
||||
return@setOnClickListener
|
||||
}
|
||||
var mode = if (binding.rgCharge.checkedRadioButtonId == R.id.rbChargeYes) 0 else 1
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_CHARGE_MODE, mode)
|
||||
|
||||
mode = if (binding.rgTakeFood.checkedRadioButtonId == R.id.rbPickAndPlace) 0 else 1
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_PICKUP_MODE, mode)
|
||||
val chargeMode = if (binding.rgCharge.checkedRadioButtonId == R.id.rbChargeYes) 0 else 1
|
||||
//原来的支付模式
|
||||
val oldChargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
if (chargeMode != oldChargeMode) {
|
||||
//支付模式有变化通知首页页面刷新
|
||||
EventBus.getDefault().post(ChargeModeEvent(chargeMode))
|
||||
}
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_CHARGE_MODE, chargeMode)
|
||||
|
||||
val pickupMode = if (binding.rgTakeFood.checkedRadioButtonId == R.id.rbPickAndPlace) 0 else 1
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_PICKUP_MODE, pickupMode)
|
||||
|
||||
ToastUtils.showToast("设置已保存")
|
||||
activity?.finish()
|
||||
}
|
||||
SensorScaleUtils.addWeightListener { value ->
|
||||
val realWeight = (value * 1000).roundToInt()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.sw.dualscreen.activity.fragment.pay
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.activity.PayActivity
|
||||
import com.sw.dualscreen.activity.fragment.BaseFragment
|
||||
@@ -11,10 +12,13 @@ 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.PaySuccessEvent
|
||||
import com.sw.dualscreen.model.response.TextBean
|
||||
import com.sw.dualscreen.utils.IntervalExecutor
|
||||
import com.sw.dualscreen.utils.SpannedUtils
|
||||
import com.sw.dualscreen.utils.countDownByFlow
|
||||
import kotlinx.coroutines.Job
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
class PayResultFragment : BaseFragment<FragmentPayResultBinding>() {
|
||||
|
||||
@@ -42,6 +46,23 @@ class PayResultFragment : BaseFragment<FragmentPayResultBinding>() {
|
||||
return FragmentPayResultBinding.inflate(layoutInflater)
|
||||
}
|
||||
|
||||
private var countDownJob: Job? = null
|
||||
private fun closePageCountDown() {
|
||||
countDownJob = countDownByFlow(
|
||||
total = 3,
|
||||
scope = lifecycleScope,
|
||||
onStart = {
|
||||
binding.btnBack.text = "返回(3s)..."
|
||||
},
|
||||
onTick = { seconds ->
|
||||
binding.btnBack.text = "返回(${seconds}s)..."
|
||||
},
|
||||
onFinish = {
|
||||
payActivity.finish()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private lateinit var payActivity: PayActivity
|
||||
override fun initialize() {
|
||||
payActivity = activity as PayActivity
|
||||
@@ -153,11 +174,14 @@ class PayResultFragment : BaseFragment<FragmentPayResultBinding>() {
|
||||
binding.tvPayAmount.text = "收款金额 $showTotalPrice 元"
|
||||
|
||||
val showExpensesBalance = expensesBalance.format2String(2)
|
||||
binding.tvPayInfo.text = "应收 $showTotalPrice 元,余额扣除 $showExpensesBalance 元"
|
||||
binding.tvPayInfo.text =
|
||||
"应收 $showTotalPrice 元,余额扣除 $showExpensesBalance 元"
|
||||
} else {
|
||||
binding.tvPayAmount.text = "收款金额 ${totalPrice.format2String(2)} 元"
|
||||
binding.tvPayInfo.text = "应收 ${totalPrice.format2String(2)} 元"
|
||||
}
|
||||
|
||||
closePageCountDown()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
@@ -220,7 +244,10 @@ class PayResultFragment : BaseFragment<FragmentPayResultBinding>() {
|
||||
}
|
||||
|
||||
private fun loadUserInfo(item: MemberInfo) {
|
||||
binding.ivHeadPic.load(item.faceUrl?.ifBlank { R.drawable.ic_avatar_default })
|
||||
binding.ivHeadPic.load(
|
||||
if(item.faceUrl.isNullOrBlank()) R.drawable.ic_avatar_default
|
||||
else item.faceUrl
|
||||
)
|
||||
binding.tvUserName.text = item.name
|
||||
|
||||
val phone = item.phone ?: ""
|
||||
|
||||
@@ -100,6 +100,7 @@ data class UserNutrition(
|
||||
//肉蛋超量
|
||||
val meatEggsExcess: String? = null,
|
||||
)
|
||||
|
||||
//{"code":"00000","data":"{\"orderType\":0,\"orderPayFrom\":2,\"payType\":\"1\",\"paySuc\":0,\"totalFee\":0.01,\"orderCode\":\"1998193614899372032\",\"message\":\"支付成功\",\"payCode\":\"1998193614899372032508227\"}","msg":"成功","total":0}
|
||||
data class PayResult(
|
||||
val paySuc: String? = null
|
||||
@@ -116,3 +117,13 @@ data class RespCodeMsg(
|
||||
val code: String?,
|
||||
val msg: String?
|
||||
)
|
||||
|
||||
|
||||
data class PostEvent(var name:String="")
|
||||
data class PaySuccessEvent(
|
||||
var name: String = ""
|
||||
)
|
||||
|
||||
data class ChargeModeEvent(
|
||||
var chargeMode:Int = 0
|
||||
)
|
||||
@@ -9,11 +9,14 @@ import android.graphics.Point
|
||||
import android.hardware.Camera
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.Display
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewOutlineProvider
|
||||
import android.view.ViewTreeObserver
|
||||
import android.widget.FrameLayout
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.updateLayoutParams
|
||||
@@ -102,6 +105,10 @@ class MainScreenPresentation(
|
||||
private var lastFaceTrackId: Int = -1 // 上一次的人脸信息
|
||||
var mealPickupMode: Int = 0 // 取餐模式 0 即放即取 1 余量取餐
|
||||
|
||||
var isKeepFaceState = true
|
||||
|
||||
var currentUserId: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = PresentationMainScreenBinding.inflate(layoutInflater)
|
||||
@@ -161,10 +168,10 @@ class MainScreenPresentation(
|
||||
Timber.tag(TAG).e("updateWeight userNutritionData is null")
|
||||
return
|
||||
}
|
||||
if (dinnerTypeInfo == null) {
|
||||
Timber.tag(TAG).e("updateWeight dinnerType is null")
|
||||
return
|
||||
}
|
||||
// if (dinnerTypeInfo == null) {
|
||||
// Timber.tag(TAG).e("updateWeight dinnerType is null")
|
||||
// return
|
||||
// }
|
||||
if (chargeMode == 1) {
|
||||
//不计费
|
||||
if (mealPickupMode == 0) {
|
||||
@@ -270,14 +277,15 @@ class MainScreenPresentation(
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
binding.ivRecImage.let {
|
||||
it.outlineProvider = object : ViewOutlineProvider() {
|
||||
override fun getOutline(view: View, outline: Outline) {
|
||||
outline.setRoundRect(0, 0, view.width, view.height, 12f.dp)
|
||||
}
|
||||
}
|
||||
it.clipToOutline = true
|
||||
}
|
||||
// binding.ivRecImage.let {
|
||||
// it.outlineProvider = object : ViewOutlineProvider() {
|
||||
// override fun getOutline(view: View, outline: Outline) {
|
||||
// outline.setRoundRect(0, 0, view.width, view.height, 12f.dp)
|
||||
// }
|
||||
// }
|
||||
// it.clipToOutline = true
|
||||
// }
|
||||
binding.ivPreviewImage.visible()
|
||||
}
|
||||
|
||||
override fun onDisplayRemoved() {
|
||||
@@ -418,6 +426,7 @@ class MainScreenPresentation(
|
||||
binding.flCameraView.visible()
|
||||
binding.ivRecImage.gone()
|
||||
binding.ivPreviewImage.visible()
|
||||
binding.ivFrame.visible()
|
||||
binding.ivFaceRecMask.gone()
|
||||
binding.tvFaceTip.gone()
|
||||
binding.llPriceInfo.gone()
|
||||
@@ -467,7 +476,7 @@ class MainScreenPresentation(
|
||||
|
||||
binding.ivRecImage.gone()
|
||||
binding.ivPreviewImage.gone()
|
||||
|
||||
binding.ivFrame.gone()
|
||||
dinnerTypeInfo = null
|
||||
// userNutritionData = null
|
||||
userNutrition = null
|
||||
@@ -476,11 +485,15 @@ class MainScreenPresentation(
|
||||
stepChangeCallback(currentStep)
|
||||
currentFood = foodInfo
|
||||
|
||||
userViewModel.getDinnerType()
|
||||
// userViewModel.getDinnerType()
|
||||
|
||||
resumeCamera()
|
||||
}
|
||||
|
||||
fun hideRecImage() {
|
||||
binding.ivRecImage.gone()
|
||||
}
|
||||
|
||||
// 当前食物信息
|
||||
private var currentFood: FoodInfo? = null
|
||||
fun updateFood(foodInfo: FoodInfo?) {
|
||||
@@ -491,12 +504,16 @@ class MainScreenPresentation(
|
||||
}
|
||||
binding.tvFoodName.text = foodInfo.foodName
|
||||
binding.ivPreviewImage.gone()
|
||||
binding.ivFrame.gone()
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
if (chargeMode == 0) {
|
||||
binding.ivRecImage.let {
|
||||
it.visible()
|
||||
val imageUrl =
|
||||
if (foodInfo.foodImg.isNullOrBlank()) foodInfo.photoUri else foodInfo.foodImg
|
||||
it.load(imageUrl)
|
||||
}
|
||||
}
|
||||
val mode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
if (mode == 0) {
|
||||
//计费,查询营养信息、价格信息------------------------
|
||||
@@ -537,12 +554,15 @@ class MainScreenPresentation(
|
||||
}
|
||||
|
||||
private fun calculateNutrition(weight1: Double) {
|
||||
if (currentFood == null || userNutrition == null) {
|
||||
return
|
||||
}
|
||||
var weight = weight1
|
||||
if (weight < 0) weight = 0.0
|
||||
debouncer.debounce {
|
||||
Timber.tag(TAG)
|
||||
.d("calculateNutrition weight = $weight, recognitionWeight = $recognitionWeight")
|
||||
val dinnerType = dinnerTypeInfo!!.dinnerType!!
|
||||
val dinnerType = dinnerTypeInfo?.dinnerType
|
||||
// Timber.tag(TAG)
|
||||
// .d("calculateNutrition foodName = ${currentFood!!.foodName}, dinnerType = $dinnerType, userId = ${userNutritionData!!.userId}")
|
||||
val energy: UserEnergy = UserNutritionUtils.calculateNutrition2(
|
||||
@@ -550,7 +570,7 @@ class MainScreenPresentation(
|
||||
// userNutritionData!!,
|
||||
userNutrition!!,
|
||||
weight,
|
||||
dinnerType = dinnerType
|
||||
dinnerType = dinnerType ?: ""
|
||||
)
|
||||
// Timber.tag(TAG).d("calculateNutrition calcResultInfo = $calcResultInfo")
|
||||
// val columnMax = UserNutritionUtils.getMaxInt(calcResultInfo)
|
||||
@@ -570,7 +590,8 @@ class MainScreenPresentation(
|
||||
0.0,
|
||||
userNutrition?.minCalorie ?: 0.0,
|
||||
userNutrition?.recommendCalorie ?: 0.0,
|
||||
((userNutrition?.recommendCalorie?:0.0) + (userNutrition?.maxCalorie?:0.0))/2,
|
||||
((userNutrition?.recommendCalorie ?: 0.0) + (userNutrition?.maxCalorie
|
||||
?: 0.0)) / 2,
|
||||
userNutrition?.maxCalorie ?: 0.0,
|
||||
)
|
||||
val calorieIndex = UserNutritionUtils.findCalorieIndex(energy.grain, calorieArray)
|
||||
@@ -585,9 +606,9 @@ class MainScreenPresentation(
|
||||
include.totalKcalTv.text = totalKcal.format2String(2)
|
||||
var totalKcalHeight = (totalKcal / maxKcal).toFloat()
|
||||
if (totalKcalHeight == 0F) {
|
||||
include.divKcalView.visibility = View.VISIBLE
|
||||
include.divKcalView.visible()
|
||||
} else {
|
||||
include.divKcalView.visibility = View.GONE
|
||||
include.divKcalView.gone()
|
||||
totalKcalHeight += 0.1F
|
||||
}
|
||||
include.customKcalColumn.setCustomHeightPercent(totalKcalHeight, true)
|
||||
@@ -603,9 +624,9 @@ class MainScreenPresentation(
|
||||
include.totalFoodTv.text = grain.format2String(2)
|
||||
var grainHeight = (grain / columnMax).toFloat()
|
||||
if (grainHeight == 0F) {
|
||||
include.divTotalFoodView.visibility = View.VISIBLE
|
||||
include.divTotalFoodView.visible()
|
||||
} else {
|
||||
include.divTotalFoodView.visibility = View.GONE
|
||||
include.divTotalFoodView.gone()
|
||||
grainHeight += 0.1F
|
||||
}
|
||||
include.customFoodColumn.setCustomHeightPercent(grainHeight, true)
|
||||
@@ -616,15 +637,16 @@ class MainScreenPresentation(
|
||||
mid = userNutrition?.fruitsVegetablesNearExcess,
|
||||
right = userNutrition?.fruitsVegetablesExcess
|
||||
)
|
||||
val fruitsIndex = UserNutritionUtils.findCalorieIndex(energy.fruitsVegetables, fruitsArray)
|
||||
val fruitsIndex =
|
||||
UserNutritionUtils.findCalorieIndex(energy.fruitsVegetables, fruitsArray)
|
||||
include.customVegetableColumn.setImageDrawable(false, fruitsIndex)
|
||||
include.totalVegetableTv.text = fruitsVegetables.format2String(2)
|
||||
var fruitsHeight = (fruitsVegetables / columnMax).toFloat()
|
||||
|
||||
if (fruitsHeight == 0F) {
|
||||
include.divVegetableView.visibility = View.VISIBLE
|
||||
include.divVegetableView.visible()
|
||||
} else {
|
||||
include.divVegetableView.visibility = View.GONE
|
||||
include.divVegetableView.gone()
|
||||
fruitsHeight += 0.1F
|
||||
}
|
||||
include.customVegetableColumn.setCustomHeightPercent(fruitsHeight, true)
|
||||
@@ -635,14 +657,15 @@ class MainScreenPresentation(
|
||||
mid = userNutrition?.meatEggsNearExcess,
|
||||
right = userNutrition?.meatEggsExcess
|
||||
)
|
||||
val meatEggsIndex = UserNutritionUtils.findCalorieIndex(energy.meatEggs, meatEggsArray)
|
||||
val meatEggsIndex =
|
||||
UserNutritionUtils.findCalorieIndex(energy.meatEggs, meatEggsArray)
|
||||
include.customMeatColumn.setImageDrawable(false, meatEggsIndex)
|
||||
include.totalMeatTv.text = meatEggs.format2String(2)
|
||||
var meatHeight = (meatEggs / columnMax).toFloat()
|
||||
if (meatHeight == 0F) {
|
||||
include.divMeatView.visibility = View.VISIBLE
|
||||
include.divMeatView.visible()
|
||||
} else {
|
||||
include.divMeatView.visibility = View.GONE
|
||||
include.divMeatView.gone()
|
||||
meatHeight += 0.1F
|
||||
}
|
||||
include.customMeatColumn.setCustomHeightPercent(meatHeight, true)
|
||||
@@ -738,6 +761,9 @@ class MainScreenPresentation(
|
||||
recognizeViewModel.recognizeUserId.observe(
|
||||
activity,
|
||||
Observer { compareResult: CompareResult ->
|
||||
activity.runOnUiThread {
|
||||
activity.showWaitingDialog("加载中,请稍后……")
|
||||
}
|
||||
Timber.tag(TAG)
|
||||
.i("recognizeUserId observe compareResult = ${compareResult.trackId}, userId = ${compareResult.faceEntity.userName}")
|
||||
recognitionTime = System.currentTimeMillis()
|
||||
@@ -745,6 +771,16 @@ class MainScreenPresentation(
|
||||
lastFaceTrackId = compareResult.trackId
|
||||
val faceEntity = compareResult.faceEntity
|
||||
val userId = faceEntity.userName
|
||||
currentUserId = userId
|
||||
// if (TextUtils.equals(userId, "2")) {
|
||||
// //解决识别出现recognizeStatus = 2待重试的问题
|
||||
// activity.runOnUiThread {
|
||||
// ToastUtils.showToast("一开始就在屏幕内发现无法识别,从屏幕外进入就可以识别")
|
||||
// activity.hideWaitingDialog()
|
||||
// }
|
||||
// //userViewModel.getUserFaceCache()
|
||||
// return@Observer
|
||||
// }
|
||||
if (userId == null) return@Observer
|
||||
//ToastUtils.showToast("人脸识别成功,userId = $userId")
|
||||
if (currentFood == null) {
|
||||
@@ -752,6 +788,7 @@ class MainScreenPresentation(
|
||||
}
|
||||
if (currentFood == null) {
|
||||
activity.runOnUiThread {
|
||||
activity.hideWaitingDialog()
|
||||
ToastUtils.showToast("请选择菜品")
|
||||
return@runOnUiThread
|
||||
}
|
||||
@@ -761,12 +798,21 @@ class MainScreenPresentation(
|
||||
userViewModel.getUserNutritionData(userId = userId) { nutrition ->
|
||||
activity.runOnUiThread {
|
||||
if (nutrition == null) {
|
||||
activity.hideWaitingDialog()
|
||||
ToastUtils.showToast("未查询到营养数据")
|
||||
return@runOnUiThread
|
||||
}
|
||||
this@MainScreenPresentation.userNutrition = nutrition
|
||||
loadUnbilledMode()
|
||||
// -------------------------------
|
||||
|
||||
val imageUrl =
|
||||
if (currentFood!!.foodImg.isNullOrBlank()) currentFood!!.photoUri else currentFood!!.foodImg
|
||||
binding.ivRecImage.let {
|
||||
it.visible()
|
||||
it.load(imageUrl)
|
||||
}
|
||||
activity.updateImage(imageUrl)
|
||||
activity.hideWaitingDialog()
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -816,7 +862,7 @@ class MainScreenPresentation(
|
||||
// layoutParams.width = (measuredHeight * ratio).toInt()
|
||||
// }
|
||||
// if (scale < 1f) {
|
||||
// val rgbParam = rgbPreview.getLayoutParams()
|
||||
// val rgbParam = rgbPreview.layoutParams
|
||||
// layoutParams.width = (rgbParam.width * scale).toInt()
|
||||
// layoutParams.height = (rgbParam.height * scale).toInt()
|
||||
// } else {
|
||||
@@ -838,16 +884,23 @@ class MainScreenPresentation(
|
||||
// layoutParams.height = (layoutParams.height / viewRatio).toInt()
|
||||
// }
|
||||
|
||||
// Timber.tag(TAG).d("initRgbCamera:metrics(${metrics.widthPixels},${metrics.heightPixels})")
|
||||
|
||||
val layoutParams = previewView.layoutParams
|
||||
// layoutParams.width = (608.dp * 1.5).roundToInt()
|
||||
// layoutParams.height = (456.dp * 1.5).roundToInt()
|
||||
// layoutParams.width = (600.dp * 1.5).roundToInt()
|
||||
// layoutParams.height = (450.dp * 1.5).roundToInt()
|
||||
layoutParams.width = 1024
|
||||
layoutParams.height = 768
|
||||
|
||||
//val layoutParams = previewView.layoutParams
|
||||
//layoutParams.width = 1024
|
||||
//layoutParams.height = 768
|
||||
// val w = 600.dp //(912.dp * scale).toInt()
|
||||
// val h = 900.dp //684.dp
|
||||
val w = 500.dp
|
||||
val h = 850.dp
|
||||
//(1024*scale).toInt()
|
||||
val layoutParams = FrameLayout.LayoutParams(w, h);
|
||||
// val layoutParams = FrameLayout.LayoutParams(480, 320);
|
||||
// val layoutParams = FrameLayout.LayoutParams(912.dp, 684.dp);
|
||||
previewView.setLayoutParams(layoutParams)
|
||||
faceRectView.setLayoutParams(layoutParams)
|
||||
|
||||
return layoutParams
|
||||
}
|
||||
|
||||
@@ -865,8 +918,11 @@ class MainScreenPresentation(
|
||||
val previewSizeRgb = camera.getParameters().getPreviewSize()
|
||||
val layoutParams = adjustPreviewViewSize(
|
||||
binding.dualCameraTexturePreviewRgb,
|
||||
binding.dualCameraTexturePreviewRgb, binding.dualCameraFaceRectView,
|
||||
previewSizeRgb, displayOrientation, 0.6F
|
||||
binding.dualCameraTexturePreviewRgb,
|
||||
binding.dualCameraFaceRectView,
|
||||
previewSizeRgb, displayOrientation,
|
||||
0.5F
|
||||
//0.6F
|
||||
)
|
||||
|
||||
Timber.tag(TAG)
|
||||
@@ -886,10 +942,8 @@ class MainScreenPresentation(
|
||||
)
|
||||
// 调整识别窗口位置
|
||||
rgbFaceRectTransformer = FaceRectTransformer(
|
||||
// previewSizeRgb.width,
|
||||
// previewSizeRgb.height,
|
||||
layoutParams.width,
|
||||
layoutParams.height,
|
||||
previewSizeRgb.width,
|
||||
previewSizeRgb.height,
|
||||
layoutParams.width,
|
||||
layoutParams.height,
|
||||
90,
|
||||
@@ -945,9 +999,12 @@ class MainScreenPresentation(
|
||||
val previewConfig: PreviewConfig = recognizeViewModel.previewConfig
|
||||
rgbCameraHelper = DualCameraHelper.Builder()
|
||||
.previewViewSize(Point(measuredWidth, measuredHeight))
|
||||
// .previewViewSize(Point(608.dp, 456.dp))
|
||||
// .previewViewSize(Point(1024, 768))
|
||||
.rotation(activity.windowManager.defaultDisplay.rotation)
|
||||
.additionalRotation(previewConfig.rgbAdditionalDisplayOrientation) // 角度
|
||||
.previewSize(recognizeViewModel.loadPreviewSize())
|
||||
// .previewSize(Point(1080, 720))
|
||||
.specificCameraId(previewConfig.rgbCameraId)
|
||||
.isMirror(true)
|
||||
.previewOn(binding.dualCameraTexturePreviewRgb)
|
||||
@@ -982,9 +1039,10 @@ class MainScreenPresentation(
|
||||
)
|
||||
|
||||
irFaceRectTransformer = FaceRectTransformer(
|
||||
// previewSizeIr.width, previewSizeIr.height,
|
||||
previewSizeIr.width, previewSizeIr.height,
|
||||
// layoutParams.width, layoutParams.height,
|
||||
layoutParams.width, layoutParams.height,
|
||||
layoutParams.width, layoutParams.height, displayOrientation, cameraId, isMirror,
|
||||
displayOrientation, cameraId, isMirror,
|
||||
ConfigUtil.isDrawIrRectHorizontalMirror(context),
|
||||
ConfigUtil.isDrawIrRectVerticalMirror(context)
|
||||
)
|
||||
@@ -1027,6 +1085,7 @@ class MainScreenPresentation(
|
||||
binding.dualCameraTexturePreviewIr.measuredHeight
|
||||
)
|
||||
)
|
||||
// .previewViewSize(Point(133,100))
|
||||
.rotation(activity.windowManager.defaultDisplay.rotation)
|
||||
.specificCameraId(previewConfig.irCameraId)
|
||||
.previewOn(binding.dualCameraTexturePreviewIr)
|
||||
@@ -1064,16 +1123,17 @@ class MainScreenPresentation(
|
||||
Timber.tag(TAG)
|
||||
.d("listIsEmpty=$listIsEmpty,lastFaceTrackId=$lastFaceTrackId,listFirstTrackId=$listFirstTrackId")
|
||||
if (listIsEmpty || (lastFaceTrackId != listFirstTrackId)) {
|
||||
if (lastFaceTrackId != -1) {
|
||||
if (lastFaceTrackId != -1 && currentUserId!=null) {
|
||||
mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
Timber.tag(TAG).i("$lastFaceTrackId 用户离开")
|
||||
lastFaceTrackId = -1
|
||||
postUserData()
|
||||
if (mealPickupMode == 0) {
|
||||
if (mealPickupMode == 1 || isKeepFaceState) {
|
||||
step2FaceRecognizing(currentFood!!)
|
||||
isKeepFaceState = false
|
||||
} else {
|
||||
activity.isAnalyzing = false
|
||||
step1FoodRecognizing()
|
||||
} else {
|
||||
step2FaceRecognizing(currentFood!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1115,7 +1175,40 @@ class MainScreenPresentation(
|
||||
if (MyApp.DEBUG) {
|
||||
ToastUtils.showToast("订单已生成")
|
||||
}
|
||||
currentUserId = null
|
||||
}
|
||||
}
|
||||
|
||||
fun hideNutritionView(chargeMode: Int) {
|
||||
binding.nutritionInclude.root.gone()
|
||||
binding.calorieInclude.root.gone()
|
||||
binding.tvFoodRecPrompt.visible()
|
||||
|
||||
binding.ivRecImage.gone()
|
||||
binding.llPriceInfo.gone()
|
||||
binding.ivPreviewImage.visible()
|
||||
binding.ivFrame.visible()
|
||||
|
||||
// if (chargeMode == 1) {
|
||||
// //不计费
|
||||
//// binding.flFace.visible()
|
||||
// binding.ivRecImage.gone()
|
||||
// binding.llPriceInfo.gone()
|
||||
// binding.ivPreviewImage.gone()
|
||||
// binding.ivFrame.gone()
|
||||
// } else {
|
||||
// //计费
|
||||
// binding.flFace.gone()
|
||||
// binding.llPriceInfo.gone()
|
||||
//// val imageUrl = if (currentFood!!.foodImg.isNullOrBlank()) currentFood!!.photoUri else currentFood!!.foodImg
|
||||
//// binding.ivRecImage.let {
|
||||
//// it.visible()
|
||||
//// it.load(imageUrl)
|
||||
//// }
|
||||
// binding.ivRecImage.gone()
|
||||
// binding.ivPreviewImage.visible()
|
||||
// binding.ivFrame.visible()
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,10 +28,10 @@ object UserNutritionUtils {
|
||||
var (calorie, grain, fruitsVegetables, meatEggs) = List(4) { 0.0 }
|
||||
|
||||
// 处理食物信息
|
||||
calorie = calculateValue(foodInfo.calorie, weight)
|
||||
grain = calculateValue(foodInfo.stapleFood, weight)
|
||||
fruitsVegetables = calculateValue(foodInfo.fruitsVegetables, weight)
|
||||
meatEggs = calculateValue(foodInfo.meatEggs, weight)
|
||||
calorie = foodInfo.calorie ?: 0.0 //calculateValue(foodInfo.calorie, weight)
|
||||
grain = foodInfo.stapleFood ?: 0.0 //calculateValue(foodInfo.stapleFood, weight)
|
||||
fruitsVegetables = foodInfo.fruitsVegetables ?: 0.0 //calculateValue(foodInfo.fruitsVegetables, weight)
|
||||
meatEggs = foodInfo.meatEggs ?: 0.0 //calculateValue(foodInfo.meatEggs, weight)
|
||||
|
||||
// 合并用户数据
|
||||
//val maxKcal = (nutrition.calorie?:0.0) * calculateDinnerTypeRatio(dinnerType) / 10.0
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.view.Display
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewTreeObserver
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.ContextCompat
|
||||
@@ -23,6 +24,7 @@ import com.sw.dualscreen.GlobalKey
|
||||
import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.activity.PayActivity
|
||||
import com.sw.dualscreen.databinding.PresentationFacePayBinding
|
||||
import com.sw.dualscreen.ext.dp
|
||||
import com.sw.dualscreen.model.response.MemberInfo
|
||||
import com.sw.dualscreen.model.response.TextBean
|
||||
import com.sw.dualscreen.utils.SPUtil
|
||||
@@ -316,13 +318,17 @@ class FacePayPresentation(
|
||||
// }
|
||||
|
||||
|
||||
val layoutParams = previewView.layoutParams
|
||||
// val layoutParams = previewView.layoutParams
|
||||
// layoutParams.width = (608.dp * 1.5).roundToInt()
|
||||
// layoutParams.height = (456.dp * 1.5).roundToInt()
|
||||
// layoutParams.width = (608.dp * 1.5).roundToInt()
|
||||
// layoutParams.height = (456.dp * 1.5).roundToInt()
|
||||
layoutParams.width = 1024
|
||||
layoutParams.height = 768
|
||||
// layoutParams.width = 1024
|
||||
// layoutParams.height = 768
|
||||
val w = 500.dp
|
||||
val h = 850.dp
|
||||
val layoutParams = FrameLayout.LayoutParams(w, h);
|
||||
|
||||
previewView.setLayoutParams(layoutParams)
|
||||
faceRectView.setLayoutParams(layoutParams)
|
||||
return layoutParams
|
||||
@@ -363,10 +369,10 @@ class FacePayPresentation(
|
||||
)
|
||||
// 调整识别窗口位置
|
||||
rgbFaceRectTransformer = FaceRectTransformer(
|
||||
// previewSizeRgb.width,
|
||||
// previewSizeRgb.height,
|
||||
layoutParams.width,
|
||||
layoutParams.height,
|
||||
previewSizeRgb.width,
|
||||
previewSizeRgb.height,
|
||||
// layoutParams.width,
|
||||
// layoutParams.height,
|
||||
layoutParams.width,
|
||||
layoutParams.height,
|
||||
90,
|
||||
|
||||
@@ -140,7 +140,10 @@ class ScanQrCodePayPresentation(
|
||||
}
|
||||
|
||||
private fun loadUserInfo(item: MemberInfo) {
|
||||
binding.ivHeadPic.load(item.faceUrl?.ifBlank { R.drawable.ic_avatar_default })
|
||||
binding.ivHeadPic.load(
|
||||
if(item.faceUrl.isNullOrBlank()) R.drawable.ic_avatar_default
|
||||
else item.faceUrl
|
||||
)
|
||||
binding.tvUserName.text = item.name
|
||||
|
||||
val phone = item.phone ?: ""
|
||||
|
||||
@@ -85,7 +85,9 @@ object SensorScaleUtils {
|
||||
// 打开后需要等待后才能调用,否则会 1001 SDK未初始化
|
||||
mSensorScale?.startContinuousRead()
|
||||
// Thread.sleep(1000)
|
||||
zero()
|
||||
|
||||
// TODO: 暂时不标定---------
|
||||
//zero()
|
||||
|
||||
}.start()
|
||||
}
|
||||
|
||||
@@ -122,30 +122,30 @@ class UserViewModel : BaseViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getUserFaceCache2(index: Int = 0) {
|
||||
Timber.d("getUserFaceCache index = $index")
|
||||
launch {
|
||||
_loadFaceResult.value = false
|
||||
val response = repository.getUserFaceCache2(index)
|
||||
if (parseResponse(response)) {
|
||||
// 获取成功一次后缓存状态
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
||||
withContext(Dispatchers.Default) {
|
||||
val list: List<UserFaceModel2> = response.result?.records ?: emptyList()
|
||||
val faceEntity = list.map {
|
||||
FaceEntity(it.userId, null, Base64.decode(it.face))
|
||||
}
|
||||
faceApi.updateFaceData2(index, faceEntity)
|
||||
}
|
||||
val nextPageIndex = response.result?.nextPageIndex ?: -1
|
||||
if (nextPageIndex > 0) {
|
||||
getUserFaceCache2(nextPageIndex)
|
||||
} else {
|
||||
_loadFaceResult.value = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// fun getUserFaceCache2(index: Int = 0) {
|
||||
// Timber.d("getUserFaceCache index = $index")
|
||||
// launch {
|
||||
// _loadFaceResult.value = false
|
||||
// val response = repository.getUserFaceCache2(index)
|
||||
// if (parseResponse(response)) {
|
||||
// // 获取成功一次后缓存状态
|
||||
// SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
||||
// withContext(Dispatchers.Default) {
|
||||
// val list: List<UserFaceModel2> = response.result?.records ?: emptyList()
|
||||
// val faceEntity = list.map {
|
||||
// FaceEntity(it.userId, null, Base64.decode(it.face))
|
||||
// }
|
||||
// faceApi.updateFaceData2(index, faceEntity)
|
||||
// }
|
||||
// val nextPageIndex = response.result?.nextPageIndex ?: -1
|
||||
// if (nextPageIndex > 0) {
|
||||
// getUserFaceCache2(nextPageIndex)
|
||||
// } else {
|
||||
// _loadFaceResult.value = true
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
fun getCollectedFoodList(
|
||||
pageNo: Int = 1,
|
||||
|
||||
@@ -204,7 +204,8 @@
|
||||
android:background="@drawable/bg_gray"
|
||||
android:text="返回"
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold" />
|
||||
android:textStyle="bold"
|
||||
android:textAllCaps="false" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
android:textColor="#FF5E7585"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="33dp"
|
||||
android:layout_marginTop="28dp"
|
||||
android:layout_marginStart="41dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
@@ -38,7 +38,7 @@
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="33dp"
|
||||
android:layout_marginTop="28dp"
|
||||
android:layout_marginHorizontal="28dp"
|
||||
android:background="#FF5E7585"
|
||||
app:layout_constraintTop_toBottomOf="@id/tv_user_name" />
|
||||
|
||||
@@ -64,10 +64,12 @@
|
||||
android:textStyle="bold"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<!-- android:layout_width="300dp"-->
|
||||
<!-- android:layout_height="510dp"-->
|
||||
<FrameLayout
|
||||
android:id="@+id/flFace"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="456dp"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="510dp"
|
||||
android:layout_marginHorizontal="28dp"
|
||||
android:layout_marginTop="56dp">
|
||||
|
||||
|
||||
@@ -24,23 +24,29 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginVertical="50dp"
|
||||
android:layout_marginVertical="30dp"
|
||||
android:text="餐品识别中..."
|
||||
android:textColor="#ff0a1428"
|
||||
android:textSize="40sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<!-- android:layout_width="300dp"-->
|
||||
<!-- android:layout_height="450dp"-->
|
||||
<!-- android:layout_width="330dp"-->
|
||||
<!-- android:layout_height="495dp"-->
|
||||
<FrameLayout
|
||||
android:id="@+id/flCameraView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="456dp"
|
||||
android:layout_height="510dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginHorizontal="28dp"
|
||||
android:visibility="visible">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/flFace"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="510dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:visibility="gone">
|
||||
<TextureView
|
||||
android:id="@+id/dual_camera_texture_preview_rgb"
|
||||
@@ -73,26 +79,34 @@
|
||||
android:textSize="24sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="28dp"
|
||||
android:background="@drawable/ic_camera_rect" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<!-- android:layout_height="456dp"-->
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/ivPreviewImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="456dp"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
app:shapeAppearance="@style/round10dpCornerStyle"
|
||||
tools:background="@mipmap/ic_launcher"/>
|
||||
tools:src="@mipmap/ic_launcher"/>
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/ivRecImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="456dp"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
tools:background="@mipmap/ic_launcher_round"
|
||||
tools:src="@mipmap/ic_launcher_round"
|
||||
app:shapeAppearance="@style/round10dpCornerStyle"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivFrame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="28dp"
|
||||
@@ -164,7 +178,6 @@
|
||||
android:textColor="#ffff3232"
|
||||
android:textSize="80sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="42dp"
|
||||
android:background="@drawable/setting_border" />
|
||||
|
||||
<include
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<resources>
|
||||
<!-- Base application theme. -->
|
||||
<style name="Base.Theme.DualScreen" parent="Theme.Material3.DayNight.NoActionBar">
|
||||
<!-- <style name="Base.Theme.DualScreen" parent="Theme.Material3.DayNight.NoActionBar">-->
|
||||
<style name="Base.Theme.DualScreen" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<!-- Customize your light theme here. -->
|
||||
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
|
||||
</style>
|
||||
|
||||
@@ -88,8 +88,10 @@ public class ConfigUtil {
|
||||
* 默认相机分辨率
|
||||
*/
|
||||
// private static final String DEFAULT_PREVIEW_SIZE = "1280x720";
|
||||
// private static final String DEFAULT_PREVIEW_SIZE = "1080x720";
|
||||
private static final String DEFAULT_PREVIEW_SIZE = "720x1080";
|
||||
// private static final String DEFAULT_PREVIEW_SIZE = "608x456";
|
||||
private static final String DEFAULT_PREVIEW_SIZE = "1024x768";
|
||||
// private static final String DEFAULT_PREVIEW_SIZE = "1024x768";
|
||||
// private static final String DEFAULT_PREVIEW_SIZE = "800x600";
|
||||
// private static final String DEFAULT_PREVIEW_SIZE = "640x480";
|
||||
|
||||
|
||||
@@ -36,7 +36,10 @@ public class FaceApi {
|
||||
faceDao.deleteAll();
|
||||
faceDao.resetId();
|
||||
}
|
||||
faceDao.insert(list);
|
||||
List<Long> insertIdList = faceDao.insert(list);
|
||||
Log.d(TAG, "updateFaceData: count = " + insertIdList.size());
|
||||
List<FaceEntity> queryList = faceDao.getAllFaces();
|
||||
Log.d(TAG, "updateFaceData: queryList.size = " + queryList.size());
|
||||
}
|
||||
|
||||
public void updateFaceData2(int index, List<FaceEntity> list) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.sw.plate.utils.arcface;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Rect;
|
||||
@@ -215,6 +216,7 @@ public class FaceRectView extends View {
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setStrokeWidth(faceRectThickness);
|
||||
paint.setColor(drawInfo.getColor());
|
||||
// paint.setColor(Color.parseColor("#FF0000"));
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
Path mPath = new Path();
|
||||
|
||||
@@ -73,7 +73,7 @@ public interface FaceDao {
|
||||
Long insert(FaceEntity faceEntity);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
void insert(List<FaceEntity> items);
|
||||
List<Long> insert(List<FaceEntity> items);
|
||||
|
||||
/**
|
||||
* 获取已注册的人脸数
|
||||
|
||||
@@ -586,9 +586,14 @@ public class RecognizeViewModel extends ViewModel implements RecognizeCallback {
|
||||
if (recognizeStatus != null) {
|
||||
if (recognizeStatus == RequestFeatureStatus.FAILED) {
|
||||
color = RecognizeColor.COLOR_FAILED;
|
||||
}
|
||||
if (recognizeStatus == RequestFeatureStatus.SUCCEED) {
|
||||
}else if (recognizeStatus == RequestFeatureStatus.SUCCEED) {
|
||||
color = RecognizeColor.COLOR_SUCCESS;
|
||||
} else if (recognizeStatus == RequestFeatureStatus.TO_RETRY) {
|
||||
color = RecognizeColor.COLOR_UNKNOWN;
|
||||
//需要重试
|
||||
// FaceEntity faceEntity = new FaceEntity("2",null, null);
|
||||
// CompareResult result = new CompareResult(faceEntity, 0.0f);
|
||||
// recognizeUserId.postValue(result);
|
||||
}
|
||||
}
|
||||
if (liveness != null && liveness == LivenessInfo.NOT_ALIVE) {
|
||||
|
||||
Reference in New Issue
Block a user