调整了部分问题
This commit is contained in:
@@ -5,24 +5,34 @@ import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.WindowInsetsController
|
||||
import android.view.WindowManager
|
||||
import android.widget.TextView
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.sw.inbound.utils.DateTimeUtils
|
||||
import com.sw.plate.utils.ScanGunKeyEventHelper
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
import com.sw.plate.utils.comn.SerialApi
|
||||
import com.sw.plate.utils.comn.SerialPortManager
|
||||
import com.sw.platecabinet.R
|
||||
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
||||
import com.sw.platecabinet.ext.setClickListeners
|
||||
import com.sw.platecabinet.utils.PermissionHelper
|
||||
import com.sw.platecabinet.view.CustomDialog
|
||||
import com.sw.platecabinet.viewmodel.SettingViewModel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* activity 基类
|
||||
@@ -34,6 +44,8 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
private var timeJob: Job? = null
|
||||
private var mDialogWaiting: CustomDialog? = null
|
||||
private val permissionHelpers = mutableMapOf<Int, PermissionHelper>()
|
||||
protected var keyEventHelper: ScanGunKeyEventHelper? = null
|
||||
private val viewModel by viewModels<SettingViewModel>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -49,6 +61,38 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
updateTime()
|
||||
registerDataChange()
|
||||
initialize()
|
||||
registerKeyEvent()
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听扫描枪扫描事件
|
||||
*/
|
||||
protected fun registerKeyEvent() {
|
||||
keyEventHelper =
|
||||
ScanGunKeyEventHelper(context, object : ScanGunKeyEventHelper.OnScanSuccessListener {
|
||||
override fun onScanSuccess(barcode: String?) {
|
||||
Timber.d("onScanSuccess barcode = $barcode")
|
||||
if (barcode == null) return
|
||||
handleScanKeyInfo(barcode)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理扫描枪数据
|
||||
*/
|
||||
protected open fun handleScanKeyInfo(scanInfo: String) {
|
||||
viewModel.findByPlateNumber(plateNumber = scanInfo)
|
||||
}
|
||||
|
||||
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
||||
if (keyEventHelper != null) {
|
||||
if (keyEventHelper!!.isScanGunEvent(event)) {
|
||||
keyEventHelper!!.analysisKeyEvent(event)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
|
||||
fun updateTime() {
|
||||
@@ -74,10 +118,16 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 左侧日期双击
|
||||
*/
|
||||
open fun onLeftDoubleClick() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 右侧时间双击
|
||||
*/
|
||||
open fun onRightDoubleClick() {
|
||||
MainActivity.start(context, pageType = PageType.SETTING_LIST)
|
||||
}
|
||||
@@ -139,6 +189,7 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||
}
|
||||
|
||||
|
||||
private fun enforceImmersiveMode() {
|
||||
// 持续强制隐藏系统栏(防止手势触发)
|
||||
window.decorView.postDelayed({
|
||||
@@ -177,10 +228,62 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
|
||||
protected abstract fun initialize()
|
||||
|
||||
protected open fun registerDataChange() {}
|
||||
/**
|
||||
* 注册数据监听
|
||||
*/
|
||||
protected open fun registerDataChange() {
|
||||
lifecycleScope.launch {
|
||||
viewModel.showLoading.collect {
|
||||
if (it) {
|
||||
showWaitingDialog("")
|
||||
} else {
|
||||
hideWaitingDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
lifecycleScope.launch {
|
||||
viewModel.currentUserInfo.drop(1).collect {
|
||||
if (it == null) return@collect
|
||||
if (it.equipmentBoxCode?.isNotEmpty() == true) {
|
||||
SerialApi.openPlate(
|
||||
it.equipmentBoxCode.toInt(),
|
||||
object : SerialPortManager.SendCallback {
|
||||
override fun onSuccess() {
|
||||
MainActivity.start(context, pageType = PageType.PLATE_OPEN)
|
||||
}
|
||||
|
||||
override fun onFail(e: Exception?) {
|
||||
ToastUtils.showToast("柜门打开失败")
|
||||
}
|
||||
})
|
||||
} else {
|
||||
viewModel.getEquipmentList()
|
||||
}
|
||||
}
|
||||
}
|
||||
lifecycleScope.launch {
|
||||
viewModel.equipmentList.drop(1).collect {
|
||||
if (it.isEmpty()) return@collect
|
||||
val unbindList = it.filter { !it.isBound() }
|
||||
if (unbindList.isEmpty()) {
|
||||
MainActivity.start(context = context, pageType = PageType.PLATE_CABINET_FULL)
|
||||
} else {
|
||||
val firstInfo = unbindList[0]
|
||||
val currentUserInfo = viewModel.currentUserInfo.value
|
||||
firstInfo.plateNumber = currentUserInfo?.plateNumber ?: ""
|
||||
MainActivity.start(
|
||||
context = context,
|
||||
pageType = PageType.BIND_PLATE,
|
||||
equipmentUserInfo = firstInfo
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
timeJob?.cancel()
|
||||
keyEventHelper?.onDestroy()
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user