This commit is contained in:
2025-09-16 19:27:12 +08:00
parent 7ac095c56e
commit 812b95575e
10 changed files with 173 additions and 115 deletions
Binary file not shown.
@@ -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) {
@@ -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<SeasoningEntity>()
@@ -229,15 +233,15 @@ class DeviceConfigActivity : BaseActivity() {
list.forEach { entity ->
val tag = entity.sort.toString()
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(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<FrameLayout>(tag)
TextCellAdapter.loadLayout(frameLayout , entity)
TextCellAdapter.loadLayout(frameLayout, entity)
}
private fun clickGridItem(sort: Int, entity: SeasoningEntity) {
@@ -76,7 +76,7 @@ class InitActivity : BaseActivity() {
initViewModel()
WeightUtil.init()
WeightUtil.connect {}
// WeightUtil.connect {}
WeightUtil.getWeight()
WeightUtil.startContinuousRead()
HttpUtil.getAppToken()
@@ -165,42 +165,24 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
HttpUtil.get(
url = sb.toString(),
doSuccess = {
binding.refreshLayout.run {
setEnableRefresh(true)
}
activity.delayDismissLoading()
finishRefresh()
val json = it.toJsonString()
val recordBean: FoodRecordBean? = json.toObject<FoodRecordBean>()
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<FragmentDishListBinding>() {
}
}
@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<FoodRecordBean>()
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()
}
}
}
@@ -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() {
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/dish_green"/>
</shape>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#ff0000"/>
</shape>
@@ -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">
<FrameLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
@@ -117,14 +118,21 @@
android:textSize="28sp" />
<TextView
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="15dp"
android:gravity="end"
android:text="@string/seasoning_setting2"
android:textColor="@color/gray_b4"
android:textSize="28sp" />
</FrameLayout>
<View
android:id="@+id/viewPoint"
android:layout_width="5dp"
android:layout_height="5dp"
android:layout_gravity="center_vertical"
android:background="@drawable/bg_circle_green"/>
</LinearLayout>
<include
android:id="@+id/include"
@@ -53,7 +53,7 @@
android:layout_marginEnd="15dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:background="@drawable/shape_green_5_corners"
android:background="@drawable/ripple_effect_green"
android:textColor="@color/white_f6"
android:textSize="30sp"
tools:ignore="HardcodedText" />