设备联调优化
This commit is contained in:
@@ -9,7 +9,10 @@ import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
@@ -23,21 +26,27 @@ import com.shuwei.intelligent.shelves.base.BaseActivity
|
||||
import com.shuwei.intelligent.shelves.databinding.ActivityShelfBinding
|
||||
import com.shuwei.intelligent.shelves.model.GoodsModel
|
||||
import com.shuwei.intelligent.shelves.model.GoodsRecord
|
||||
import com.shuwei.intelligent.shelves.model.SendWeightEvent
|
||||
import com.shuwei.intelligent.shelves.model.ShelfModel
|
||||
import com.shuwei.intelligent.shelves.net.Loading
|
||||
import com.shuwei.intelligent.shelves.net.NetViewModel
|
||||
import com.shuwei.intelligent.shelves.net.RespData
|
||||
import com.shuwei.intelligent.shelves.net.UiState
|
||||
import com.shuwei.intelligent.shelves.serial.SerialPortManager
|
||||
import com.shuwei.intelligent.shelves.task.TaskManager
|
||||
import com.shuwei.intelligent.shelves.utils.DateTimeUtil
|
||||
import com.shuwei.intelligent.shelves.utils.KeyboardUtil
|
||||
import com.shuwei.intelligent.shelves.utils.ext.addOnActionSearchListener
|
||||
import com.shuwei.intelligent.shelves.utils.ext.clickWithDebounce
|
||||
import com.shuwei.intelligent.shelves.utils.ext.dp
|
||||
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 org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
@@ -55,6 +64,7 @@ class ShelfActivity : BaseActivity() {
|
||||
const val SHELF_INDEX = "shelfIndex"
|
||||
|
||||
const val PAGE_SIZE = 100
|
||||
|
||||
}
|
||||
|
||||
private lateinit var binding: ActivityShelfBinding
|
||||
@@ -65,7 +75,6 @@ class ShelfActivity : BaseActivity() {
|
||||
|
||||
private var realWeight: Int = 0
|
||||
private var pageNo: Int = 1
|
||||
private var shelfIndex: Int = 0
|
||||
|
||||
private val viewModel: NetViewModel by viewModels()
|
||||
|
||||
@@ -76,13 +85,15 @@ class ShelfActivity : BaseActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityShelfBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
EventBus.getDefault().register(this)
|
||||
// tvFoodWeight =binding.tvFoodWeight
|
||||
shelfModel = intent.getSerializableExtra(SHELF_MODEL) as ShelfModel?
|
||||
|
||||
shelfModel?.let {
|
||||
binding.tvShelfName.text = it.shelfName
|
||||
binding.tvFoodName.text = if (it.goodsName.isNullOrBlank()) "-" else it.goodsName
|
||||
realWeight = ((it.weight ?: 0.0) * 1000).toInt()
|
||||
// realWeight = (HomeActivity.getRealWeight() * 1000).toInt()
|
||||
binding.tvFoodWeight.text = "${realWeight}克"
|
||||
}
|
||||
|
||||
@@ -137,9 +148,11 @@ class ShelfActivity : BaseActivity() {
|
||||
SerialPortManager.send(zeroClearingCmd)
|
||||
//清零
|
||||
realWeight = 0
|
||||
binding.tvFoodWeight.text = "${realWeight}克"
|
||||
// binding.tvFoodWeight.text = "${realWeight}克"
|
||||
|
||||
SerialPortManager.send(DEVICE_INFO_CMD)
|
||||
Loading.show(this@ShelfActivity)
|
||||
v.postDelayed({Loading.dismiss()}, 5000)
|
||||
}
|
||||
KeyboardUtil.hideKeyboard(v.context, v)
|
||||
}
|
||||
@@ -159,7 +172,7 @@ class ShelfActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
registerReceiver(receiver, IntentFilter(RECEIVER_DEVICE_INFO + shelfModel?.deviceNo))
|
||||
// registerReceiver(receiver, IntentFilter(RECEIVER_DEVICE_INFO + shelfModel?.deviceNo))
|
||||
|
||||
binding.refreshLayout.let {
|
||||
it.setEnableRefresh(true)
|
||||
@@ -171,6 +184,8 @@ class ShelfActivity : BaseActivity() {
|
||||
it.setOnLoadMoreListener { getGoodsList() }
|
||||
}
|
||||
getGoodsList()
|
||||
|
||||
TaskManager.startDeviceTask()
|
||||
}
|
||||
|
||||
private fun finishRefresh() {
|
||||
@@ -239,20 +254,23 @@ class ShelfActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private val receiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
intent?.let {
|
||||
// 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}克"
|
||||
}
|
||||
}
|
||||
}
|
||||
// private val receiver = object : BroadcastReceiver() {
|
||||
// override fun onReceive(context: Context?, intent: Intent?) {
|
||||
// intent?.let {
|
||||
// if (it.action == RECEIVER_DEVICE_INFO + shelfModel?.deviceNo) {
|
||||
// val weight = it.getDoubleExtra(SHELF_WEIGHT, 0.0)
|
||||
// Log.d(TAG, "getDeviceInfo:onReceive: weight=$weight")
|
||||
// realWeight = (weight * 1000).toInt()
|
||||
// binding.tvFoodWeight.text = "${realWeight}克"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
override fun onDestroy() {
|
||||
unregisterReceiver(receiver)
|
||||
// unregisterReceiver(receiver)
|
||||
EventBus.getDefault().unregister(this)
|
||||
TaskManager.cancelDeviceTask()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
@@ -315,6 +333,9 @@ class ShelfActivity : BaseActivity() {
|
||||
getGoodsList()
|
||||
}
|
||||
it.ivEmptyIcon.setImageResource(R.drawable.ic_empty_gray)
|
||||
it.ivEmptyIcon.updateLayoutParams<LinearLayout.LayoutParams> {
|
||||
width = 200.dp
|
||||
}
|
||||
}
|
||||
binding.refreshLayout.run {
|
||||
setEnableRefresh(false)
|
||||
@@ -322,4 +343,11 @@ class ShelfActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public fun receiveWeightEvent(event: SendWeightEvent) {
|
||||
if (event.shelfNo == (shelfModel?.deviceNo?:0)) {
|
||||
binding.tvFoodWeight.text = "${event.weight}克"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user