接口联调2
This commit is contained in:
@@ -15,6 +15,7 @@ import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.chad.library.adapter4.util.setOnDebouncedItemClick
|
||||
import com.scwang.smart.refresh.layout.constant.RefreshState
|
||||
import com.shuwei.intelligent.shelves.HomeActivity.Companion.DEVICE_INFO_CMD
|
||||
import com.shuwei.intelligent.shelves.adapter.SearchAdapter
|
||||
import com.shuwei.intelligent.shelves.base.BaseActivity
|
||||
@@ -48,6 +49,7 @@ class ShelfActivity : BaseActivity() {
|
||||
const val RECEIVER_DEVICE_INFO = "receiverDeviceInfo"
|
||||
const val SHELF_WEIGHT = "shelfWeight"
|
||||
|
||||
const val PAGE_SIZE = 50
|
||||
}
|
||||
|
||||
private lateinit var binding: ActivityShelfBinding
|
||||
@@ -57,6 +59,7 @@ class ShelfActivity : BaseActivity() {
|
||||
private var clickIndex: Int = -1
|
||||
|
||||
private var realWeight: Int = 0
|
||||
private var pageNo: Int = 1
|
||||
|
||||
private val viewModel: NetViewModel by viewModels()
|
||||
|
||||
@@ -87,8 +90,7 @@ class ShelfActivity : BaseActivity() {
|
||||
}
|
||||
// loadSearchData()
|
||||
viewModel.getGoodsList(
|
||||
canteenId = "1599670511042785282",
|
||||
goodsName = text.toString().trim()
|
||||
canteenId = "1599670511042785282", goodsName = text.toString().trim()
|
||||
)
|
||||
KeyboardUtil.hideKeyboard(context, this)
|
||||
}
|
||||
@@ -119,8 +121,7 @@ class ShelfActivity : BaseActivity() {
|
||||
val shelfNo = shelfModel?.deviceNo ?: 0
|
||||
val hex = shelfNo.toString(16).padStart(2, '0').uppercase()
|
||||
Log.d(TAG, "onCreate: hex=$hex")
|
||||
val zeroClearingCmd =
|
||||
"${HomeActivity.HEADER}0401${hex}${HomeActivity.FOOTER}"
|
||||
val zeroClearingCmd = "${HomeActivity.HEADER}0401${hex}${HomeActivity.FOOTER}"
|
||||
Log.d(TAG, "onCreate: zeroClearingCmd=$zeroClearingCmd")
|
||||
SerialPortManager.send(zeroClearingCmd)
|
||||
}
|
||||
@@ -144,9 +145,32 @@ class ShelfActivity : BaseActivity() {
|
||||
|
||||
registerReceiver(receiver, IntentFilter(RECEIVER_DEVICE_INFO))
|
||||
|
||||
binding.refreshLayout.let {
|
||||
it.setEnableRefresh(true)
|
||||
it.setEnableLoadMore(false)
|
||||
it.setOnRefreshListener {
|
||||
pageNo = 1
|
||||
getGoodsList()
|
||||
}
|
||||
it.setOnLoadMoreListener { getGoodsList() }
|
||||
}
|
||||
getGoodsList()
|
||||
}
|
||||
|
||||
private fun finishRefresh() {
|
||||
binding.refreshLayout.let {
|
||||
if (it.state == RefreshState.Refreshing) {
|
||||
it.finishRefresh(500)
|
||||
} else if (binding.refreshLayout.state == RefreshState.Loading) {
|
||||
it.finishLoadMore(500)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun getGoodsList() {
|
||||
viewModel.getGoodsList(
|
||||
canteenId = "1599670511042785282"
|
||||
canteenId = App.getInstance().canteenId, pageNo = pageNo, pageSize = PAGE_SIZE
|
||||
)
|
||||
}
|
||||
|
||||
@@ -156,6 +180,7 @@ class ShelfActivity : BaseActivity() {
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun updateUI(data: RespData<*>) {
|
||||
finishRefresh()
|
||||
Loading.dismiss()
|
||||
Log.d(TAG, "updateUI: ${data.toJsonString()}")
|
||||
if (data.result !is GoodsRecord) {
|
||||
@@ -166,12 +191,21 @@ class ShelfActivity : BaseActivity() {
|
||||
UIUtils.toast("数据错误")
|
||||
return
|
||||
}
|
||||
list.clear()
|
||||
list.addAll(data.result.records)
|
||||
if (pageNo == 1) {
|
||||
list.clear()
|
||||
}
|
||||
val records = data.result.records
|
||||
list.addAll(records)
|
||||
val enableLoadMore = records.size >= PAGE_SIZE
|
||||
binding.refreshLayout.setEnableLoadMore(enableLoadMore)
|
||||
if (enableLoadMore) {
|
||||
pageNo++
|
||||
}
|
||||
searchAdapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun showError(message: String) {
|
||||
finishRefresh()
|
||||
Loading.dismiss()
|
||||
UIUtils.toast(message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user