fix(ui): 优化菜品制作界面布局和称重功能
- 调整 activity_prepare_cook.xml 中的边距和布局参数 - 更新称重显示文本为“称重:0g”并调整样式 - 在 BaseActivity 中将 loading 显示和隐藏操作移到主线程执行 - 为称重按钮添加防抖点击监听器和清零功能 - 在食物识别过程中添加加载提示和调试日志 - 修复食物识别流程中的加载框显示和隐藏逻辑 - 添加识别结果页面加载功能和取消判断
This commit is contained in:
@@ -162,18 +162,22 @@ open class BaseActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
fun showLoading(msg: String = "加载中……") {
|
||||
Loading.show(
|
||||
context = this,
|
||||
message = msg
|
||||
)
|
||||
handler.post {
|
||||
Loading.show(
|
||||
context = this,
|
||||
message = msg
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun dismissLoading() {
|
||||
Loading.dismiss()
|
||||
handler.post {
|
||||
Loading.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
fun delayDismissLoading() {
|
||||
window.decorView.postDelayed({
|
||||
handler.postDelayed({
|
||||
Loading.dismiss()
|
||||
}, 500)
|
||||
}
|
||||
|
||||
@@ -122,7 +122,11 @@ class PrepareCookActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private fun addViewClickListener() {
|
||||
binding.tvShowWeight.clickWithDebounce { WeightUtil.tareTwo(AddressUtil.ONE) }
|
||||
binding.tvShowWeight.setOnClickListener {
|
||||
showLoading("正在清零……")
|
||||
WeightUtil.tareTwo(AddressUtil.ONE)
|
||||
delayDismissLoading()
|
||||
}
|
||||
WeightUtil.addWeightListener(
|
||||
weightKey = TAG,
|
||||
getWeight = { address, state, weight ->
|
||||
@@ -208,8 +212,10 @@ class PrepareCookActivity : BaseActivity() {
|
||||
return
|
||||
}
|
||||
if (!pageVisible || manualCancelFlag || isTakingPhoto.get() || showRecognizePage || abs(lastWeight - weight) <= WEIGHT_CHANGE_VALUE) {
|
||||
Log.d(TAG, "recognizeFood, lastWeight:$lastWeight, weight:$weight, pageVisible:$pageVisible, manualCancelFlag:$manualCancelFlag, isTakingPhoto:${isTakingPhoto.get()}")
|
||||
return
|
||||
}
|
||||
showLoading("识别中……")
|
||||
isTakingPhoto.set(true)
|
||||
cameraUtils.takePhoto(
|
||||
succCallback = cameraSuccessCallback,
|
||||
@@ -471,12 +477,14 @@ class PrepareCookActivity : BaseActivity() {
|
||||
withContext(Dispatchers.IO) {
|
||||
val bitmap = ImageUtil.uriToBitmap(this@PrepareCookActivity, uri)
|
||||
if (bitmap == null) {
|
||||
dismissLoading()
|
||||
Log.d(TAG, "takePhoto bitmap is null")
|
||||
isTakingPhoto.set(false)
|
||||
return@withContext
|
||||
}
|
||||
val foodScoreList = FoodModule.getFoodScoreList(bitmap)
|
||||
if (foodScoreList.isEmpty()) {
|
||||
dismissLoading()
|
||||
Log.d(TAG, "takePhoto foodScoreList is empty")
|
||||
isTakingPhoto.set(false)
|
||||
return@withContext
|
||||
@@ -495,6 +503,7 @@ class PrepareCookActivity : BaseActivity() {
|
||||
Log.d(TAG, "takePhoto failure")
|
||||
isTakingPhoto.set(false)
|
||||
toast(errMsg)
|
||||
dismissLoading()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -502,10 +511,11 @@ class PrepareCookActivity : BaseActivity() {
|
||||
* @param list 食材列表
|
||||
*/
|
||||
private fun queryFood(list: List<FoodModule.IdNameScore>) {
|
||||
Log.d(TAG, "takePhoto queryFood, list=${list.toString()}")
|
||||
Log.d(TAG, "takePhoto queryFood, list=$list")
|
||||
//调用接口成功,返回食材列表设置isTakingPhoto.set(false),暂时写死数据
|
||||
val foodList = mutableListOf<CookFoodGoodsEntity>()
|
||||
list.forEachIndexed { index, food ->
|
||||
Log.d(TAG, "takePhoto queryFood, index=${index},food=$food")
|
||||
var foodName = ""
|
||||
var foodId = ""
|
||||
food.name.split("WP").let {
|
||||
@@ -527,6 +537,23 @@ class PrepareCookActivity : BaseActivity() {
|
||||
}
|
||||
)
|
||||
}
|
||||
Log.d(TAG, "takePhoto queryFood, 数据添加完成")
|
||||
handler.postDelayed({
|
||||
dismissLoading()
|
||||
loadRecognizeResultPage(foodList)
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载识别结果页面
|
||||
*/
|
||||
private fun loadRecognizeResultPage(foodList: List<CookFoodGoodsEntity>) {
|
||||
if (currentWeight < WEIGHT_RECOGNIZE_VALUE) {
|
||||
Log.d(TAG, "takePhoto queryFood, 已取消")
|
||||
toast("已取消")
|
||||
isTakingPhoto.set(false)
|
||||
return
|
||||
}
|
||||
lastWeight = currentWeight
|
||||
FoodRecognizeActivity.start(
|
||||
activity = this,
|
||||
|
||||
@@ -60,16 +60,14 @@
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:layout_marginVertical="30dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:padding="10dp"
|
||||
android:text="@string/dish_composition"
|
||||
android:textColor="@color/black666"
|
||||
@@ -78,10 +76,12 @@
|
||||
<TextView
|
||||
android:id="@+id/tvShowWeight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:padding="10dp"
|
||||
tools:text="0g"
|
||||
android:layout_height="80dp"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:paddingHorizontal="30dp"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
tools:text="称重:0g"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user