fix(activity): 修复拿走物品后识别弹窗未自动关闭的问题
- 将关闭阈值从 weight < 10 调整为 weight < 20,覆盖轻微零点漂移
- 将 size == 1 判断改为 none { isShowing && it != goodsRecognizeDialog },避免 DialogManager 中存在幽灵条目时导致关闭逻辑失效
- GoodsStoreDialog:无论 funcType 值,均拍照上传图片以增加样本数据
- BaseViewModel:recognizeGoodsList 增加异常捕获,异常时回调空列表
This commit is contained in:
@@ -210,13 +210,13 @@ abstract class GoodsListActivity : BaseActivity() {
|
||||
binding.tvTotalWeight.text = "重量:${weight}克"
|
||||
}
|
||||
if (weight < 200) {
|
||||
if (weight < 10) {
|
||||
if (weight < 20) {
|
||||
// val clazzName = DialogManager.getDialogList()
|
||||
// .map { it.javaClass.simpleName }
|
||||
// .joinToString(",")
|
||||
// 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?.dismiss()
|
||||
@@ -253,8 +253,9 @@ abstract class GoodsListActivity : BaseActivity() {
|
||||
searchFood(uri)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Loading.dismiss()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
private val delayHandler by lazy {
|
||||
@@ -395,19 +396,22 @@ abstract class GoodsListActivity : BaseActivity() {
|
||||
// readBitmap(it)
|
||||
// }
|
||||
// }
|
||||
ImageUtil.uriToBitmap(this, uri)?.let { bitmap ->
|
||||
val newBmp = BitmapCropper.cropCenter(
|
||||
original = bitmap,
|
||||
targetWidth = 1000, targetHeight = 1300,
|
||||
offsetX = 30, offsetY = 100
|
||||
)
|
||||
readBitmap(newBmp)
|
||||
if (newBmp.isRecycled.not()) {
|
||||
newBmp.recycle()
|
||||
}
|
||||
if (bitmap.isRecycled.not()) {
|
||||
bitmap.recycle()
|
||||
}
|
||||
val bitmap = ImageUtil.uriToBitmap(this, uri)
|
||||
if (bitmap == null) {
|
||||
Loading.dismiss()
|
||||
return
|
||||
}
|
||||
val newBmp = BitmapCropper.cropCenter(
|
||||
original = bitmap,
|
||||
targetWidth = 1000, targetHeight = 1300,
|
||||
offsetX = 30, offsetY = 100
|
||||
)
|
||||
readBitmap(newBmp)
|
||||
if (newBmp.isRecycled.not()) {
|
||||
newBmp.recycle()
|
||||
}
|
||||
if (bitmap.isRecycled.not()) {
|
||||
bitmap.recycle()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -357,27 +357,28 @@ class GoodsStoreDialog(
|
||||
context.toast("入库金额不能为0")
|
||||
return
|
||||
}
|
||||
if (funcType == 1) {
|
||||
activity?.let { Loading.show(it) }
|
||||
cameraUtils.takePhoto { uri ->
|
||||
//imageUri = uri
|
||||
collectGoodsVector(uri) {
|
||||
activity?.uploadImage(goods.id!!, goods.goodsName!!, imageFile)
|
||||
}
|
||||
binding.root.postDelayed({
|
||||
Loading.dismiss()
|
||||
confirm(unitName, count, price, totalPrice)
|
||||
}, 500)
|
||||
// if (funcType == 1) {
|
||||
//无论是否识别到物品,都上传图片增加样本数据
|
||||
activity?.let { Loading.show(it) }
|
||||
cameraUtils.takePhoto { uri ->
|
||||
//imageUri = uri
|
||||
collectGoodsVector(uri) {
|
||||
activity?.uploadImage(goods.id!!, goods.goodsName!!, imageFile)
|
||||
}
|
||||
cameraUtils.addFailCallback {
|
||||
binding.root.postDelayed({
|
||||
Loading.dismiss()
|
||||
confirm(unitName, count, price, totalPrice)
|
||||
}, 500)
|
||||
}
|
||||
} else {
|
||||
confirm(unitName, count, price, totalPrice)
|
||||
binding.root.postDelayed({
|
||||
Loading.dismiss()
|
||||
confirm(unitName, count, price, totalPrice)
|
||||
}, 500)
|
||||
}
|
||||
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?) {
|
||||
|
||||
@@ -212,17 +212,25 @@ abstract class BaseViewModel(
|
||||
callback: (List<SearchGoodsInfo.Record>) -> Unit
|
||||
) {
|
||||
launch {
|
||||
if (nameList.isNullOrEmpty() && scoreList.isNullOrEmpty()) return@launch
|
||||
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()
|
||||
try {
|
||||
if (nameList.isNullOrEmpty() && scoreList.isNullOrEmpty()) {
|
||||
callback(listOf())
|
||||
return@launch
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user