feat(app): 重构应用为发盘机app,界面布局优化、移除无用代码
- 将应用名称从 SmartPlateCabinet 更改为 SmartTakePlate - 更新初始化页面背景图片为 bg_collect_page3 - 替换 View 组件为 Space 组件以优化布局权重分配 - 调整取盘按钮尺寸和文字大小提升用户体验 - 简化人脸识别登录页面布局结构 - 更新应用图标资源为 logo_launcher - 移除未使用的权限声明和活动注册 - 优化人脸识别相关 API 接口调用 - 调整时间显示逻辑仅保留时间部分 - 移除扫描枪事件监听相关功能代码 - 重构人脸识别数据更新逻辑 - 移除余额不足对话框相关代码
This commit is contained in:
@@ -1,41 +1,34 @@
|
||||
package com.sw.platecabinet.activity
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
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.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.google.gson.Gson
|
||||
import com.sw.inbound.utils.DateTimeUtils
|
||||
import com.sw.plate.App
|
||||
import com.sw.plate.utils.Base64
|
||||
import com.sw.plate.utils.ScanGunKeyEventHelper
|
||||
import com.sw.plate.utils.arcface.facedb.FaceDatabase
|
||||
import com.sw.plate.utils.arcface.facedb.entity.FaceEntity
|
||||
import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel
|
||||
import com.sw.platecabinet.MyApp
|
||||
import com.sw.platecabinet.R
|
||||
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
||||
import com.sw.platecabinet.ext.clickWithCoroutines
|
||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||
import com.sw.platecabinet.model.response.UserFaceModel
|
||||
import com.sw.platecabinet.utils.IntervalExecutor
|
||||
import com.sw.platecabinet.utils.PermissionHelper
|
||||
import com.sw.platecabinet.utils.PlateUtils
|
||||
import com.sw.platecabinet.utils.SpTool
|
||||
import com.sw.platecabinet.view.CustomLoadingDialog
|
||||
import com.sw.platecabinet.viewmodel.SettingViewModel
|
||||
import com.sw.platecabinet.viewmodel.UserViewModel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -52,15 +45,14 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
protected lateinit var context: Context
|
||||
private var timeJob: Job? = null
|
||||
private var mDialogWaiting: CustomLoadingDialog? = null
|
||||
private val permissionHelpers = mutableMapOf<Int, PermissionHelper>()
|
||||
protected var keyEventHelper: ScanGunKeyEventHelper? = null
|
||||
|
||||
// 管理员对应的viewmodel
|
||||
val settingViewModel by viewModels<SettingViewModel>()
|
||||
// private val permissionHelpers = mutableMapOf<Int, PermissionHelper>()
|
||||
// protected var keyEventHelper: ScanGunKeyEventHelper? = null
|
||||
|
||||
// 用户对应的viewModel
|
||||
protected val userViewModel by viewModels<UserViewModel>()
|
||||
|
||||
public val recognizeViewModel by viewModels<RecognizeViewModel>()
|
||||
|
||||
private var startTime: Long = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -81,62 +73,62 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
updateTime()
|
||||
registerDataChange()
|
||||
initialize()
|
||||
registerKeyEvent()
|
||||
// registerKeyEvent()
|
||||
val durationTime = System.currentTimeMillis() - startTime
|
||||
Timber.d("启动时间:$durationTime")
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听扫描枪扫描事件
|
||||
*/
|
||||
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 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) {
|
||||
// settingViewModel.findByPlateNumber(plateNumber = scanInfo)
|
||||
var plateNumber = scanInfo
|
||||
if (scanInfo.length > 6) {
|
||||
plateNumber = scanInfo.take(6)
|
||||
}
|
||||
Log.d("TAG", "handleScanKeyInfo: " + Gson().toJson(MyApp.plateList))
|
||||
if (MyApp.plateList == null) {
|
||||
initPlateList()
|
||||
}
|
||||
//柜子未关联该餐盘,直接找空位置放入盘子
|
||||
val item = MyApp.plateList?.firstOrNull { it.plateNumber.isNullOrBlank() }
|
||||
if (item == null) {
|
||||
//柜子已满
|
||||
MainActivity.start(context = context, pageType = PageType.PLATE_CABINET_FULL)
|
||||
return
|
||||
}
|
||||
//找到位置,放入餐盘,清除已有id和时间
|
||||
item.plateNumber = plateNumber
|
||||
item.faceId = null
|
||||
item.updateTime = null
|
||||
PlateUtils.open(this, item.equipmentBoxCode, true)
|
||||
SpTool.savePlateData(MyApp.plateList!!)
|
||||
//// settingViewModel.findByPlateNumber(plateNumber = scanInfo)
|
||||
// var plateNumber = scanInfo
|
||||
// if (scanInfo.length > 6) {
|
||||
// plateNumber = scanInfo.take(6)
|
||||
// }
|
||||
// Log.d("TAG", "handleScanKeyInfo: " + Gson().toJson(MyApp.plateList))
|
||||
// if (MyApp.plateList == null) {
|
||||
// initPlateList()
|
||||
// }
|
||||
// //柜子未关联该餐盘,直接找空位置放入盘子
|
||||
// val item = MyApp.plateList?.firstOrNull { it.plateNumber.isNullOrBlank() }
|
||||
// if (item == null) {
|
||||
// //柜子已满
|
||||
// MainActivity.start(context = context, pageType = PageType.PLATE_CABINET_FULL)
|
||||
// return
|
||||
// }
|
||||
// //找到位置,放入餐盘,清除已有id和时间
|
||||
// item.plateNumber = plateNumber
|
||||
// item.faceId = null
|
||||
// item.updateTime = null
|
||||
// PlateUtils.open(this, item.equipmentBoxCode, true)
|
||||
// SpTool.savePlateData(MyApp.plateList!!)
|
||||
}
|
||||
|
||||
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
||||
if (keyEventHelper != null) {
|
||||
if (keyEventHelper!!.isScanGunEvent(event)) {
|
||||
keyEventHelper!!.analysisKeyEvent(event)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
// override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
||||
// if (keyEventHelper != null) {
|
||||
// if (keyEventHelper!!.isScanGunEvent(event)) {
|
||||
// keyEventHelper!!.analysisKeyEvent(event)
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// return super.dispatchKeyEvent(event)
|
||||
// }
|
||||
|
||||
fun updateTime() {
|
||||
headerBinding?.let {
|
||||
@@ -153,9 +145,8 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
val scope = CoroutineScope(Dispatchers.Main)
|
||||
timeJob = scope.launch {
|
||||
DateTimeUtils.realTimeChineseDateFlow()
|
||||
.collect { (date, time) ->
|
||||
it.tvLeftDate.text = date
|
||||
it.tvRightTime.text = time
|
||||
.collect { date ->
|
||||
it.tvRightTime.text = date
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,36 +163,36 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
* 右侧时间双击
|
||||
*/
|
||||
open fun onRightDoubleClick() {
|
||||
MainActivity.start(context, pageType = PageType.SETTING_LIST)
|
||||
//MainActivity.start(context, pageType = PageType.SETTING_LIST)
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
permissions: Array<out String>,
|
||||
grantResults: IntArray
|
||||
) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
|
||||
val helper = permissionHelpers[requestCode]
|
||||
val allGranted = PermissionHelper.handlePermissionResult(
|
||||
this,
|
||||
requestCode,
|
||||
permissions,
|
||||
grantResults,
|
||||
permissionHelper = helper
|
||||
)
|
||||
|
||||
if (allGranted) {
|
||||
permissionHelpers.remove(requestCode)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册PermissionHelper以便处理结果
|
||||
*/
|
||||
fun registerPermissionHelper(helper: PermissionHelper) {
|
||||
permissionHelpers[helper.requestCode] = helper
|
||||
}
|
||||
// override fun onRequestPermissionsResult(
|
||||
// requestCode: Int,
|
||||
// permissions: Array<out String>,
|
||||
// grantResults: IntArray
|
||||
// ) {
|
||||
// super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
//
|
||||
// val helper = permissionHelpers[requestCode]
|
||||
// val allGranted = PermissionHelper.handlePermissionResult(
|
||||
// this,
|
||||
// requestCode,
|
||||
// permissions,
|
||||
// grantResults,
|
||||
// permissionHelper = helper
|
||||
// )
|
||||
//
|
||||
// if (allGranted) {
|
||||
// permissionHelpers.remove(requestCode)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 注册PermissionHelper以便处理结果
|
||||
// */
|
||||
// fun registerPermissionHelper(helper: PermissionHelper) {
|
||||
// permissionHelpers[helper.requestCode] = helper
|
||||
// }
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
@@ -290,125 +281,12 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
*/
|
||||
protected open fun registerDataChange() {
|
||||
Timber.d("registerDataChange")
|
||||
// lifecycleScope.launch {
|
||||
// viewModel.showLoading.collect {
|
||||
// Timber.d("registerDataChange 用户 showLoading = $it")
|
||||
// if (it) {
|
||||
// showWaitingDialog("")
|
||||
// } else {
|
||||
// hideWaitingDialog()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// lifecycleScope.launch {
|
||||
// viewModel.currentUserInfo.collect {
|
||||
// if (it == null) return@collect
|
||||
//// it.showBalanceNotEnoughDialog = true
|
||||
// handleLoginSuccess(it, false)
|
||||
// }
|
||||
// }
|
||||
// lifecycleScope.launch {
|
||||
// settingViewModel.showLoading.collect {
|
||||
// Timber.d("registerDataChange 管理员 showLoading = $it")
|
||||
// if (it) {
|
||||
// showWaitingDialog("")
|
||||
// } else {
|
||||
// hideWaitingDialog()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// lifecycleScope.launch {
|
||||
// settingViewModel.searchUserInfo.collect {
|
||||
// Timber.d("registerDataChange 管理员 currentUserInfo = $it")
|
||||
// if (it == null) return@collect
|
||||
// handleLoginSuccess(it, true)
|
||||
// }
|
||||
// }
|
||||
// lifecycleScope.launch {
|
||||
// settingViewModel.equipmentList.collect {
|
||||
// loadEquipmentList(it)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// private fun loadEquipmentList(items: List<EquipmentUserInfo>) {
|
||||
// if (items.isEmpty()) return
|
||||
// val unbindList = items.filter { !it.isBound() }
|
||||
// if (unbindList.isEmpty()) {
|
||||
// MainActivity.start(context = context, pageType = PageType.PLATE_CABINET_FULL)
|
||||
// } else {
|
||||
// val firstInfo = unbindList[0]
|
||||
// val currentUserInfo = settingViewModel.searchUserInfo.value
|
||||
// firstInfo.plateNumber = currentUserInfo?.plateNumber ?: ""
|
||||
// MainActivity.start(
|
||||
// context = context,
|
||||
// pageType = PageType.BIND_PLATE,
|
||||
// equipmentUserInfo = firstInfo
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 处理登录成功操作
|
||||
* @param isAdmin true 管理员 执行绑盘此操作 false 用户,提示错误
|
||||
*/
|
||||
open fun handleLoginSuccess(equipmentUserInfo: EquipmentUserInfo, isAdmin: Boolean) {
|
||||
// Timber.d("handleLoginSuccess isAdmin = $isAdmin")
|
||||
// equipmentUserInfo.isIntercept = false
|
||||
// val cardBalance = equipmentUserInfo.cardBalance ?: 0.toDouble()
|
||||
// val balanceIsNotEnough = cardBalance <= 0.toDouble()
|
||||
// if (balanceIsNotEnough && equipmentUserInfo.showBalanceNotEnoughDialog) {
|
||||
// //提示余额不足弹窗
|
||||
// equipmentUserInfo.isIntercept = true
|
||||
// BalanceNotEnoughDialog(this).show()
|
||||
// return
|
||||
// }
|
||||
// viewModel.resetUserInfo()
|
||||
//// if (equipmentUserInfo.isOtherEquipment()) {
|
||||
//// MainActivity.start(
|
||||
//// context,
|
||||
//// pageType = PageType.PLATE_TIP,
|
||||
//// equipmentUserInfo = equipmentUserInfo,
|
||||
//// isAdmin
|
||||
//// )
|
||||
//// return
|
||||
//// }
|
||||
// if (equipmentUserInfo.equipmentBoxCode?.isNotEmpty() == true) {
|
||||
// SerialApi.openPlate(
|
||||
// equipmentUserInfo.equipmentBoxCode!!.toInt(),
|
||||
// object : SerialPortManager.SendCallback {
|
||||
// override fun onSuccess() {
|
||||
// MainActivity.start(
|
||||
// context,
|
||||
// pageType = PageType.PLATE_TIP,
|
||||
// isAdmin = isAdmin
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// override fun onFail(e: Exception?) {
|
||||
// ToastUtils.showToast("柜门打开失败")
|
||||
// }
|
||||
// })
|
||||
// } else {
|
||||
// if (isAdmin) {
|
||||
// settingViewModel.getEquipmentList {
|
||||
// loadEquipmentList(it)
|
||||
// }
|
||||
// } else {
|
||||
// Timber.d("无餐盘信息")
|
||||
// MainActivity.start(
|
||||
// context,
|
||||
// pageType = PageType.PLATE_TIP,
|
||||
// equipmentUserInfo = equipmentUserInfo,
|
||||
// isAdmin = isAdmin
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
timeJob?.cancel()
|
||||
keyEventHelper?.onDestroy()
|
||||
// keyEventHelper?.onDestroy()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
@@ -430,35 +308,19 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
private var faceTimestamp = 0L
|
||||
|
||||
//private var taskPageNo = 1
|
||||
private fun getFaceIncrementList(pageNo: Int = 1, action:(List<String?>)-> Unit) {
|
||||
private fun getFaceIncrementList(pageNo: Int = 1, action: (List<String?>) -> Unit) {
|
||||
val timestamp = SpTool.lastFaceTimestamp
|
||||
// if (timestamp == 0L) {
|
||||
// return
|
||||
// }
|
||||
settingViewModel.getFaceIncrementList(
|
||||
userViewModel.getFaceIncrementList(
|
||||
pageNo = pageNo,
|
||||
timestamp = timestamp
|
||||
) { list ->
|
||||
runOnUiThread {
|
||||
if (pageNo == 1 && list.isEmpty()) {
|
||||
//未查询到增量数据
|
||||
// Thread{
|
||||
// val faceDao = FaceDatabase.getInstance(this).faceDao()
|
||||
// if (faceDao.getFaceCount() == 0) {
|
||||
// FaceEntity("-1", null, byteArrayOf(-1)).also { it.userType = "-1" }
|
||||
// }
|
||||
// }.start()
|
||||
return@runOnUiThread
|
||||
}
|
||||
updateFaceData(list)
|
||||
val userIdList = list.map { it.userId }
|
||||
action(userIdList)
|
||||
//if (list.size >= settingViewModel.PAGE_SIZE) {
|
||||
// faceTimestamp = list.last().faceUpdateTimestamp ?: 0
|
||||
// taskPageNo++
|
||||
// getFaceIncrementList(taskPageNo)
|
||||
// return@runOnUiThread
|
||||
//}
|
||||
if (list.isNotEmpty()) {
|
||||
faceTimestamp = list.last().faceUpdateTimestamp ?: 0
|
||||
}
|
||||
@@ -467,7 +329,6 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
public val recognizeViewModel by viewModels<RecognizeViewModel>()
|
||||
private fun updateFaceData(list: List<UserFaceModel>) {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val faceList = mutableListOf<FaceEntity>()
|
||||
@@ -477,13 +338,11 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
if (model.faceDeleted == true) {
|
||||
//删除数据
|
||||
faceDao.deleteFaceById(model.userId)
|
||||
// if (faceDao.getFaceCount() == 0) {
|
||||
// FaceEntity("-1", null, byteArrayOf(-1)).also { it.userType = "-1" }
|
||||
// }
|
||||
} else {
|
||||
// 获取该用户所有已存特征,判断当前特征是否已存在
|
||||
val existList = faceDao.queryAllByUserName(model.userId)
|
||||
val featureMatches = existList.map { Base64.encode(it.featureData) == model.faceFeatureStr }
|
||||
val featureMatches =
|
||||
existList.map { Base64.encode(it.featureData) == model.faceFeatureStr }
|
||||
Timber.d("userId=${model.userId}, 已存记录数=${existList.size}, 各条特征是否与服务器一致=$featureMatches")
|
||||
val alreadyExists = featureMatches.any { it }
|
||||
if (!alreadyExists) {
|
||||
@@ -506,7 +365,7 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getNewFaceEntity(model: UserFaceModel) : FaceEntity {
|
||||
private fun getNewFaceEntity(model: UserFaceModel): FaceEntity {
|
||||
return FaceEntity(
|
||||
model.userId,
|
||||
null,
|
||||
@@ -518,29 +377,41 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
fun initPlateList() {
|
||||
// SpTool.putString(SpTool.PLATE_BOX_DATA, "")
|
||||
// var list = SpTool.getPlateData()
|
||||
val list: MutableList<EquipmentUserInfo> = mutableListOf()
|
||||
repeat(22) { index ->
|
||||
list.add(
|
||||
EquipmentUserInfo(equipmentBoxCode = "${index + 1}")
|
||||
)
|
||||
}
|
||||
MyApp.plateList = list
|
||||
}
|
||||
|
||||
fun clearAllFace(block: () -> Unit) {
|
||||
Thread {
|
||||
val faceDao = FaceDatabase.getInstance(App.getContext()).faceDao()
|
||||
faceDao.deleteAll()
|
||||
faceDao.resetId()
|
||||
// faceDao.insert(
|
||||
// FaceEntity("-1", null, byteArrayOf(-1)).also { it.userType = "-1" }
|
||||
// )
|
||||
recognizeViewModel.refreshFaceList()
|
||||
runOnUiThread { block() }
|
||||
}.start()
|
||||
}
|
||||
|
||||
private var permissionCallback: ((isGranted: Boolean) -> Unit)? = null
|
||||
private var activityCallback: ((intent: Intent?) -> Unit)? = null
|
||||
|
||||
fun requestPermission(permission: String, callback: (isGranted: Boolean) -> Unit) {
|
||||
this.permissionCallback = callback
|
||||
requestPermissionLauncher.launch(permission)
|
||||
}
|
||||
|
||||
// 权限请求回调
|
||||
val requestPermissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { isGranted ->
|
||||
permissionCallback?.invoke(isGranted)
|
||||
}
|
||||
|
||||
fun startActivity(intent: Intent, callback: (Intent?) -> Unit) {
|
||||
this.activityCallback = callback
|
||||
startActivityLauncher.launch(intent)
|
||||
}
|
||||
|
||||
// activity页面返回的回调
|
||||
private val startActivityLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) {
|
||||
activityCallback?.invoke(it.data)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user