fix(activity): 修复拿走物品后识别弹窗未自动关闭的问题

- 将关闭阈值从 weight < 10 调整为 weight < 20,覆盖轻微零点漂移
- 将 size == 1 判断改为 none { isShowing && it != goodsRecognizeDialog },避免 DialogManager 中存在幽灵条目时导致关闭逻辑失效
- GoodsStoreDialog:无论 funcType 值,均拍照上传图片以增加样本数据
- BaseViewModel:recognizeGoodsList 增加异常捕获,异常时回调空列表
This commit is contained in:
2026-05-09 15:44:05 +08:00
parent 7c5278bc88
commit 79f58a36e3
3 changed files with 58 additions and 45 deletions
@@ -210,13 +210,13 @@ abstract class GoodsListActivity : BaseActivity() {
binding.tvTotalWeight.text = "重量:${weight}" binding.tvTotalWeight.text = "重量:${weight}"
} }
if (weight < 200) { if (weight < 200) {
if (weight < 10) { if (weight < 20) {
// val clazzName = DialogManager.getDialogList() // val clazzName = DialogManager.getDialogList()
// .map { it.javaClass.simpleName } // .map { it.javaClass.simpleName }
// .joinToString(",") // .joinToString(",")
// Timber.tag(TAG).d(clazzName) // Timber.tag(TAG).d(clazzName)
if (DialogManager.getDialogList().size == 1 && // 无其他弹窗正在显示时(过滤幽灵条目),自动关闭识别弹窗
DialogManager.contains("GoodsRecognizeDialog") && if (DialogManager.getDialogList().none { it.isShowing && it != goodsRecognizeDialog } &&
goodsRecognizeDialog?.isShowing == true goodsRecognizeDialog?.isShowing == true
) { ) {
goodsRecognizeDialog?.dismiss() goodsRecognizeDialog?.dismiss()
@@ -253,8 +253,9 @@ abstract class GoodsListActivity : BaseActivity() {
searchFood(uri) searchFood(uri)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
Loading.dismiss()
} }
}.start() }
} }
private val delayHandler by lazy { private val delayHandler by lazy {
@@ -395,19 +396,22 @@ abstract class GoodsListActivity : BaseActivity() {
// readBitmap(it) // readBitmap(it)
// } // }
// } // }
ImageUtil.uriToBitmap(this, uri)?.let { bitmap -> val bitmap = ImageUtil.uriToBitmap(this, uri)
val newBmp = BitmapCropper.cropCenter( if (bitmap == null) {
original = bitmap, Loading.dismiss()
targetWidth = 1000, targetHeight = 1300, return
offsetX = 30, offsetY = 100 }
) val newBmp = BitmapCropper.cropCenter(
readBitmap(newBmp) original = bitmap,
if (newBmp.isRecycled.not()) { targetWidth = 1000, targetHeight = 1300,
newBmp.recycle() offsetX = 30, offsetY = 100
} )
if (bitmap.isRecycled.not()) { readBitmap(newBmp)
bitmap.recycle() if (newBmp.isRecycled.not()) {
} newBmp.recycle()
}
if (bitmap.isRecycled.not()) {
bitmap.recycle()
} }
} }
@@ -357,27 +357,28 @@ class GoodsStoreDialog(
context.toast("入库金额不能为0") context.toast("入库金额不能为0")
return return
} }
if (funcType == 1) { // if (funcType == 1) {
activity?.let { Loading.show(it) } //无论是否识别到物品,都上传图片增加样本数据
cameraUtils.takePhoto { uri -> activity?.let { Loading.show(it) }
//imageUri = uri cameraUtils.takePhoto { uri ->
collectGoodsVector(uri) { //imageUri = uri
activity?.uploadImage(goods.id!!, goods.goodsName!!, imageFile) collectGoodsVector(uri) {
} activity?.uploadImage(goods.id!!, goods.goodsName!!, imageFile)
binding.root.postDelayed({
Loading.dismiss()
confirm(unitName, count, price, totalPrice)
}, 500)
} }
cameraUtils.addFailCallback { binding.root.postDelayed({
binding.root.postDelayed({ Loading.dismiss()
Loading.dismiss() confirm(unitName, count, price, totalPrice)
confirm(unitName, count, price, totalPrice) }, 500)
}, 500)
}
} else {
confirm(unitName, count, price, totalPrice)
} }
cameraUtils.addFailCallback {
binding.root.postDelayed({
Loading.dismiss()
confirm(unitName, count, price, totalPrice)
}, 500)
}
// } else {
// confirm(unitName, count, price, totalPrice)
// }
} }
private fun confirm(unitName: String, count: Double, price: Double, totalPrice: Double?) { private fun confirm(unitName: String, count: Double, price: Double, totalPrice: Double?) {
@@ -212,17 +212,25 @@ abstract class BaseViewModel(
callback: (List<SearchGoodsInfo.Record>) -> Unit callback: (List<SearchGoodsInfo.Record>) -> Unit
) { ) {
launch { launch {
if (nameList.isNullOrEmpty() && scoreList.isNullOrEmpty()) return@launch try {
val paramList = if (nameList.isNullOrEmpty()) scoreList!!.map { it.name } else nameList if (nameList.isNullOrEmpty() && scoreList.isNullOrEmpty()) {
val response = repository.recognizeGoodsList(paramList) callback(listOf())
val list = if (parseResponse(response)) response.data ?: listOf() else listOf() return@launch
if (scoreList.isNullOrEmpty().not()) {
list.forEach { record ->
val item = scoreList.firstOrNull { it.name == record.goodsName }
record.score = ((1 - (item?.score ?: 0.0)) * 10000).roundToInt()
} }
val paramList = if (nameList.isNullOrEmpty()) scoreList!!.map { it.name } else nameList
val response = repository.recognizeGoodsList(paramList)
val list = if (parseResponse(response)) response.data ?: listOf() else listOf()
if (scoreList.isNullOrEmpty().not()) {
list.forEach { record ->
val item = scoreList.firstOrNull { it.name == record.goodsName }
record.score = ((1 - (item?.score ?: 0.0)) * 10000).roundToInt()
}
}
callback(list)
} catch (e: Exception) {
Timber.e(e)
callback(listOf())
} }
callback(list)
} }
} }