From eaa1b1eb0029ed63f259057abb68c5250c7e73ba Mon Sep 17 00:00:00 2001 From: lvmeng <848755140@qq.com> Date: Fri, 30 Jan 2026 18:01:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E6=8E=A5=E5=8F=A3=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dish/match/adapter/SamplingAdapter.kt | 18 +++-- .../com/shuwei/dish/match/base/BaseApp.kt | 6 +- .../dish/match/dialog/FoodSearchDialog.kt | 24 +++---- .../match/dialog/SeasoningSearchDialog.kt | 24 +++---- .../com/shuwei/dish/match/net/ApiService.kt | 12 +--- .../com/shuwei/dish/match/net/ApiService2.kt | 68 ------------------- .../com/shuwei/dish/match/net/NetViewModel.kt | 30 -------- .../dish/match/ui/FoodSearchActivity.kt | 10 +-- .../com/shuwei/dish/match/ui/InitActivity.kt | 59 ++++++++-------- .../match/ui/fragment/DishListFragment.kt | 4 +- 10 files changed, 74 insertions(+), 181 deletions(-) delete mode 100644 app/src/main/java/com/shuwei/dish/match/net/ApiService2.kt diff --git a/app/src/main/java/com/shuwei/dish/match/adapter/SamplingAdapter.kt b/app/src/main/java/com/shuwei/dish/match/adapter/SamplingAdapter.kt index 3ae27b6..b35fc7c 100644 --- a/app/src/main/java/com/shuwei/dish/match/adapter/SamplingAdapter.kt +++ b/app/src/main/java/com/shuwei/dish/match/adapter/SamplingAdapter.kt @@ -9,7 +9,6 @@ import com.chad.library.adapter4.viewholder.QuickViewHolder import com.shuwei.dish.match.R import com.shuwei.dish.match.entity.FoodRecord import com.shuwei.dish.match.databinding.ListItemDishBinding -import com.shuwei.dish.match.utils.ext.gone import com.shuwei.dish.match.utils.ext.visible import java.text.DecimalFormat @@ -28,9 +27,9 @@ class SamplingAdapter(list: MutableList) : holder.binding.run { val isCooking = item!!.isCooking clBlock.setBackgroundResource(R.drawable.shape_white_fb_15_corners) - val totalWeight = item!!.totalWeight ?: 0.toDouble() + val totalWeight = item.totalWeight ?: 0.toDouble() tvDishName.run { - text = item!!.foodName + text = (item.foodName?:"").ifBlank { "--" } setTextColor( ContextCompat.getColor( holder.itemView.context, @@ -41,11 +40,16 @@ class SamplingAdapter(list: MutableList) : tvDishCount.visible() if (isCooking) { tvDishCount.text = "制作统计:-kg" - tvShowState.text = "烹饪中" + tvShowState.text = "烹饪中" } else { - val useWeight = if (totalWeight > 0.toDouble()) totalWeight else (item.foodWeight ?: 0.toDouble()) - tvDishCount.text = "累计统计:${df.format(useWeight / 1000.0F)}kg(${item.count}次)" - tvShowState.text = "${df.format((item.foodWeight ?: 0.toDouble()) / 1000.0F)}kg" + val realTotalWeight = if (totalWeight > 0.toDouble()) totalWeight else (item.foodWeight + ?: 0.toDouble()) + val showTotalWeight = + if (realTotalWeight == 0.toDouble()) "-" else df.format(realTotalWeight / 1000.0F) + tvDishCount.text = "累计统计:${showTotalWeight}kg(${item.count ?: "-"}次)" + val foodWeight = item.foodWeight ?: 0.toDouble() + val showFoodWeight = if (foodWeight == 0.toDouble()) "-" else df.format(foodWeight / 1000.0F) + tvShowState.text = "${showFoodWeight}kg" } } } diff --git a/app/src/main/java/com/shuwei/dish/match/base/BaseApp.kt b/app/src/main/java/com/shuwei/dish/match/base/BaseApp.kt index d63db84..467a53c 100644 --- a/app/src/main/java/com/shuwei/dish/match/base/BaseApp.kt +++ b/app/src/main/java/com/shuwei/dish/match/base/BaseApp.kt @@ -32,10 +32,10 @@ class BaseApp : Application() { // const val canteenId = "1678234139391512577" var canteenId = "0" - var configUrl = "" +// var configUrl = "" - var token: String? = null - var deviceId: String? = null +// var token: String? = null +// var deviceId: String? = null var appVersion: String = "1" @Volatile private var sharedPref: SharedPreferences? = null diff --git a/app/src/main/java/com/shuwei/dish/match/dialog/FoodSearchDialog.kt b/app/src/main/java/com/shuwei/dish/match/dialog/FoodSearchDialog.kt index bb88d7f..73d562a 100644 --- a/app/src/main/java/com/shuwei/dish/match/dialog/FoodSearchDialog.kt +++ b/app/src/main/java/com/shuwei/dish/match/dialog/FoodSearchDialog.kt @@ -138,7 +138,7 @@ class FoodSearchDialog( } private var pageNo = 1 - private val pageSize = 120 + private val pageSize = 50 /** */ @@ -204,22 +204,27 @@ class FoodSearchDialog( "pageSize" to pageSize ) if (goodsName.isNullOrBlank().not()) { - param.put("name", goodsName!!) + param.put("goodsName", goodsName!!) } activity?.queryGoodsList(param = param, onSuccess = { loadGoodsList(it) }, onFailure = { code, msg -> activity?.toast(msg) - if (pageNo == 1) { - binding.refreshLayout.finishRefresh(1200) - } else { - binding.refreshLayout.finishLoadMore(1200) - } + finishRefresh() }) } + private fun finishRefresh() { + if (pageNo == 1) { + binding.refreshLayout.finishRefresh() + } else { + binding.refreshLayout.finishLoadMore() + } + } + @SuppressLint("NotifyDataSetChanged") private fun loadGoodsList(records: MutableList?) { + finishRefresh() if (records.isNullOrEmpty()) { activity?.toast("暂未搜索到食材信息") return @@ -229,11 +234,6 @@ class FoodSearchDialog( } list.addAll(records) searchAdapter.notifyDataSetChanged() - if (pageNo == 1) { - binding.refreshLayout.finishRefresh(1200) - } else { - binding.refreshLayout.finishLoadMore(1200) - } val isLoadMoreEnable = records.size >= pageSize binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable) if (isLoadMoreEnable) { diff --git a/app/src/main/java/com/shuwei/dish/match/dialog/SeasoningSearchDialog.kt b/app/src/main/java/com/shuwei/dish/match/dialog/SeasoningSearchDialog.kt index 9faecca..8f9007d 100644 --- a/app/src/main/java/com/shuwei/dish/match/dialog/SeasoningSearchDialog.kt +++ b/app/src/main/java/com/shuwei/dish/match/dialog/SeasoningSearchDialog.kt @@ -167,6 +167,7 @@ class SeasoningSearchDialog( } } binding.refreshLayout.setEnableRefresh(false) + binding.refreshLayout.setEnableLoadMore(false) binding.tvClear.setOnClickListener { Log.d(TAG, "show: weighAddress=$weighAddress") WeightUtil.tareTwo(weighAddress) @@ -204,7 +205,7 @@ class SeasoningSearchDialog( private var currentWeight = 0.toDouble() private var pageNo = 1 - private val pageSize = 120 + private val pageSize = 50 /** */ @@ -271,7 +272,7 @@ class SeasoningSearchDialog( "pageSize" to pageSize ) if (goodsName.isNullOrBlank().not()) { - param.put("name", goodsName!!) + param.put("goodsName", goodsName!!) } activity?.querySeasoningList( param = param, @@ -280,17 +281,14 @@ class SeasoningSearchDialog( }, onFailure = { code, msg -> activity?.toast(msg) - if (pageNo == 1) { - binding.refreshLayout.finishRefresh(1200) - } else { - binding.refreshLayout.finishLoadMore(1200) - } + finishRefresh() } ) } @SuppressLint("NotifyDataSetChanged") private fun loadGoodsList(records: MutableList?) { + finishRefresh() if (records.isNullOrEmpty()) { activity?.toast("暂未搜索到调料信息") return @@ -300,11 +298,6 @@ class SeasoningSearchDialog( } list.addAll(records) searchAdapter.notifyDataSetChanged() - if (pageNo == 1) { - binding.refreshLayout.finishRefresh(1200) - } else { - binding.refreshLayout.finishLoadMore(1200) - } val isLoadMoreEnable = records.size >= pageSize binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable) if (isLoadMoreEnable) { @@ -312,6 +305,13 @@ class SeasoningSearchDialog( } } + private fun finishRefresh() { + if (pageNo == 1) { + binding.refreshLayout.finishRefresh() + } else { + binding.refreshLayout.finishLoadMore() + } + } fun getTextSpan(weight: Double): SpannableStringBuilder { var topWeight = "$weight" diff --git a/app/src/main/java/com/shuwei/dish/match/net/ApiService.kt b/app/src/main/java/com/shuwei/dish/match/net/ApiService.kt index 4f09fb5..6068323 100644 --- a/app/src/main/java/com/shuwei/dish/match/net/ApiService.kt +++ b/app/src/main/java/com/shuwei/dish/match/net/ApiService.kt @@ -13,14 +13,6 @@ import retrofit2.http.Url interface ApiService { -// @GET("/food/stFoodInfoMatching/list") -// suspend fun getFoodList( -// @Query("dinnerType") dinnerType: String, -// @Query("canteenId") canteenId: String = BaseApp.canteenId, -// @Query("pageNo") pageNo: Int, -// @Query("pageSize") pageSize: Int -// ): ApiResponse - /** * 查询菜品详情 */ @@ -67,8 +59,8 @@ interface ApiService { @Body param: MutableMap ): ApiResponse?> -/** - * 物品信息 + /** + * 调料信息 */ @POST suspend fun querySeasoningList( diff --git a/app/src/main/java/com/shuwei/dish/match/net/ApiService2.kt b/app/src/main/java/com/shuwei/dish/match/net/ApiService2.kt deleted file mode 100644 index 15255ef..0000000 --- a/app/src/main/java/com/shuwei/dish/match/net/ApiService2.kt +++ /dev/null @@ -1,68 +0,0 @@ -//package com.shuwei.dish.match.net -// -//import com.shuwei.dish.match.base.BaseApp -//import com.shuwei.dish.match.base.BaseReq -//import com.shuwei.dish.match.entity.FoodRecordBean -//import com.shuwei.dish.match.http.UrlConfig -//import retrofit2.http.Body -//import retrofit2.http.GET -//import retrofit2.http.POST -//import retrofit2.http.Query -//import retrofit2.http.Url -// -//interface ApiService2 { -// -// @GET("food/stFoodInfoMatching/list") -// suspend fun getDishList( -// @Query("dinnerType") dinnerType: String, -// @Query("canteenId") canteenId: String = BaseApp.canteenId, -// @Query("pageNo") pageNo: Int, -// @Query("pageSize") pageSize: Int -// ): BaseReq -// -//// /** -//// * device获取token -//// */ -//// @GET("/sys/getEquipmentToken") -//// suspend fun getDeviceToken( -//// @Query("qrcodeId") qrcodeId: String, -//// @Query("appVersion") appVersion: String = App.appVersion -//// ): ApiResponse -//// -//// /** -//// *获取配置信息 -//// */ -//// @GET("/equipment/stEquipment/queryByEquipmentCode") -//// suspend fun getDeviceInfo( -//// @Query("equipmentCode") equipmentCode: String, -//// @Query("appVersion") appVersion: String = App.appVersion -//// ): ApiResponse -//// -//// @GET -//// suspend fun getAccessToken( -//// @Url url: String = UrlConfig.GET_ACCESS_TOKEN, -//// @Query("qrcodeId") qrcodeId: String -//// ): ApiResponse -//// -//// @GET -//// suspend fun getShelfList( -//// @Url url: String = UrlConfig.GET_SHELF_LIST, -//// @Query("deviceId") deviceId: String -//// ): ApiResponse -//// -//// @GET -//// suspend fun getGoodsList( -//// @Url url: String = UrlConfig.GET_GOODS_LIST, -//// @Query("canteenId") canteenId: String = "0", -//// @Query("goodsName") goodsName: String? = null, -//// @Query("pageNo") pageNo: Int = 1, -//// @Query("pageSize") pageSize: Int = 50 -//// ): ApiResponse?> -//// -//// @POST -//// suspend fun saveShelfGoodsList( -//// @Url url: String = UrlConfig.SAVE_SHELF_GOODS_LIST, -//// @Body body: ShelfBody -//// ): ApiResponse -// -//} \ No newline at end of file diff --git a/app/src/main/java/com/shuwei/dish/match/net/NetViewModel.kt b/app/src/main/java/com/shuwei/dish/match/net/NetViewModel.kt index cd78796..2adbb24 100644 --- a/app/src/main/java/com/shuwei/dish/match/net/NetViewModel.kt +++ b/app/src/main/java/com/shuwei/dish/match/net/NetViewModel.kt @@ -10,36 +10,6 @@ import kotlinx.coroutines.launch class NetViewModel : ViewModel() { -// fun getFoodList( -// dinnerType: String, -// pageNo: Int, -// pageSize: Int, -// onSuccess: (FoodRecordBean?) -> Unit, -// onFailure: (String, String) -> Unit -// ) { -// viewModelScope.launch { -// apiRequest( -// onRequest = { -// apiService2.getDishList( -// dinnerType = dinnerType, -// pageNo = pageNo, -// pageSize = pageSize -// ) -// }, -// onSuccess = { -// if (it.code == 200) { -// onSuccess(it.data) -// return@apiRequest -// } -// onFailure("${it.code}", it.msg ?: "") -// }, -// onFailure = { -// onFailure("-1", it.errorMsg) -// } -// ) -// } -// } - fun submitCookFood( entity: CookFoodEntity, onSuccess: (Any?) -> Unit, diff --git a/app/src/main/java/com/shuwei/dish/match/ui/FoodSearchActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/FoodSearchActivity.kt index 4b8ff2e..9df5d76 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/FoodSearchActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/FoodSearchActivity.kt @@ -197,8 +197,8 @@ class FoodSearchActivity : BaseActivity() { val map = mutableMapOf( "foodName" to input.trim(), - "pageNum" to "$pageNo", - "pageSize" to "$pageSize", + "pageNum" to pageNo, + "pageSize" to pageSize, "placeId" to BaseApp.canteenId, "dinnerType" to getDinnerTypeText() ) @@ -207,10 +207,7 @@ class FoodSearchActivity : BaseActivity() { onSuccess = { delayDismissLoading() finishRefresh() - binding.refreshLayout.run { - setEnableRefresh(true) - } -// if (it == null || it.records.isNullOrEmpty()) { + binding.refreshLayout.setEnableRefresh(true) if (it.isNullOrEmpty()) { // toast("暂未搜索到相关菜品信息") if (pageNo == 1) { @@ -218,7 +215,6 @@ class FoodSearchActivity : BaseActivity() { } return@searchFoodList } -// val records = it.records if (pageNo == 1) { list.clear() } diff --git a/app/src/main/java/com/shuwei/dish/match/ui/InitActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/InitActivity.kt index cf178fc..2ffba34 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/InitActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/InitActivity.kt @@ -44,12 +44,11 @@ class InitActivity : BaseActivity() { BaseApp.appVersion = AppUtil.getAppVersionCode(this).toString() // 获取 ANDROID_ID - var androidId = - Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID) - androidId = "39a7abdd06b3c7ab" - BaseApp.deviceId = androidId - SpTool.put(SpTool.DEVICE_ID, androidId) - BaseApp.configUrl = UrlConfig.BASE_URL +// var androidId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID) +// androidId = "39a7abdd06b3c7ab" +// BaseApp.deviceId = androidId +// SpTool.put(SpTool.DEVICE_ID, androidId) +// BaseApp.configUrl = UrlConfig.BASE_URL BaseApp.canteenId = "0" // // TODO: 以上保存deviceId用于临时使用,后续改为下面注释方式 @@ -150,18 +149,18 @@ class InitActivity : BaseActivity() { } } - private fun initConfig() { - binding.ivQrCode.setImageBitmap( - QRCodeUtil.generateQRCode( - content = BaseApp.deviceId ?: "", - size = 200.dp - ) - ) - binding.btnInit.setOnClickListener { -// HttpUtil.loopGetToken = false -// getDeviceConfig() - } - } +// private fun initConfig() { +// binding.ivQrCode.setImageBitmap( +// QRCodeUtil.generateQRCode( +// content = BaseApp.deviceId ?: "", +// size = 200.dp +// ) +// ) +// binding.btnInit.setOnClickListener { +//// HttpUtil.loopGetToken = false +//// getDeviceConfig() +// } +// } // private fun getDeviceConfig() { // val tokenUrl = @@ -203,18 +202,18 @@ class InitActivity : BaseActivity() { var canteenId: String? = null ) - private fun checkConfigData(data: String): Boolean { - if (data.isBlank()) { - return false - } - val config = data.toObject() - if (config == null) { - return false - } - BaseApp.configUrl = config.appPackageUrl ?: "" - BaseApp.canteenId = config.canteenId ?: "" - return true - } +// private fun checkConfigData(data: String): Boolean { +// if (data.isBlank()) { +// return false +// } +// val config = data.toObject() +// if (config == null) { +// return false +// } +// BaseApp.configUrl = config.appPackageUrl ?: "" +// BaseApp.canteenId = config.canteenId ?: "" +// return true +// } override fun onDestroy() { WeightUtil.stopContinuousRead() diff --git a/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishListFragment.kt b/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishListFragment.kt index b1e96c2..c6a90b0 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishListFragment.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishListFragment.kt @@ -156,10 +156,10 @@ class DishListFragment : BaseFragment() { "placeId" to BaseApp.canteenId, "dinnerType" to getDinnerTypeText() ), - onSuccess = { recordBean -> + onSuccess = { records -> activity.delayDismissLoading() finishRefresh() - loadDishList(recordBean) + loadDishList(records) }, onFailure = { code, msg -> if (isAdded.not()) {