feat(common): 添加View点击区域扩展功能并优化主界面重量检测逻辑
- 在CommonExt.kt中新增expandClickArea扩展函数,支持扩大View的点击响应区域 - 新增TouchDelegate导入用于实现点击区域扩展功能 - 调整MainActivity.kt中的重量检测逻辑顺序,先处理联合支付模式下的特殊情况 - 添加对当前用户ID的检查,优化即放即取模式下的重量数据处理流程 - 重构重量重置识别条件的位置,确保正确的执行顺序
This commit is contained in:
@@ -365,11 +365,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
it.text = "$weight"
|
||||
}
|
||||
}
|
||||
if (weight <= WEIGHT_RESET_RECOGNIZE) {
|
||||
log("registerDataChange weight 秤重量小于${WEIGHT_RESET_RECOGNIZE}g")
|
||||
//检测到秤上没有东西,重新启动识别菜品 && presentation?.mealPickupMode == 1
|
||||
checkedItem = null
|
||||
}
|
||||
if (settlementMode == 0) {
|
||||
log("registerDataChange weight 联合支付模式")
|
||||
//联合支付-------------------------------------------
|
||||
@@ -379,10 +374,19 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
loadYLJLBySettlement(weight)
|
||||
return
|
||||
}
|
||||
if (presentation?.currentUserId.isNullOrBlank().not()) {
|
||||
//联合支付+即放即取,已识别人脸的状态下,从秤上拿餐品后,不再读取数据,等待人脸离开提交订单
|
||||
return
|
||||
}
|
||||
loadJFJQBySettlement(weight)
|
||||
return
|
||||
}
|
||||
|
||||
if (weight <= WEIGHT_RESET_RECOGNIZE) {
|
||||
log("registerDataChange weight 秤重量小于${WEIGHT_RESET_RECOGNIZE}g")
|
||||
//检测到秤上没有东西
|
||||
checkedItem = null
|
||||
}
|
||||
//独立支付-------------------------------------------
|
||||
if (lastWeight - weight > 5) {
|
||||
//及放及取,从秤上拿走超过5克
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.graphics.Rect
|
||||
import android.graphics.YuvImage
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.TypedValue
|
||||
import android.view.TouchDelegate
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.view.inputmethod.EditorInfo
|
||||
@@ -172,3 +173,24 @@ val Context.screenSize: IntArray
|
||||
displayMetrics.heightPixels
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩大 View 的点击区域
|
||||
* @param horizontal 水平方向扩大距离(dp)→ 左右各扩大一半
|
||||
* @param vertical 垂直方向扩大距离(dp)→ 上下各扩大一半
|
||||
*/
|
||||
fun View.expandClickArea(horizontal: Int, vertical: Int) {
|
||||
val density = resources.displayMetrics.density
|
||||
val hPx = (horizontal * density).toInt()
|
||||
val vPx = (vertical * density).toInt()
|
||||
|
||||
post {
|
||||
val rect = android.graphics.Rect()
|
||||
getHitRect(rect)
|
||||
|
||||
// 扩大区域:负值 = 向外扩大
|
||||
rect.inset(-hPx, -vPx)
|
||||
//rect.bottom += downPx // 只往下扩大
|
||||
(parent as View).touchDelegate = TouchDelegate(rect, this)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user