调试通过获取设备信息实时更新二级页面重量,首页和二级页面列表页增加空数据展示
This commit is contained in:
@@ -10,6 +10,7 @@ import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
@@ -30,11 +31,12 @@ import com.shuwei.intelligent.shelves.net.UiState
|
||||
import com.shuwei.intelligent.shelves.serial.SerialPortManager
|
||||
import com.shuwei.intelligent.shelves.utils.DateTimeUtil
|
||||
import com.shuwei.intelligent.shelves.utils.KeyboardUtil
|
||||
import com.shuwei.intelligent.shelves.utils.UIUtils
|
||||
import com.shuwei.intelligent.shelves.utils.ext.addOnActionSearchListener
|
||||
import com.shuwei.intelligent.shelves.utils.ext.clickWithDebounce
|
||||
import com.shuwei.intelligent.shelves.utils.ext.gone
|
||||
import com.shuwei.intelligent.shelves.utils.ext.toJsonString
|
||||
import com.shuwei.intelligent.shelves.utils.ext.toast
|
||||
import com.shuwei.intelligent.shelves.utils.ext.visible
|
||||
import kotlinx.coroutines.launch
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
@@ -45,11 +47,14 @@ class ShelfActivity : BaseActivity() {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "ShelfActivity"
|
||||
|
||||
private const val YYYY_MM_DD__EEEE_HH_MM_SS = "yyyy年MM月dd日 EEEE***HH:mm:ss"
|
||||
const val SHELF_MODEL = "shelfModel"
|
||||
const val RECEIVER_DEVICE_INFO = "receiverDeviceInfo"
|
||||
const val SHELF_WEIGHT = "shelfWeight"
|
||||
const val SHELF_INDEX = "shelfIndex"
|
||||
|
||||
const val PAGE_SIZE = 50
|
||||
const val PAGE_SIZE = 100
|
||||
}
|
||||
|
||||
private lateinit var binding: ActivityShelfBinding
|
||||
@@ -60,6 +65,7 @@ class ShelfActivity : BaseActivity() {
|
||||
|
||||
private var realWeight: Int = 0
|
||||
private var pageNo: Int = 1
|
||||
private var shelfIndex: Int = 0
|
||||
|
||||
private val viewModel: NetViewModel by viewModels()
|
||||
|
||||
@@ -81,19 +87,23 @@ class ShelfActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
initRecyclerView()
|
||||
// initWeight()
|
||||
|
||||
binding.etInputFood.run {
|
||||
addOnActionSearchListener {
|
||||
if (text.isNullOrBlank()) {
|
||||
toast(hint.toString())
|
||||
return@addOnActionSearchListener
|
||||
}
|
||||
// loadSearchData()
|
||||
viewModel.getGoodsList(
|
||||
canteenId = "1599670511042785282", goodsName = text.toString().trim()
|
||||
)
|
||||
pageNo = 1
|
||||
getGoodsList()
|
||||
KeyboardUtil.hideKeyboard(context, this)
|
||||
}
|
||||
addTextChangedListener(afterTextChanged = {editable ->
|
||||
if (editable.isNullOrBlank()) {
|
||||
pageNo = 1
|
||||
getGoodsList()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
binding.btnConfirm.clickWithDebounce {
|
||||
@@ -103,7 +113,7 @@ class ShelfActivity : BaseActivity() {
|
||||
}
|
||||
val data = ShelfModel(
|
||||
shelfName = shelfModel?.shelfName,
|
||||
goodsId = list[clickIndex].goodsId?:"",
|
||||
goodsId = list[clickIndex].goodsId ?: "",
|
||||
goodsName = list[clickIndex].goodsName,
|
||||
weight = realWeight / 1000.0,
|
||||
createTime = DateTimeUtil.formatDateTime(dateTime = Date())
|
||||
@@ -128,6 +138,8 @@ class ShelfActivity : BaseActivity() {
|
||||
//清零
|
||||
realWeight = 0
|
||||
binding.tvFoodWeight.text = "${realWeight}克"
|
||||
|
||||
SerialPortManager.send(DEVICE_INFO_CMD)
|
||||
}
|
||||
KeyboardUtil.hideKeyboard(v.context, v)
|
||||
}
|
||||
@@ -147,7 +159,7 @@ class ShelfActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
registerReceiver(receiver, IntentFilter(RECEIVER_DEVICE_INFO))
|
||||
registerReceiver(receiver, IntentFilter(RECEIVER_DEVICE_INFO + shelfModel?.deviceNo))
|
||||
|
||||
binding.refreshLayout.let {
|
||||
it.setEnableRefresh(true)
|
||||
@@ -176,7 +188,10 @@ class ShelfActivity : BaseActivity() {
|
||||
|
||||
private fun getGoodsList() {
|
||||
viewModel.getGoodsList(
|
||||
canteenId = App.getInstance().canteenId, pageNo = pageNo, pageSize = PAGE_SIZE
|
||||
canteenId = App.getInstance().canteenId,
|
||||
goodsName = binding.etInputFood.text.trim().toString(),
|
||||
pageNo = pageNo,
|
||||
pageSize = PAGE_SIZE
|
||||
)
|
||||
}
|
||||
|
||||
@@ -186,15 +201,20 @@ class ShelfActivity : BaseActivity() {
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun updateUI(data: RespData<*>) {
|
||||
binding.include?.root?.gone()
|
||||
finishRefresh()
|
||||
Loading.dismiss()
|
||||
binding.root.postDelayed({ Loading.dismiss() }, 200)
|
||||
Log.d(TAG, "updateUI: ${data.toJsonString()}")
|
||||
if (data.result !is GoodsRecord) {
|
||||
UIUtils.toast("数据错误")
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
return
|
||||
}
|
||||
if (data.result.records.isNullOrEmpty()) {
|
||||
UIUtils.toast("数据错误")
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
return
|
||||
}
|
||||
if (pageNo == 1) {
|
||||
@@ -213,15 +233,18 @@ class ShelfActivity : BaseActivity() {
|
||||
private fun showError(message: String) {
|
||||
finishRefresh()
|
||||
Loading.dismiss()
|
||||
UIUtils.toast(message)
|
||||
toast(message)
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
private val receiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
intent?.let {
|
||||
val data = it.getStringExtra(RECEIVER_DEVICE_INFO)
|
||||
Log.d(TAG, "onReceive: $data")
|
||||
// val data = it.getStringExtra(RECEIVER_DEVICE_INFO)
|
||||
val weight = it.getDoubleExtra(SHELF_WEIGHT, 0.0)
|
||||
Log.d(TAG, "getDeviceInfo:onReceive: weight=$weight")
|
||||
realWeight = (weight * 1000).toInt()
|
||||
binding.tvFoodWeight.text = "${realWeight}克"
|
||||
}
|
||||
@@ -233,31 +256,6 @@ class ShelfActivity : BaseActivity() {
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
// private fun initWeight() {
|
||||
// realWeight = Random.nextInt(1, 5001)
|
||||
// }
|
||||
|
||||
// private fun loadSearchData() {
|
||||
// list.add(SearchModel(foodId = 1000, foodName = "菲律宾乳猪五花肉"))
|
||||
// list.add(SearchModel(foodId = 1001, foodName = "金针菇"))
|
||||
// list.add(SearchModel(foodId = 1002, foodName = "大菠菜"))
|
||||
// list.add(SearchModel(foodId = 1003, foodName = "清远麻鸡块"))
|
||||
// list.add(SearchModel(foodId = 1004, foodName = "普罗旺斯番茄"))
|
||||
// list.add(SearchModel(foodId = 1005, foodName = "长条茄子"))
|
||||
// list.add(SearchModel(foodId = 1006, foodName = "得莫利鱼"))
|
||||
// list.add(SearchModel(foodId = 1007, foodName = "土豆丝"))
|
||||
// list.add(SearchModel(foodId = 1008, foodName = "辣椒炒肉"))
|
||||
// list.add(SearchModel(foodId = 1009, foodName = "雪菜烧豆腐"))
|
||||
// list.add(SearchModel(foodId = 1010, foodName = "冬虫夏草炝拌芥兰苗"))
|
||||
// list.add(
|
||||
// SearchModel(
|
||||
// foodId = 1011,
|
||||
// foodName = "蘑菇玉米山药莲藕胡萝卜红枣莲子枸杞清炖排骨汤"
|
||||
// )
|
||||
// )
|
||||
// searchAdapter.notifyDataSetChanged()
|
||||
// }
|
||||
|
||||
private val list: MutableList<GoodsModel> = mutableListOf()
|
||||
private val searchAdapter by lazy {
|
||||
SearchAdapter(list).apply {
|
||||
@@ -279,8 +277,6 @@ class ShelfActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private val YYYY_MM_DD__EEEE_HH_MM_SS = "yyyy年MM月dd日 EEEE***HH:mm:ss"
|
||||
|
||||
private fun updateDateTime() {
|
||||
val sdf = SimpleDateFormat(YYYY_MM_DD__EEEE_HH_MM_SS, Locale.CHINA)
|
||||
val dateTime = sdf.format(Date())
|
||||
@@ -308,4 +304,22 @@ class ShelfActivity : BaseActivity() {
|
||||
handler.removeCallbacks(updateTask)
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun loadEmptyView() {
|
||||
list.clear()
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
binding.include?.let {
|
||||
it.root.visible()
|
||||
it.root.setOnClickListener {
|
||||
pageNo = 1
|
||||
getGoodsList()
|
||||
}
|
||||
it.ivEmptyIcon.setImageResource(R.drawable.ic_empty_gray)
|
||||
}
|
||||
binding.refreshLayout.run {
|
||||
setEnableRefresh(false)
|
||||
setEnableLoadMore(false)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user