diff --git a/app/release/baselineProfiles/0/app-release.dm b/app/release/baselineProfiles/0/app-release.dm deleted file mode 100644 index ba4dbe6..0000000 Binary files a/app/release/baselineProfiles/0/app-release.dm and /dev/null differ diff --git a/app/src/main/java/com/shuwei/dish/match/dialog/BottomDialog2.kt b/app/src/main/java/com/shuwei/dish/match/dialog/BottomDialog2.kt index ead680d..bce6dc0 100644 --- a/app/src/main/java/com/shuwei/dish/match/dialog/BottomDialog2.kt +++ b/app/src/main/java/com/shuwei/dish/match/dialog/BottomDialog2.kt @@ -129,7 +129,12 @@ class BottomDialog2( } binding.refreshLayout.setEnableRefresh(false) binding.tvClear.setOnClickListener { + Log.d(TAG, "show: weighAddress=$weighAddress") WeightUtil.tareTwo(weighAddress) +// repeat(14) { num-> +// Log.d(TAG, "show: num=$num") +// WeightUtil.tareTwo(num+1) +// } } WeightUtil.addWeightListener { address, state, weight -> if (weighAddress == address) { diff --git a/app/src/main/java/com/shuwei/dish/match/ui/DeviceConfigActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/DeviceConfigActivity.kt index 650c784..9b498cc 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/DeviceConfigActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/DeviceConfigActivity.kt @@ -138,16 +138,20 @@ class DeviceConfigActivity : BaseActivity() { } private fun addWeighListener() { - WeightUtil.addWeightListener { address, state, weight -> -// Log.d(TAG, "addWeighListener: address=$address,stat=$state,weight=$weight") + WeightUtil.addWeightListener(onConnect = { state -> + binding.viewPoint.setBackgroundResource( + if (state) R.drawable.bg_circle_green else R.drawable.bg_circle_red + ) + }, getWeight = { address, state, weight -> + Log.d(TAG, "addWeighListener: address=$address,stat=$state,weight=$weight") weightArray.put(address, weight) - val item = seasoningItems.firstOrNull { address == addressArray[it.sort]} + val item = seasoningItems.firstOrNull { address == addressArray[it.sort] } item?.let { it.useWeight = weight.toDouble() updateGridData(it) } //setGridData(seasoningItems) - } + }) } private var seasoningItems = mutableListOf() @@ -229,15 +233,15 @@ class DeviceConfigActivity : BaseActivity() { list.forEach { entity -> val tag = entity.sort.toString() val frameLayout = gridLayout.findViewWithTag(tag) - TextCellAdapter.loadLayout(frameLayout , entity) + TextCellAdapter.loadLayout(frameLayout, entity) } } - private fun updateGridData(entity:SeasoningEntity) { + private fun updateGridData(entity: SeasoningEntity) { val gridLayout = binding.include.root val tag = entity.sort.toString() val frameLayout = gridLayout.findViewWithTag(tag) - TextCellAdapter.loadLayout(frameLayout , entity) + TextCellAdapter.loadLayout(frameLayout, entity) } private fun clickGridItem(sort: Int, entity: SeasoningEntity) { 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 e4b5581..374732f 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 @@ -76,7 +76,7 @@ class InitActivity : BaseActivity() { initViewModel() WeightUtil.init() - WeightUtil.connect {} +// WeightUtil.connect {} WeightUtil.getWeight() WeightUtil.startContinuousRead() HttpUtil.getAppToken() 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 603905c..812c3ad 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 @@ -165,42 +165,24 @@ class DishListFragment : BaseFragment() { HttpUtil.get( url = sb.toString(), doSuccess = { - binding.refreshLayout.run { - setEnableRefresh(true) - } - activity.delayDismissLoading() - finishRefresh() - val json = it.toJsonString() - val recordBean: FoodRecordBean? = json.toObject() - if (recordBean == null || recordBean.records.isNullOrEmpty()) { - //toast("暂未搜索到相关菜品信息") + loadDishList(it) + }, doFailure = { code, msg -> + try { + if (isAdded.not()) { + return@get + } + binding.refreshLayout.run { + setEnableRefresh(true) + } + toast(msg) + finishRefresh() if (pageNo == 1) { loadEmptyView() } - return@get + activity.delayDismissLoading() + } catch (e: Exception) { + e.printStackTrace() } - val records = recordBean.records - if (pageNo == 1) { - list.clear() - } - list.addAll(records!!) - dishAdapter.notifyDataSetChanged() - val isLoadMoreEnable = records.size >= pageSize - binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable) - if (isLoadMoreEnable) { - pageNo++ - } - refreshLocalData(list) - }, doFailure = { code, msg -> - binding.refreshLayout.run { - setEnableRefresh(true) - } - toast(msg) - finishRefresh() - if (pageNo == 1) { - loadEmptyView() - } - activity.delayDismissLoading() }) } @@ -269,5 +251,41 @@ class DishListFragment : BaseFragment() { } } + @SuppressLint("NotifyDataSetChanged") + private fun loadDishList(data: Any) { + try { + if (isAdded.not()) { + return + } + binding.refreshLayout.run { + setEnableRefresh(true) + } + activity.delayDismissLoading() + finishRefresh() + val json = data.toJsonString() + val recordBean: FoodRecordBean? = json.toObject() + if (recordBean == null || recordBean.records.isNullOrEmpty()) { + //toast("暂未搜索到相关菜品信息") + if (pageNo == 1) { + loadEmptyView() + } + return + } + val records = recordBean.records + if (pageNo == 1) { + list.clear() + } + list.addAll(records!!) + dishAdapter.notifyDataSetChanged() + val isLoadMoreEnable = records.size >= pageSize + binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable) + if (isLoadMoreEnable) { + pageNo++ + } + refreshLocalData(list) + } catch (e: Exception) { + e.printStackTrace() + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/shuwei/dish/match/utils/WeightUtil.kt b/app/src/main/java/com/shuwei/dish/match/utils/WeightUtil.kt index f2c1fba..7136202 100644 --- a/app/src/main/java/com/shuwei/dish/match/utils/WeightUtil.kt +++ b/app/src/main/java/com/shuwei/dish/match/utils/WeightUtil.kt @@ -9,8 +9,74 @@ import com.wabon.wbintelligenthardwaresdk.api.SensorScale object WeightUtil { + var isConnected = false + fun init() { Weigher.init() + +// Weigher.setListener(object : WeightListenerImpl() { +// override fun onInit(connect: Boolean) { +// Log.d("WeightUtil", "connect=$connect") +// } +// +// override fun onZero() { +// Log.d("WeightUtil", "zero ok") +// } +// +// override fun onTare() { +// Log.d("WeightUtil", "去皮置零操作成功") +// } +// +// override fun onSetIdentify() { +// Log.d("WeightUtil", "鉴别率设置操作成功") +// } +// +// override fun onGetWeight(address: Int, state: Int, weight: Int) { +// runOnUiThread { +// val stateStr = when (state) { +// SensorScale.STATE_STABLE -> "稳定" +// SensorScale.STATE_UNSTABLE -> "不稳定" +// SensorScale.STATE_OVER_WEIGHT -> "量程溢出" +// else -> "" +// } +// val result1 = String.format("$stateStr 重量:%s kg", weight / 1000f) +// Log.d("WeightUtil", "ttlReturn, address:$address,$result1") +//// weightArray.put(address, weight) +// } +// } +// +// override fun onReadIdentify(rate: Int) { +// Log.d("WeightUtil", "读取鉴别率成功:rate=$rate") +// } +// +// override fun onFail(errCode: Int) { +// val str = when (errCode) { +// Weigher.ERR_001 -> "电子称未初始化" +// Weigher.ERR_002 -> "开机零位异常" +// Weigher.ERR_003 -> "传感器故障" +// Weigher.ERR_004 -> "鉴别率超出范围" +// Weigher.ERR_PCB_NOT_SUPPORT -> "主板不支持, " + Build.MODEL +// else -> "" +// } +// Log.d("WeightUtil", str) +// } +// +// override fun onFastFilter() { +// Log.d("WeightUtil", "快速滤波设置成功") +// } +// +// override fun onReadParam() { +// Log.d("WeightUtil", "prepare ok") +// } +// +// override fun onRangCal() { +// Log.d("WeightUtil", "rang cal ok") +// } +// +// override fun onSetParam() { +// Log.d("WeightUtil", "onSetParam") +// } +// }) } fun getWeight() { @@ -25,73 +91,6 @@ object WeightUtil { Weigher.tareTwo(address) } - fun connect(initCallback: (connect: Boolean) -> Unit) { - Weigher.setListener(object : WeightListenerImpl() { - override fun onInit(connect: Boolean) { - initCallback(connect) - Log.d("WeightUtil", "connect=$connect") - } - - override fun onZero() { - Log.d("WeightUtil", "zero ok") - } - - override fun onTare() { - Log.d("WeightUtil", "去皮置零操作成功") - } - - override fun onSetIdentify() { - Log.d("WeightUtil", "鉴别率设置操作成功") - } - - override fun onGetWeight(address: Int, state: Int, weight: Int) { - runOnUiThread { - val stateStr = when (state) { - SensorScale.STATE_STABLE -> "稳定" - SensorScale.STATE_UNSTABLE -> "不稳定" - SensorScale.STATE_OVER_WEIGHT -> "量程溢出" - else -> "" - } - val result1 = String.format("$stateStr 重量:%s kg", weight / 1000f) - Log.d("WeightUtil", "ttlReturn, address:$address,$result1") -// weightArray.put(address, weight) - } - } - - override fun onReadIdentify(rate: Int) { - Log.d("WeightUtil", "读取鉴别率成功:rate=$rate") - } - - override fun onFail(errCode: Int) { - val str = when (errCode) { - Weigher.ERR_001 -> "电子称未初始化" - Weigher.ERR_002 -> "开机零位异常" - Weigher.ERR_003 -> "传感器故障" - Weigher.ERR_004 -> "鉴别率超出范围" - Weigher.ERR_PCB_NOT_SUPPORT -> "主板不支持, " + Build.MODEL - else -> "" - } - Log.d("WeightUtil", str) - } - - override fun onFastFilter() { - Log.d("WeightUtil", "快速滤波设置成功") - } - - override fun onReadParam() { - Log.d("WeightUtil", "prepare ok") - } - - override fun onRangCal() { - Log.d("WeightUtil", "rang cal ok") - } - - override fun onSetParam() { - Log.d("WeightUtil", "onSetParam") - } - }) - } - private fun runOnUiThread(action: () -> Unit) { Handler(Looper.getMainLooper()).post { action() @@ -99,10 +98,16 @@ object WeightUtil { } fun addWeightListener( - zero: (() -> Unit) = {}, + onConnect: (state: Boolean) -> Unit = {}, + zero: () -> Unit = {}, getWeight: ((address: Int, state: Int, weight: Int) -> Unit) = { _, _, _ -> } ) { Weigher.setListener(object : WeightListenerImpl() { + override fun onInit(connect: Boolean) { + super.onInit(connect) + onConnect(connect) + } + override fun onZero() { zero() } @@ -141,7 +146,15 @@ open class WeightListenerImpl : Weigher.Listener { } override fun onFail(errCode: Int) { - + val str = when (errCode) { + Weigher.ERR_001 -> "电子称未初始化" + Weigher.ERR_002 -> "开机零位异常" + Weigher.ERR_003 -> "传感器故障" + Weigher.ERR_004 -> "鉴别率超出范围" + Weigher.ERR_PCB_NOT_SUPPORT -> "主板不支持, " + Build.MODEL + else -> "" + } + Log.d("WeightUtil", str) } override fun onFastFilter() { diff --git a/app/src/main/res/drawable/bg_circle_green.xml b/app/src/main/res/drawable/bg_circle_green.xml new file mode 100644 index 0000000..2d85d1d --- /dev/null +++ b/app/src/main/res/drawable/bg_circle_green.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_circle_red.xml b/app/src/main/res/drawable/bg_circle_red.xml new file mode 100644 index 0000000..2759d51 --- /dev/null +++ b/app/src/main/res/drawable/bg_circle_red.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_device_config.xml b/app/src/main/res/layout/activity_device_config.xml index d5a3020..8304f3e 100644 --- a/app/src/main/res/layout/activity_device_config.xml +++ b/app/src/main/res/layout/activity_device_config.xml @@ -98,10 +98,11 @@ android:layout_marginBottom="60dp" android:background="@drawable/shape_white_30_corners" android:orientation="vertical" + android:gravity="center_vertical" android:layout_marginStart="30dp" android:layout_marginEnd="30dp"> - - + + +