diff --git a/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt b/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt index 6af936e..cb39387 100644 --- a/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt +++ b/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt @@ -24,9 +24,11 @@ import androidx.camera.lifecycle.ProcessCameraProvider import androidx.core.content.ContextCompat import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.LinearLayoutManager import com.google.common.util.concurrent.ListenableFuture import com.sw.dualscreen.GlobalData import com.sw.dualscreen.GlobalKey +import com.sw.dualscreen.adapter.FoodOrderAdapter import com.sw.dualscreen.adapter.MainFoodListAdapter import com.sw.dualscreen.databinding.ActivityMainBinding import com.sw.dualscreen.dialog.RemindDialog @@ -290,11 +292,13 @@ class MainActivity : BaseActivity() { if (weight <= WEIGHT_RESET_RECOGNIZE) { //秤上重量过小,显示识别中页面 presentation?.step1FoodRecognizing() + lastWeight = weight return } //余量计量+联合支付人脸查询订单完成 if (presentation!!.jointPaymentQueryFinish) { presentation?.updateWeight(weight) + lastWeight = weight return } val isWeightChange = weight - lastWeight > WEIGHT_CHANGE_VALUE @@ -303,12 +307,15 @@ class MainActivity : BaseActivity() { private fun readWeight(weight: Int) { log("registerDataChange weight = $weight") - runOnUiThread { - binding.tvShowWeight.let { - if (it.text.toString() == weight.toString()) return@runOnUiThread + binding.tvShowWeight.let { + if (it.text.toString() != weight.toString()) { it.text = "$weight" } } + if (weight <= WEIGHT_RESET_RECOGNIZE) { + //检测到秤上没有东西,重新启动识别菜品 && presentation?.mealPickupMode == 1 + checkedItem = null + } if (settlementMode == 0) { //联合支付------------------------------------------- //0-即放即取,1-余量计量 @@ -344,7 +351,9 @@ class MainActivity : BaseActivity() { override fun registerDataChange() { super.registerDataChange() SensorScaleUtils.addWeightListener { value -> - readWeight(value) + runOnUiThread { + readWeight(value) + } } } @@ -356,7 +365,7 @@ class MainActivity : BaseActivity() { presentation?.updateWeight(weight) if (weight <= WEIGHT_RESET_RECOGNIZE) { - log("recognizeByWeight---00002,秤重未超过5克") + log("recognizeByWeight---00002,秤重未超过${WEIGHT_RESET_RECOGNIZE}克") //检测到秤上没有东西,重新启动识别菜品 && presentation?.mealPickupMode == 1 isRecognitionFood = true return @@ -364,8 +373,9 @@ class MainActivity : BaseActivity() { if (isWeightChange && isRecognitionFood) { log("recognizeByWeight---00003,mealPickupMode=${presentation?.mealPickupMode}") - if (presentation?.mealPickupMode == 1) { + if (presentation?.mealPickupMode == 1 && checkedItem != null) { isRecognitionFood = false + return } debouncer.debounce { log("recognizeByWeight---00004") @@ -1171,4 +1181,5 @@ class MainActivity : BaseActivity() { // ObjectBox.init(this) // } + } \ No newline at end of file diff --git a/app/src/main/java/com/sw/dualscreen/adapter/FoodOrderAdapter.kt b/app/src/main/java/com/sw/dualscreen/adapter/FoodOrderAdapter.kt index 06898bf..2628a08 100644 --- a/app/src/main/java/com/sw/dualscreen/adapter/FoodOrderAdapter.kt +++ b/app/src/main/java/com/sw/dualscreen/adapter/FoodOrderAdapter.kt @@ -17,7 +17,7 @@ import com.sw.dualscreen.ext.gone import com.sw.dualscreen.ext.visible import com.sw.dualscreen.model.response.FoodItem -class FoodOrderAdapter(var list: MutableList) : +class FoodOrderAdapter(list: MutableList) : BaseQuickAdapter(list) { inner class VH(var binding: ListItemFoodOrderBinding) : QuickViewHolder(binding.root) @@ -33,10 +33,10 @@ class FoodOrderAdapter(var list: MutableList) : val binding = holder.binding item?.let { binding.tvFoodName.text = it.foodName - val foodPrice = it.foodPrice.format2String(2) if (it.orderFrom == 2) { - binding.tvPriceNorm.text = "${it.specName}/${it.specWeight}克" + binding.tvPriceNorm.text = if (it.specName.isNullOrBlank()) "${it.specWeight}克" else "${it.specName}/${it.specWeight}克" } else { + val foodPrice = it.foodPrice.format2String(2) binding.tvPriceNorm.text = "${foodPrice}/${it.num}克" } //if (it.specName.isNullOrBlank().not()) { diff --git a/app/src/main/java/com/sw/dualscreen/model/response/DataBean.kt b/app/src/main/java/com/sw/dualscreen/model/response/DataBean.kt index bcb61a7..e0d72be 100644 --- a/app/src/main/java/com/sw/dualscreen/model/response/DataBean.kt +++ b/app/src/main/java/com/sw/dualscreen/model/response/DataBean.kt @@ -165,22 +165,23 @@ data class WeightRecord( ) data class FoodItem( - val id: String? = null, - val foodId: String? = null, - val foodName: String? = null, - val foodMaterialId: String? = null, - val specId: String? = null, - val num: Int = 0, - val eatNum: Int = 0, - val price: Double = 0.0, - val foodPrice: Double = 0.0, - val discount: Double = 0.0, - val income: Double = 0.0, - val foodDifferenceId: Long = 0, - val createTime: String? = null, - val specName: String? = null, - val specWeight: Int = 0, - val orderFrom: Int = 0 + var id: String? = null, + var foodId: String? = null, + var foodName: String? = null, + var foodMaterialId: String? = null, + var specId: String? = null, + var num: Int = 0, + var eatNum: Int = 0, + var price: Double = 0.0, + var foodPrice: Double = 0.0, + var discount: Double = 0.0, + var income: Double = 0.0, + var foodDifferenceId: Long = 0, + var createTime: String? = null, + var specName: String? = null, + var specWeight: Int = 0, + var orderFrom: Int = 0, + var isLocalData: Boolean = false ) data class FoodOrderModel( diff --git a/app/src/main/java/com/sw/dualscreen/network/api/ApiService.kt b/app/src/main/java/com/sw/dualscreen/network/api/ApiService.kt index 4c9d227..ed4a106 100644 --- a/app/src/main/java/com/sw/dualscreen/network/api/ApiService.kt +++ b/app/src/main/java/com/sw/dualscreen/network/api/ApiService.kt @@ -314,7 +314,7 @@ interface ApiService { ): ApiResponse /** - * 档口机向量数据分页查询 + * 查询就餐数据 */ @GET suspend fun getFoodOrderList( diff --git a/app/src/main/java/com/sw/dualscreen/presentation/MainScreenPresentation.kt b/app/src/main/java/com/sw/dualscreen/presentation/MainScreenPresentation.kt index 86c010b..6e1962d 100644 --- a/app/src/main/java/com/sw/dualscreen/presentation/MainScreenPresentation.kt +++ b/app/src/main/java/com/sw/dualscreen/presentation/MainScreenPresentation.kt @@ -670,12 +670,63 @@ class MainScreenPresentation( // } } + private var lastAddWeight = 0 + private fun addFoodToOrder(weight: Int, foodInfo: FoodInfo) { + if (weight == lastAddWeight) return + lastAddWeight = weight + if (weight <= 10) { + if (foodOrderList.isNotEmpty()) { + val last = foodOrderList.last() + if (last.isLocalData) { + foodOrderList.remove(last) + foodOrderAdapter.submitList(foodOrderList) + //foodOrderAdapter.notifyDataSetChanged() + } + } + return + } + val foodPrice = if (isMember) foodInfo.vipPrice else foodInfo.specPrice + val eatNum = activity.getEatNum(weight.toDouble(), foodInfo.specWeight) + val price = eatNum * (foodPrice?:0.0) + if (foodOrderList.isNotEmpty()) { + val last = foodOrderList.last() + if (last.isLocalData) { + last.eatNum = eatNum + last.num = weight + last.price = price + foodOrderAdapter.submitList(foodOrderList) + //foodOrderAdapter.notifyItemChanged(foodOrderList.lastIndex) + return + } + } + foodOrderList.add(FoodItem( + id = System.currentTimeMillis().toString(), + foodId = foodInfo.foodId, + foodName = foodInfo.foodName, + price = price, + specId = foodInfo.specId, + foodMaterialId = foodInfo.foodMaterialId, + specWeight = foodInfo.specWeight?.toInt() ?: 0, + orderFrom = 2, + num = weight, + eatNum = eatNum, + isLocalData = true + )) + foodOrderAdapter.submitList(foodOrderList) + //foodOrderAdapter.notifyDataSetChanged() + } + private fun calculateNutrition(value: Int) { if (currentFood == null || userNutrition == null) { return } var weight = value if (weight < 0) weight = 0 + if (activity.settlementMode == 0) { + activity.runOnUiThread { + addFoodToOrder(weight, currentFood!!) + } + } debouncer.debounce { Timber.tag(TAG) .d("calculateNutrition weight = $weight, recognitionWeight = $recognitionWeight") @@ -1341,7 +1392,7 @@ class MainScreenPresentation( it.root.updateLayoutParams { height = activity.screenSize[1] / 2 + 120.dp } - it.tvFoodList.run { + it.rvFoodList.run { if (adapter == null) { layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) @@ -1349,16 +1400,17 @@ class MainScreenPresentation( } } userViewModel.getFoodOrderList(userId) { model -> - if (model == null) return@getFoodOrderList - foodOrderList.clear() - model.list?.let { - foodOrderList.addAll(model.list) - } - foodOrderAdapter.notifyDataSetChanged() - binding.detailInclude.tvTotalWeight.text = "总重量:${model.eatWeightSum}克" - binding.detailInclude.tvTotalCalorie.text = - "总热量:${model.calorie.roundToInt()}千卡" - jointPaymentQueryFinish = true + activity.runOnUiThread { + if (model == null) return@runOnUiThread + foodOrderList.clear() + foodOrderList.addAll(model.list?:emptyList()) + foodOrderAdapter.submitList(foodOrderList) + //foodOrderAdapter.notifyDataSetChanged() + binding.detailInclude.tvTotalWeight.text = "总重量:${model.eatWeightSum}克" + binding.detailInclude.tvTotalCalorie.text = + "总热量:${model.calorie.roundToInt()}千卡" + jointPaymentQueryFinish = true + } } } } diff --git a/app/src/main/res/drawable/bg_order_flag.xml b/app/src/main/res/drawable/bg_order_flag.xml index 220e6d3..69f3fef 100644 --- a/app/src/main/res/drawable/bg_order_flag.xml +++ b/app/src/main/res/drawable/bg_order_flag.xml @@ -1,7 +1,7 @@ - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 094bbcb..4cc2766 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -51,10 +51,11 @@ @@ -87,6 +88,7 @@ android:layout_margin="27dp" android:background="@drawable/ic_camera_rect" /> +