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 = "加载中……") {
|
fun showLoading(msg: String = "加载中……") {
|
||||||
|
handler.post {
|
||||||
Loading.show(
|
Loading.show(
|
||||||
context = this,
|
context = this,
|
||||||
message = msg
|
message = msg
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun dismissLoading() {
|
fun dismissLoading() {
|
||||||
|
handler.post {
|
||||||
Loading.dismiss()
|
Loading.dismiss()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun delayDismissLoading() {
|
fun delayDismissLoading() {
|
||||||
window.decorView.postDelayed({
|
handler.postDelayed({
|
||||||
Loading.dismiss()
|
Loading.dismiss()
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,11 @@ class PrepareCookActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addViewClickListener() {
|
private fun addViewClickListener() {
|
||||||
binding.tvShowWeight.clickWithDebounce { WeightUtil.tareTwo(AddressUtil.ONE) }
|
binding.tvShowWeight.setOnClickListener {
|
||||||
|
showLoading("正在清零……")
|
||||||
|
WeightUtil.tareTwo(AddressUtil.ONE)
|
||||||
|
delayDismissLoading()
|
||||||
|
}
|
||||||
WeightUtil.addWeightListener(
|
WeightUtil.addWeightListener(
|
||||||
weightKey = TAG,
|
weightKey = TAG,
|
||||||
getWeight = { address, state, weight ->
|
getWeight = { address, state, weight ->
|
||||||
@@ -208,8 +212,10 @@ class PrepareCookActivity : BaseActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!pageVisible || manualCancelFlag || isTakingPhoto.get() || showRecognizePage || abs(lastWeight - weight) <= WEIGHT_CHANGE_VALUE) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
showLoading("识别中……")
|
||||||
isTakingPhoto.set(true)
|
isTakingPhoto.set(true)
|
||||||
cameraUtils.takePhoto(
|
cameraUtils.takePhoto(
|
||||||
succCallback = cameraSuccessCallback,
|
succCallback = cameraSuccessCallback,
|
||||||
@@ -471,12 +477,14 @@ class PrepareCookActivity : BaseActivity() {
|
|||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val bitmap = ImageUtil.uriToBitmap(this@PrepareCookActivity, uri)
|
val bitmap = ImageUtil.uriToBitmap(this@PrepareCookActivity, uri)
|
||||||
if (bitmap == null) {
|
if (bitmap == null) {
|
||||||
|
dismissLoading()
|
||||||
Log.d(TAG, "takePhoto bitmap is null")
|
Log.d(TAG, "takePhoto bitmap is null")
|
||||||
isTakingPhoto.set(false)
|
isTakingPhoto.set(false)
|
||||||
return@withContext
|
return@withContext
|
||||||
}
|
}
|
||||||
val foodScoreList = FoodModule.getFoodScoreList(bitmap)
|
val foodScoreList = FoodModule.getFoodScoreList(bitmap)
|
||||||
if (foodScoreList.isEmpty()) {
|
if (foodScoreList.isEmpty()) {
|
||||||
|
dismissLoading()
|
||||||
Log.d(TAG, "takePhoto foodScoreList is empty")
|
Log.d(TAG, "takePhoto foodScoreList is empty")
|
||||||
isTakingPhoto.set(false)
|
isTakingPhoto.set(false)
|
||||||
return@withContext
|
return@withContext
|
||||||
@@ -495,6 +503,7 @@ class PrepareCookActivity : BaseActivity() {
|
|||||||
Log.d(TAG, "takePhoto failure")
|
Log.d(TAG, "takePhoto failure")
|
||||||
isTakingPhoto.set(false)
|
isTakingPhoto.set(false)
|
||||||
toast(errMsg)
|
toast(errMsg)
|
||||||
|
dismissLoading()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -502,10 +511,11 @@ class PrepareCookActivity : BaseActivity() {
|
|||||||
* @param list 食材列表
|
* @param list 食材列表
|
||||||
*/
|
*/
|
||||||
private fun queryFood(list: List<FoodModule.IdNameScore>) {
|
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),暂时写死数据
|
//调用接口成功,返回食材列表设置isTakingPhoto.set(false),暂时写死数据
|
||||||
val foodList = mutableListOf<CookFoodGoodsEntity>()
|
val foodList = mutableListOf<CookFoodGoodsEntity>()
|
||||||
list.forEachIndexed { index, food ->
|
list.forEachIndexed { index, food ->
|
||||||
|
Log.d(TAG, "takePhoto queryFood, index=${index},food=$food")
|
||||||
var foodName = ""
|
var foodName = ""
|
||||||
var foodId = ""
|
var foodId = ""
|
||||||
food.name.split("WP").let {
|
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
|
lastWeight = currentWeight
|
||||||
FoodRecognizeActivity.start(
|
FoodRecognizeActivity.start(
|
||||||
activity = this,
|
activity = this,
|
||||||
|
|||||||
@@ -60,16 +60,14 @@
|
|||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
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">
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="start"
|
android:layout_gravity="start"
|
||||||
|
android:layout_marginVertical="30dp"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
android:text="@string/dish_composition"
|
android:text="@string/dish_composition"
|
||||||
android:textColor="@color/black666"
|
android:textColor="@color/black666"
|
||||||
@@ -78,10 +76,12 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvShowWeight"
|
android:id="@+id/tvShowWeight"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="80dp"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end|center_vertical"
|
||||||
android:padding="10dp"
|
android:paddingHorizontal="30dp"
|
||||||
tools:text="0g"
|
android:gravity="center_vertical"
|
||||||
|
android:maxLines="1"
|
||||||
|
tools:text="称重:0g"
|
||||||
android:textColor="@color/black666"
|
android:textColor="@color/black666"
|
||||||
android:textSize="28sp" />
|
android:textSize="28sp" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user