This commit is contained in:
mazengfei
2026-01-30 16:38:42 +08:00
parent efcf3d436b
commit 6439720182
4 changed files with 90 additions and 9 deletions
@@ -51,6 +51,8 @@ import com.sw.inbound.utils.ext.visible
import com.sw.inbound.viewmodel.ReceiptViewModel
import dagger.hilt.android.AndroidEntryPoint
import io.objectbox.Box
import io.objectbox.exception.DbException
import io.objectbox.exception.FileCorruptException
import io.objectbox.kotlin.boxFor
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
@@ -255,7 +257,7 @@ class FoodCollectionActivity : ComponentActivity() {
@SuppressLint("NotifyDataSetChanged")
private fun clearData() {
val count = collectList.count { it.imageFile !=null }
val count = collectList.count { it.imageFile != null }
if (count == 0) return
clearCoilCache(this)
collectList.forEach {
@@ -308,7 +310,17 @@ class FoodCollectionActivity : ComponentActivity() {
toast("操作失败")
return@let
}
val foodList = FoodModule.queryFoodNameScore(imageVector)
val foodList = try {
FoodModule.queryFoodNameScore(imageVector)
} catch (e: DbException) {
try {
ObjectBox.init(this)
} catch (e: Exception) {
e.printStackTrace()
}
toast("数据库异常,请稍后重试")
return@let
}
val filterList =
foodList.filter { it.score < FoodModule.BAG_RATE && it.name.contains("黑袋子") }
if (filterList.isNotEmpty()) {
@@ -342,7 +354,20 @@ class FoodCollectionActivity : ComponentActivity() {
} catch (e: Exception) {
e.printStackTrace()
hideWaitingDialog()
toast("程序异常${e.message}")
val errMsg = e.message ?: ""
if (errMsg.contains("Could not get from cursor") ||
e is FileCorruptException ||
e is DbException
) {
try {
ObjectBox.init(this)
} catch (e: Exception) {
e.printStackTrace()
}
toast("请重试")
} else {
toast("程序异常$errMsg")
}
}
}
@@ -354,7 +379,7 @@ class FoodCollectionActivity : ComponentActivity() {
// .filter { it.imageVector != null }
.forEachIndexed { index, it ->
//image2VectorTask(it.bitmap!!, index)
it.imageVector?.let{ imageVector ->
it.imageVector?.let { imageVector ->
image2VectorTask(imageVector = imageVector, position = index)
}
}
@@ -559,7 +584,8 @@ class FoodCollectionActivity : ComponentActivity() {
runOnUiThread {
hideWaitingDialog()
val view = View.inflate(this, R.layout.dialog_waiting, null)
if (!TextUtils.isEmpty(tip)) (view.findViewById<View?>(R.id.tvTip) as TextView).text = tip
if (!TextUtils.isEmpty(tip)) (view.findViewById<View?>(R.id.tvTip) as TextView).text =
tip
mDialogWaiting = CustomDialog(this, view, R.style.MyDialog)
mDialogWaiting!!.show()
mDialogWaiting!!.setCancelable(true)