餐盘柜优化-绑定临时用户
This commit is contained in:
@@ -127,14 +127,14 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
item.plateNumber = plateNumber
|
item.plateNumber = plateNumber
|
||||||
item.faceId = null
|
item.faceId = null
|
||||||
item.updateTime = null
|
item.updateTime = null
|
||||||
PlateUtils.open(this, item.equipmentBoxCode)
|
PlateUtils.open(this, item.equipmentBoxCode, true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//放入餐盘,清除已有id和时间
|
//放入餐盘,清除已有id和时间
|
||||||
item.plateNumber = plateNumber
|
item.plateNumber = plateNumber
|
||||||
item.faceId = null
|
item.faceId = null
|
||||||
item.updateTime = null
|
item.updateTime = null
|
||||||
PlateUtils.open(this, item.equipmentBoxCode)
|
PlateUtils.open(this, item.equipmentBoxCode, true)
|
||||||
SpTool.savePlateData(MyApp.plateList!!)
|
SpTool.savePlateData(MyApp.plateList!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,23 +266,26 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
/**
|
/**
|
||||||
* 显示等待提示框
|
* 显示等待提示框
|
||||||
*/
|
*/
|
||||||
fun showWaitingDialog(tip: String?): Dialog? {
|
fun showWaitingDialog(tip: String?) {
|
||||||
|
runOnUiThread {
|
||||||
hideWaitingDialog()
|
hideWaitingDialog()
|
||||||
val view = View.inflate(this, R.layout.dialog_waiting, null)
|
val view = View.inflate(this, R.layout.dialog_waiting, null)
|
||||||
if (!TextUtils.isEmpty(tip)) (view.findViewById<View?>(R.id.tvTip) as TextView).setText(tip)
|
if (!TextUtils.isEmpty(tip)) (view.findViewById<View?>(R.id.tvTip) as TextView).setText(tip)
|
||||||
mDialogWaiting = CustomLoadingDialog(this, view, R.style.MyDialog)
|
mDialogWaiting = CustomLoadingDialog(this, view, R.style.MyDialog)
|
||||||
mDialogWaiting!!.show()
|
mDialogWaiting!!.show()
|
||||||
mDialogWaiting!!.setCancelable(true)
|
mDialogWaiting!!.setCancelable(true)
|
||||||
return mDialogWaiting
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 隐藏等待提示框
|
* 隐藏等待提示框
|
||||||
*/
|
*/
|
||||||
fun hideWaitingDialog() {
|
fun hideWaitingDialog() {
|
||||||
|
runOnUiThread {
|
||||||
mDialogWaiting?.dismiss()
|
mDialogWaiting?.dismiss()
|
||||||
mDialogWaiting = null
|
mDialogWaiting = null
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun inflateViewBinding(): VB
|
protected abstract fun inflateViewBinding(): VB
|
||||||
|
|
||||||
@@ -295,40 +298,40 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
*/
|
*/
|
||||||
protected open fun registerDataChange() {
|
protected open fun registerDataChange() {
|
||||||
Timber.d("registerDataChange")
|
Timber.d("registerDataChange")
|
||||||
lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
viewModel.showLoading.collect {
|
// viewModel.showLoading.collect {
|
||||||
Timber.d("registerDataChange 用户 showLoading = $it")
|
// Timber.d("registerDataChange 用户 showLoading = $it")
|
||||||
if (it) {
|
// if (it) {
|
||||||
showWaitingDialog("")
|
// showWaitingDialog("")
|
||||||
} else {
|
// } else {
|
||||||
hideWaitingDialog()
|
// hideWaitingDialog()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
viewModel.currentUserInfo.collect {
|
// viewModel.currentUserInfo.collect {
|
||||||
if (it == null) return@collect
|
// if (it == null) return@collect
|
||||||
// it.showBalanceNotEnoughDialog = true
|
//// it.showBalanceNotEnoughDialog = true
|
||||||
handleLoginSuccess(it, false)
|
// handleLoginSuccess(it, false)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
settingViewModel.showLoading.collect {
|
// settingViewModel.showLoading.collect {
|
||||||
Timber.d("registerDataChange 管理员 showLoading = $it")
|
// Timber.d("registerDataChange 管理员 showLoading = $it")
|
||||||
if (it) {
|
// if (it) {
|
||||||
showWaitingDialog("")
|
// showWaitingDialog("")
|
||||||
} else {
|
// } else {
|
||||||
hideWaitingDialog()
|
// hideWaitingDialog()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
settingViewModel.searchUserInfo.collect {
|
// settingViewModel.searchUserInfo.collect {
|
||||||
Timber.d("registerDataChange 管理员 currentUserInfo = $it")
|
// Timber.d("registerDataChange 管理员 currentUserInfo = $it")
|
||||||
if (it == null) return@collect
|
// if (it == null) return@collect
|
||||||
handleLoginSuccess(it, true)
|
// handleLoginSuccess(it, true)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
// lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
// settingViewModel.equipmentList.collect {
|
// settingViewModel.equipmentList.collect {
|
||||||
// loadEquipmentList(it)
|
// loadEquipmentList(it)
|
||||||
@@ -336,22 +339,22 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadEquipmentList(items: List<EquipmentUserInfo>) {
|
// private fun loadEquipmentList(items: List<EquipmentUserInfo>) {
|
||||||
if (items.isEmpty()) return
|
// if (items.isEmpty()) return
|
||||||
val unbindList = items.filter { !it.isBound() }
|
// val unbindList = items.filter { !it.isBound() }
|
||||||
if (unbindList.isEmpty()) {
|
// if (unbindList.isEmpty()) {
|
||||||
MainActivity.start(context = context, pageType = PageType.PLATE_CABINET_FULL)
|
// MainActivity.start(context = context, pageType = PageType.PLATE_CABINET_FULL)
|
||||||
} else {
|
// } else {
|
||||||
val firstInfo = unbindList[0]
|
// val firstInfo = unbindList[0]
|
||||||
val currentUserInfo = settingViewModel.searchUserInfo.value
|
// val currentUserInfo = settingViewModel.searchUserInfo.value
|
||||||
firstInfo.plateNumber = currentUserInfo?.plateNumber ?: ""
|
// firstInfo.plateNumber = currentUserInfo?.plateNumber ?: ""
|
||||||
MainActivity.start(
|
// MainActivity.start(
|
||||||
context = context,
|
// context = context,
|
||||||
pageType = PageType.BIND_PLATE,
|
// pageType = PageType.BIND_PLATE,
|
||||||
equipmentUserInfo = firstInfo
|
// equipmentUserInfo = firstInfo
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理登录成功操作
|
* 处理登录成功操作
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class InitActivity : BaseActivity<ActivityInitBinding>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
binding.main.setOnClickListener {
|
binding.takeButton.setOnClickListener {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
// binding.takeButton.setOnClickListener {
|
// binding.takeButton.setOnClickListener {
|
||||||
|
|||||||
@@ -63,13 +63,14 @@ import org.greenrobot.eventbus.Subscribe
|
|||||||
import org.greenrobot.eventbus.ThreadMode
|
import org.greenrobot.eventbus.ThreadMode
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import kotlin.math.log
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 人脸识别
|
* 人脸识别
|
||||||
*/
|
*/
|
||||||
class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||||
ViewTreeObserver.OnGlobalLayoutListener {
|
ViewTreeObserver.OnGlobalLayoutListener {
|
||||||
// private val recognizeViewModel by viewModels<RecognizeViewModel>()
|
// private val recognizeViewModel by viewModels<RecognizeViewModel>()
|
||||||
private var countDownTimer: CountDownTimer? = null
|
private var countDownTimer: CountDownTimer? = null
|
||||||
|
|
||||||
private val CAMERA_PERMISSION_REQUEST_CODE = 100
|
private val CAMERA_PERMISSION_REQUEST_CODE = 100
|
||||||
@@ -96,11 +97,11 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
instance = this
|
instance = this
|
||||||
viewModel.activeEngine()
|
viewModel.activeEngine()
|
||||||
addSocketListener()
|
addSocketListener()
|
||||||
|
|
||||||
initCountTime()
|
initCountTime()
|
||||||
initArcViewModel()
|
initArcViewModel()
|
||||||
initArcView()
|
initArcView()
|
||||||
@@ -120,7 +121,6 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
|
|
||||||
// binding.btnCollectFace.setOnClickListener { collectFace() }
|
// binding.btnCollectFace.setOnClickListener { collectFace() }
|
||||||
|
|
||||||
checkFaceState()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkCameraPermission() {
|
private fun checkCameraPermission() {
|
||||||
@@ -157,12 +157,15 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
private var openRectInfoDraw = false
|
private var openRectInfoDraw = false
|
||||||
|
|
||||||
private fun initArcViewModel() {
|
private fun initArcViewModel() {
|
||||||
|
|
||||||
recognizeViewModel.setLiveType(livenessType)
|
recognizeViewModel.setLiveType(livenessType)
|
||||||
recognizeViewModel.prepareRegister()
|
recognizeViewModel.prepareRegister()
|
||||||
recognizeViewModel.setOnRegisterFinishedCallback { facePreviewInfo, userFaceInfo ->
|
recognizeViewModel.setOnRegisterFinishedCallback { facePreviewInfo, userFaceInfo ->
|
||||||
|
//Log.d(TAG, "initArcViewModel: userFaceInfo == null : ${userFaceInfo == null}")
|
||||||
|
if (this.userFaceInfo == null && userFaceInfo != null) {
|
||||||
|
recognizeViewModel.updateRegisterStatus(RecognizeViewModel.REGISTER_STATUS_DONE)
|
||||||
this.userFaceInfo = userFaceInfo
|
this.userFaceInfo = userFaceInfo
|
||||||
Log.d(TAG, "initArcViewModel: userFaceInfo == null : ${userFaceInfo == null}")
|
return@setOnRegisterFinishedCallback
|
||||||
|
}
|
||||||
}
|
}
|
||||||
recognizeViewModel.ftInitCode.observe(this, Observer { ftInitCode: Int? ->
|
recognizeViewModel.ftInitCode.observe(this, Observer { ftInitCode: Int? ->
|
||||||
if (ftInitCode != ErrorInfo.MOK) {
|
if (ftInitCode != ErrorInfo.MOK) {
|
||||||
@@ -243,6 +246,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
* 打开餐盘柜
|
* 打开餐盘柜
|
||||||
*/
|
*/
|
||||||
private fun openPlate(userId: String?) {
|
private fun openPlate(userId: String?) {
|
||||||
|
Log.d(TAG, "openPlate: userId=$userId")
|
||||||
getPlateData { items ->
|
getPlateData { items ->
|
||||||
Log.d(TAG, "openPlate: items:${Gson().toJson(items)}")
|
Log.d(TAG, "openPlate: items:${Gson().toJson(items)}")
|
||||||
var item = items.firstOrNull { it.faceId == userId }
|
var item = items.firstOrNull { it.faceId == userId }
|
||||||
@@ -253,7 +257,9 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
return@getPlateData
|
return@getPlateData
|
||||||
}
|
}
|
||||||
// 未查询到当前用户,查询第一个未绑定的餐盘
|
// 未查询到当前用户,查询第一个未绑定的餐盘
|
||||||
item = items.firstOrNull { it.plateNumber.isNullOrEmpty().not() && it.faceId.isNullOrBlank() }
|
item = items.firstOrNull {
|
||||||
|
it.plateNumber.isNullOrEmpty().not() && it.faceId.isNullOrBlank()
|
||||||
|
}
|
||||||
Log.d(TAG, "openPlate: item2:${item}")
|
Log.d(TAG, "openPlate: item2:${item}")
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
//暂无餐盘
|
//暂无餐盘
|
||||||
@@ -264,7 +270,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
item.faceId = userId
|
item.faceId = userId
|
||||||
item.updateTime = DateTimeUtils.getDateTimeString()
|
item.updateTime = DateTimeUtils.getDateTimeString()
|
||||||
//打开柜子
|
//打开柜子
|
||||||
PlateUtils.open(this, item.equipmentBoxCode)
|
PlateUtils.open(this, item.equipmentBoxCode, false)
|
||||||
|
|
||||||
currentPlateInfo = item
|
currentPlateInfo = item
|
||||||
MyApp.plateList = items
|
MyApp.plateList = items
|
||||||
@@ -508,16 +514,32 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 临时用户id
|
||||||
|
*/
|
||||||
|
private var tempUserId: String = ""
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
if (isFirstOpen) {
|
||||||
|
goInitActivity()
|
||||||
|
binding.root.postDelayed({
|
||||||
|
isFirstOpen = false
|
||||||
|
}, 1000)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tempUserId = "${System.currentTimeMillis()}"
|
||||||
resumeCamera()
|
resumeCamera()
|
||||||
viewModel.resetUserInfo()
|
viewModel.resetUserInfo()
|
||||||
countDownTimer?.let {
|
countDownTimer?.let {
|
||||||
it.cancel()
|
it.cancel()
|
||||||
it.start()
|
it.start()
|
||||||
}
|
}
|
||||||
|
checkFaceState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var isFirstOpen = true
|
||||||
|
|
||||||
protected override fun onPause() {
|
protected override fun onPause() {
|
||||||
pauseCamera()
|
pauseCamera()
|
||||||
super.onPause()
|
super.onPause()
|
||||||
@@ -535,8 +557,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
// goInitActivity()
|
// goInitActivity()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val totalTimeInMillis = 30 * 1000L
|
||||||
fun initCountTime() {
|
fun initCountTime() {
|
||||||
val totalTimeInMillis = 30L * 1000
|
|
||||||
countDownTimer = object : CountDownTimer(totalTimeInMillis, 1000) {
|
countDownTimer = object : CountDownTimer(totalTimeInMillis, 1000) {
|
||||||
override fun onTick(millisUntilFinished: Long) {
|
override fun onTick(millisUntilFinished: Long) {
|
||||||
Timber.d("initCountTime onTick = ${(millisUntilFinished / 1000).toInt()}")
|
Timber.d("initCountTime onTick = ${(millisUntilFinished / 1000).toInt()}")
|
||||||
@@ -546,7 +568,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
override fun onFinish() {
|
override fun onFinish() {
|
||||||
goInitActivity()
|
goInitActivity()
|
||||||
}
|
}
|
||||||
}.start()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun goInitActivity() {
|
fun goInitActivity() {
|
||||||
@@ -556,19 +578,25 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
|
|
||||||
private fun collectFace() {
|
private fun collectFace() {
|
||||||
//toast("currentUserId=$currentUserId")
|
//toast("currentUserId=$currentUserId")
|
||||||
|
Log.d(TAG, "collectFace: -----------11111111----------")
|
||||||
|
if (isFirstOpen) return
|
||||||
|
Log.d(TAG, "collectFace: ----------22222222-----------")
|
||||||
if (facePreviewInfoList.isNullOrEmpty()) {
|
if (facePreviewInfoList.isNullOrEmpty()) {
|
||||||
ToastUtils.showToast("未检测到人脸信息")
|
//ToastUtils.showToast("未检测到人脸信息")
|
||||||
return
|
Log.d(TAG, "collectFace: ----------33333333-----------")
|
||||||
}
|
Log.d(TAG, "collectFace: 未检测到人脸信息")
|
||||||
if (currentUserId != null) {
|
|
||||||
currentUserId = null
|
|
||||||
// ToastUtils.showToast("您已采集过人脸信息")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Log.d(TAG, "collectFace: ----------44444444-----------")
|
||||||
|
// if (currentUserId != null) {
|
||||||
|
// currentUserId = null
|
||||||
|
//// ToastUtils.showToast("您已采集过人脸信息")
|
||||||
|
// return
|
||||||
|
// }
|
||||||
currentUserId = null
|
currentUserId = null
|
||||||
userFaceInfo = null
|
userFaceInfo = null
|
||||||
recognizeViewModel.updateRegisterStatus(REGISTER_STATUS_READY)
|
recognizeViewModel.updateRegisterStatus(REGISTER_STATUS_READY)
|
||||||
//showWaitingDialog("人脸信息中……")
|
// showWaitingDialog("加载中……")
|
||||||
|
|
||||||
// binding.tvFaceTip.gone()
|
// binding.tvFaceTip.gone()
|
||||||
// binding.btnCollectFace.invisible()
|
// binding.btnCollectFace.invisible()
|
||||||
@@ -576,14 +604,14 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
// binding.pbCollectLoading.visible()
|
// binding.pbCollectLoading.visible()
|
||||||
// binding.tvCollectState.text = "采集中......"
|
// binding.tvCollectState.text = "采集中......"
|
||||||
getFaceData { faceData ->
|
getFaceData { faceData ->
|
||||||
Log.d("LoginByFaceActivity", "faceData: $faceData")
|
Log.d("LoginByFaceActivity", "collectFace,faceData: $faceData")
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
//hideWaitingDialog()
|
// hideWaitingDialog()
|
||||||
//toast("人脸信息已采集")
|
//toast("人脸信息已采集")
|
||||||
// binding.pbCollectLoading.gone()
|
// binding.pbCollectLoading.gone()
|
||||||
//binding.tvCollectState.text = "采集完成"
|
//binding.tvCollectState.text = "采集完成"
|
||||||
userFaceInfo = null
|
userFaceInfo = null
|
||||||
countDown()
|
// countDown()
|
||||||
}
|
}
|
||||||
// sendFaceData(faceData)
|
// sendFaceData(faceData)
|
||||||
saveFaceInfo(faceData)
|
saveFaceInfo(faceData)
|
||||||
@@ -602,12 +630,14 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
val faceData = Base64.encode(userFaceInfo!!.faceFeature!!.featureData)
|
val faceData = Base64.encode(userFaceInfo!!.faceFeature!!.featureData)
|
||||||
block(faceData)
|
block(faceData)
|
||||||
|
checkFaceJob?.cancel()
|
||||||
job?.cancel()
|
job?.cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private var facePreviewInfoList: MutableList<FacePreviewInfo>?=null
|
|
||||||
|
private var facePreviewInfoList: MutableList<FacePreviewInfo>? = null
|
||||||
private var userFaceInfo: UserFaceInfo? = null
|
private var userFaceInfo: UserFaceInfo? = null
|
||||||
private var countDownJob: Job? = null
|
private var countDownJob: Job? = null
|
||||||
private var job: Job? = null
|
private var job: Job? = null
|
||||||
@@ -634,18 +664,24 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun saveFaceInfo(faceData: String) {
|
private fun saveFaceInfo(faceData: String) {
|
||||||
|
Log.d(TAG, "collectFace,saveFaceInfo: $faceData")
|
||||||
Thread {
|
Thread {
|
||||||
try {
|
try {
|
||||||
val tempId = "${System.currentTimeMillis()}"
|
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
||||||
|
val entity = faceDao.queryByUserName(tempUserId)
|
||||||
|
if (entity != null) {
|
||||||
|
//已存在用户
|
||||||
|
return@Thread
|
||||||
|
}
|
||||||
val faceEntity = FaceEntity(
|
val faceEntity = FaceEntity(
|
||||||
tempId,
|
tempUserId,
|
||||||
null,
|
null,
|
||||||
Base64.decode(faceData)
|
Base64.decode(faceData)
|
||||||
).also {
|
).also {
|
||||||
it.userType = "2"
|
it.userType = "2"
|
||||||
}
|
}
|
||||||
FaceDatabase.getInstance(this).faceDao().insert(faceEntity)
|
faceDao.insert(faceEntity)
|
||||||
recognizeViewModel.refreshFaceList();
|
recognizeViewModel.refreshFaceList()
|
||||||
// runOnUiThread {
|
// runOnUiThread {
|
||||||
// ToastUtils.showToast("你的人脸信息已采集")
|
// ToastUtils.showToast("你的人脸信息已采集")
|
||||||
// }
|
// }
|
||||||
@@ -654,6 +690,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var tcpClient: TcpClient? = null
|
private var tcpClient: TcpClient? = null
|
||||||
|
|
||||||
private fun addSocketListener() {
|
private fun addSocketListener() {
|
||||||
@@ -688,10 +725,12 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
LanServer.TYPE_ADD_FACE_DATA -> {
|
LanServer.TYPE_ADD_FACE_DATA -> {
|
||||||
//采集设备id自己生成,不接收服务端的,在本地只判断是否存在同一人脸数据
|
//采集设备id自己生成,不接收服务端的,在本地只判断是否存在同一人脸数据
|
||||||
}
|
}
|
||||||
|
|
||||||
LanServer.TYPE_CLEAR_FACE_DATA -> {
|
LanServer.TYPE_CLEAR_FACE_DATA -> {
|
||||||
clearFaceData()
|
clearFaceData()
|
||||||
}
|
}
|
||||||
else-> {}
|
|
||||||
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -719,16 +758,21 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
recognizeViewModel.refreshFaceList();
|
recognizeViewModel.refreshFaceList();
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
private val WAITING_TIME = 5 * 1000L
|
|
||||||
|
private val WAITING_TIME = 3 * 1000L
|
||||||
private var checkStartTime = 0L
|
private var checkStartTime = 0L
|
||||||
private var checkFaceJob: Job?=null
|
private var checkFaceJob: Job? = null
|
||||||
private fun checkFaceState() {
|
private fun checkFaceState() {
|
||||||
|
checkStartTime = System.currentTimeMillis()
|
||||||
checkFaceJob = executor.startIntervalTask(5) {
|
checkFaceJob = executor.startIntervalTask(5) {
|
||||||
if (System.currentTimeMillis() - checkStartTime >= WAITING_TIME && currentUserId.isNullOrBlank()) {
|
Log.d("Login", "currentUserId=${currentUserId}")
|
||||||
|
if (currentUserId.isNullOrBlank().not()) {
|
||||||
checkFaceJob?.cancel()
|
checkFaceJob?.cancel()
|
||||||
|
return@startIntervalTask
|
||||||
|
}
|
||||||
|
if (System.currentTimeMillis() - checkStartTime >= WAITING_TIME) {
|
||||||
//超过5秒采集人脸并识别
|
//超过5秒采集人脸并识别
|
||||||
collectFace()
|
collectFace()
|
||||||
return@startIntervalTask
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,33 +33,42 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||||||
// 静态启动方法
|
// 静态启动方法
|
||||||
companion object {
|
companion object {
|
||||||
private const val PARAM_PAGE_TYPE = "pageType"
|
private const val PARAM_PAGE_TYPE = "pageType"
|
||||||
private const val PARAM_EQUIPMENT_INFO = "equipmentUserInfo"
|
// private const val PARAM_EQUIPMENT_INFO = "equipmentUserInfo"
|
||||||
private const val PARAM_IS_ADMIN = "isAdmin"
|
// private const val PARAM_IS_ADMIN = "isAdmin"
|
||||||
fun start(
|
// fun start(
|
||||||
context: Context,
|
// context: Context,
|
||||||
pageType: PageType,
|
// pageType: PageType,
|
||||||
equipmentUserInfo: EquipmentUserInfo? = null,
|
// equipmentUserInfo: EquipmentUserInfo? = null,
|
||||||
isAdmin: Boolean = false,
|
// isAdmin: Boolean = false,
|
||||||
block:()->Unit={}
|
// block:()->Unit={}
|
||||||
) {
|
// ) {
|
||||||
|
// val intent = Intent(context, MainActivity::class.java)
|
||||||
|
// intent.putExtra(PARAM_PAGE_TYPE, pageType.name)
|
||||||
|
// intent.putExtra(PARAM_EQUIPMENT_INFO, equipmentUserInfo)
|
||||||
|
// intent.putExtra(PARAM_IS_ADMIN, isAdmin)
|
||||||
|
// context.startActivity(intent)
|
||||||
|
// }
|
||||||
|
|
||||||
|
fun start(context: Context,pageType: PageType, isScanCode: Boolean = false) {
|
||||||
val intent = Intent(context, MainActivity::class.java)
|
val intent = Intent(context, MainActivity::class.java)
|
||||||
intent.putExtra(PARAM_PAGE_TYPE, pageType.name)
|
intent.putExtra(PARAM_PAGE_TYPE, pageType.name)
|
||||||
intent.putExtra(PARAM_EQUIPMENT_INFO, equipmentUserInfo)
|
intent.putExtra(PlateOpenFragment.IS_SCAN_CODE, isScanCode)
|
||||||
intent.putExtra(PARAM_IS_ADMIN, isAdmin)
|
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
val param = intent.getStringExtra(PARAM_PAGE_TYPE)
|
val param = intent.getStringExtra(PARAM_PAGE_TYPE)
|
||||||
val isAdmin = intent.getBooleanExtra(PARAM_IS_ADMIN, false)
|
// val isAdmin = intent.getBooleanExtra(PARAM_IS_ADMIN, false)
|
||||||
val equipmentUserInfo = intent.getParcelableExtra<EquipmentUserInfo>(PARAM_EQUIPMENT_INFO)
|
val isScanCode = intent.getBooleanExtra(PlateOpenFragment.IS_SCAN_CODE, false)
|
||||||
|
// val equipmentUserInfo = intent.getParcelableExtra<EquipmentUserInfo>(PARAM_EQUIPMENT_INFO)
|
||||||
pageType = param?.let { PageType.valueOf(param) } ?: PageType.SETTING_LIST
|
pageType = param?.let { PageType.valueOf(param) } ?: PageType.SETTING_LIST
|
||||||
fragmentHelper = FragmentHelper(supportFragmentManager, R.id.fragment_container)
|
fragmentHelper = FragmentHelper(supportFragmentManager, R.id.fragment_container)
|
||||||
val page = when (pageType) {
|
val page = when (pageType) {
|
||||||
PageType.SETTING_LIST -> SettingListFragment()
|
PageType.SETTING_LIST -> SettingListFragment()
|
||||||
// PageType.BIND_PLATE -> BindPlateFragment.newInstance(equipmentUserInfo)
|
// PageType.BIND_PLATE -> BindPlateFragment.newInstance(equipmentUserInfo)
|
||||||
PageType.PLATE_TIP -> PlateOpenFragment.newInstance(equipmentUserInfo, isAdmin)
|
// PageType.PLATE_TIP -> PlateOpenFragment.newInstance(equipmentUserInfo, isAdmin)
|
||||||
|
PageType.PLATE_TIP -> PlateOpenFragment.newInstance(isScanCode)
|
||||||
// PageType.UNBIND_PLATE -> UnBindPlateFragment.newInstance(equipmentUserInfo)
|
// PageType.UNBIND_PLATE -> UnBindPlateFragment.newInstance(equipmentUserInfo)
|
||||||
PageType.PLATE_CABINET_FULL -> PlateCabinetFullFragment()
|
PageType.PLATE_CABINET_FULL -> PlateCabinetFullFragment()
|
||||||
else -> null
|
else -> null
|
||||||
|
|||||||
@@ -15,47 +15,62 @@ import com.sw.platecabinet.model.response.EquipmentUserInfo
|
|||||||
class PlateOpenFragment :
|
class PlateOpenFragment :
|
||||||
BaseFragment<FragmentPlateOpenBinding>(FragmentPlateOpenBinding::inflate) {
|
BaseFragment<FragmentPlateOpenBinding>(FragmentPlateOpenBinding::inflate) {
|
||||||
private var totalTimeInMillis: Long = Constants.AUTO_CLOSE_TIME * 1000
|
private var totalTimeInMillis: Long = Constants.AUTO_CLOSE_TIME * 1000
|
||||||
internal val KEY_ACTION_TYPE = "actionType"
|
// internal val KEY_ACTION_TYPE = "actionType"
|
||||||
internal val PARAM_IS_ADMIN = "isAdmin"
|
// internal val PARAM_IS_ADMIN = "isAdmin"
|
||||||
private var info: EquipmentUserInfo? = null
|
// private var info: EquipmentUserInfo? = null
|
||||||
private var isAdmin: Boolean = false
|
// private var isAdmin: Boolean = false
|
||||||
|
|
||||||
|
private var isScanCode = false
|
||||||
companion object {
|
companion object {
|
||||||
|
const val IS_SCAN_CODE = "isScanCode"
|
||||||
|
// @JvmStatic
|
||||||
|
// fun newInstance(userInfo: EquipmentUserInfo?, isAdmin: Boolean) =
|
||||||
|
// PlateOpenFragment().apply {
|
||||||
|
// arguments = Bundle().apply {
|
||||||
|
//// putParcelable(KEY_ACTION_TYPE, userInfo)
|
||||||
|
//// putBoolean(PARAM_IS_ADMIN, isAdmin)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun newInstance(userInfo: EquipmentUserInfo?, isAdmin: Boolean) =
|
fun newInstance(isScanCode: Boolean) =
|
||||||
PlateOpenFragment().apply {
|
PlateOpenFragment().apply {
|
||||||
arguments = Bundle().apply {
|
arguments = Bundle().apply {
|
||||||
putParcelable(KEY_ACTION_TYPE, userInfo)
|
putBoolean(IS_SCAN_CODE, isScanCode)
|
||||||
putBoolean(PARAM_IS_ADMIN, isAdmin)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
arguments?.let {
|
arguments?.let {
|
||||||
info = it.getParcelable(KEY_ACTION_TYPE)
|
// info = it.getParcelable(KEY_ACTION_TYPE)
|
||||||
isAdmin = it.getBoolean(PARAM_IS_ADMIN)
|
// isAdmin = it.getBoolean(PARAM_IS_ADMIN)
|
||||||
info?.let {
|
// info?.let {
|
||||||
if (!it.hasEquipmentBox()) {
|
// if (!it.hasEquipmentBox()) {
|
||||||
binding.ivType.setImageResource(R.drawable.ic_tip_warn)
|
|
||||||
binding.tvTitle.text = "暂无餐盘信息"
|
|
||||||
binding.tvSubTitle.text = "请联系管理员"
|
|
||||||
binding.tvTitle.setTextColor(requireContext().getColor(R.color.tip_title_fail))
|
|
||||||
}
|
|
||||||
// else if (it.isOtherEquipment()) {
|
|
||||||
// binding.ivType.setImageResource(R.drawable.ic_tip_warn)
|
// binding.ivType.setImageResource(R.drawable.ic_tip_warn)
|
||||||
// binding.tvTitle.text = "暂无餐盘信息"
|
// binding.tvTitle.text = "暂无餐盘信息"
|
||||||
// binding.tvSubTitle.text = "您的餐盘绑定在${it.equipmentName ?: " "}号柜上"
|
// binding.tvSubTitle.text = "请联系管理员"
|
||||||
// binding.tvTitle.setTextColor(requireContext().getColor(R.color.tip_title_fail))
|
// binding.tvTitle.setTextColor(requireContext().getColor(R.color.tip_title_fail))
|
||||||
// }
|
// }
|
||||||
else {
|
//// else if (it.isOtherEquipment()) {
|
||||||
|
//// binding.ivType.setImageResource(R.drawable.ic_tip_warn)
|
||||||
|
//// binding.tvTitle.text = "暂无餐盘信息"
|
||||||
|
//// binding.tvSubTitle.text = "您的餐盘绑定在${it.equipmentName ?: " "}号柜上"
|
||||||
|
//// binding.tvTitle.setTextColor(requireContext().getColor(R.color.tip_title_fail))
|
||||||
|
//// }
|
||||||
|
// else {
|
||||||
|
// binding.ivType.setImageResource(R.drawable.ic_tip_success)
|
||||||
|
// binding.tvTitle.text = "柜门开启"
|
||||||
|
// binding.tvSubTitle.text = "餐盘取出后请关闭柜门"
|
||||||
|
// binding.tvTitle.setTextColor(requireContext().getColor(R.color.tip_title_success))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
isScanCode = it.getBoolean(IS_SCAN_CODE, false)
|
||||||
binding.ivType.setImageResource(R.drawable.ic_tip_success)
|
binding.ivType.setImageResource(R.drawable.ic_tip_success)
|
||||||
binding.tvTitle.text = "柜门开启"
|
binding.tvTitle.text = "柜门开启"
|
||||||
binding.tvSubTitle.text = "餐盘取出后请关闭柜门"
|
binding.tvSubTitle.text = if (isScanCode) "餐盘放入后请关闭柜门" else "餐盘取出后请关闭柜门"
|
||||||
binding.tvTitle.setTextColor(requireContext().getColor(R.color.tip_title_success))
|
binding.tvTitle.setTextColor(requireContext().getColor(R.color.tip_title_success))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
initCountTime()
|
initCountTime()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ class SettingListFragment :
|
|||||||
this.tvOpen.setTextColor(resources.getColor(R.color.unbind_32283C))
|
this.tvOpen.setTextColor(resources.getColor(R.color.unbind_32283C))
|
||||||
this.llBindInfo.visibility = View.GONE
|
this.llBindInfo.visibility = View.GONE
|
||||||
this.tvUnbind.visibility = View.VISIBLE
|
this.tvUnbind.visibility = View.VISIBLE
|
||||||
|
this.tvUnbind.text = if (item.plateNumber.isNullOrBlank()) "未绑定" else "未绑定(${item.plateNumber})"
|
||||||
}
|
}
|
||||||
// this.llRoot.setOnClickListener {
|
// this.llRoot.setOnClickListener {
|
||||||
//// Timber.d("itemClick llRoot ${item.name}, position = $position")
|
//// Timber.d("itemClick llRoot ${item.name}, position = $position")
|
||||||
@@ -179,7 +180,12 @@ class SettingListFragment :
|
|||||||
// }
|
// }
|
||||||
this.llOpen.setOnClickListener {
|
this.llOpen.setOnClickListener {
|
||||||
// item.faceId = null
|
// item.faceId = null
|
||||||
PlateUtils.open(requireActivity(), item.equipmentBoxCode)
|
PlateUtils.open(
|
||||||
|
fragmentActivity = requireActivity(),
|
||||||
|
code = item.equipmentBoxCode,
|
||||||
|
isScanCode = false,
|
||||||
|
isSetting = true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,12 @@ import timber.log.Timber
|
|||||||
|
|
||||||
object PlateUtils {
|
object PlateUtils {
|
||||||
|
|
||||||
fun open(fragmentActivity: FragmentActivity, code: String?) {
|
fun open(
|
||||||
|
fragmentActivity: FragmentActivity,
|
||||||
|
code: String?,
|
||||||
|
isScanCode: Boolean,
|
||||||
|
isSetting: Boolean = false
|
||||||
|
) {
|
||||||
val activity = fragmentActivity as BaseActivity<*>
|
val activity = fragmentActivity as BaseActivity<*>
|
||||||
Timber.d("itemClick llOpen equipmentBoxCode = ${code}")
|
Timber.d("itemClick llOpen equipmentBoxCode = ${code}")
|
||||||
val equipmentBoxCode: Int = code?.toInt() ?: -1
|
val equipmentBoxCode: Int = code?.toInt() ?: -1
|
||||||
@@ -23,14 +28,15 @@ object PlateUtils {
|
|||||||
SerialApi.openPlate(equipmentBoxCode, object : SerialPortManager.SendCallback {
|
SerialApi.openPlate(equipmentBoxCode, object : SerialPortManager.SendCallback {
|
||||||
override fun onSuccess() {
|
override fun onSuccess() {
|
||||||
activity.hideWaitingDialog()
|
activity.hideWaitingDialog()
|
||||||
|
if (isSetting.not()) {
|
||||||
MainActivity.start(
|
MainActivity.start(
|
||||||
activity,
|
activity,
|
||||||
pageType = PageType.PLATE_TIP,
|
pageType = PageType.PLATE_TIP,
|
||||||
isAdmin = true,
|
isScanCode = isScanCode
|
||||||
block = {
|
|
||||||
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
ToastUtils.showToast("柜门打开成功")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFail(e: Exception?) {
|
override fun onFail(e: Exception?) {
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ class UserViewModel : BaseViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 通过人脸获取到的用户信息
|
// 通过人脸获取到的用户信息
|
||||||
private val _currentUserInfo = MutableStateFlow<EquipmentUserInfo?>(null)
|
// private val _currentUserInfo = MutableStateFlow<EquipmentUserInfo?>(null)
|
||||||
val currentUserInfo: StateFlow<EquipmentUserInfo?> = _currentUserInfo
|
// val currentUserInfo: StateFlow<EquipmentUserInfo?> = _currentUserInfo
|
||||||
|
|
||||||
private val faceApi: FaceApi = FaceApi()
|
private val faceApi: FaceApi = FaceApi()
|
||||||
|
|
||||||
@@ -140,35 +140,35 @@ class UserViewModel : BaseViewModel() {
|
|||||||
* 校验码登录
|
* 校验码登录
|
||||||
*/
|
*/
|
||||||
fun loginWithPwd(loginParam: LoginParam) {
|
fun loginWithPwd(loginParam: LoginParam) {
|
||||||
launchWithLoading {
|
// launchWithLoading {
|
||||||
val response = repository.equipmentBoxLogin(loginParam)
|
// val response = repository.equipmentBoxLogin(loginParam)
|
||||||
if (parseResponse(response)) {
|
// if (parseResponse(response)) {
|
||||||
_currentUserInfo.value = response.data
|
// _currentUserInfo.value = response.data
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户id获取用户信息
|
* 通过用户id获取用户信息
|
||||||
*/
|
*/
|
||||||
fun getUserInfoById(memberId: String?, action: (EquipmentUserInfo?) -> Unit = {}) {
|
// fun getUserInfoById(memberId: String?, action: (EquipmentUserInfo?) -> Unit = {}) {
|
||||||
_currentUserInfo.value = null
|
// _currentUserInfo.value = null
|
||||||
launchWithLoading {
|
// launchWithLoading {
|
||||||
val loginParam = LoginParam(faceId = memberId)
|
// val loginParam = LoginParam(faceId = memberId)
|
||||||
val response = repository.equipmentBoxLogin(loginParam)
|
// val response = repository.equipmentBoxLogin(loginParam)
|
||||||
if (parseResponse(response)) {
|
// if (parseResponse(response)) {
|
||||||
_currentUserInfo.value = response.data
|
// _currentUserInfo.value = response.data
|
||||||
action(response.data)
|
// action(response.data)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重置用户信息
|
* 重置用户信息
|
||||||
*/
|
*/
|
||||||
fun resetUserInfo() {
|
fun resetUserInfo() {
|
||||||
Timber.d("resetUserInfo")
|
Timber.d("resetUserInfo")
|
||||||
_currentUserInfo.value = null
|
// _currentUserInfo.value = null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDeviceConfig(block: (DeviceConfig?) -> Unit) {
|
fun getDeviceConfig(block: (DeviceConfig?) -> Unit) {
|
||||||
|
|||||||
@@ -43,16 +43,24 @@
|
|||||||
<!-- android:layout_marginTop="20dp"-->
|
<!-- android:layout_marginTop="20dp"-->
|
||||||
<!-- android:src="@drawable/ic_init_press" />-->
|
<!-- android:src="@drawable/ic_init_press" />-->
|
||||||
|
|
||||||
<TextView android:id="@+id/takeButton"
|
<FrameLayout
|
||||||
|
android:id="@+id/takeButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="-20dp">
|
||||||
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="60dp"
|
android:layout_height="60dp"
|
||||||
android:text="点击取盘"
|
android:text="点击取盘"
|
||||||
android:textColor="#FFCC99"
|
android:textColor="#FFCC99"
|
||||||
android:textSize="24sp"
|
android:textSize="24sp"
|
||||||
|
android:layout_marginHorizontal="30dp"
|
||||||
|
android:layout_marginVertical="20dp"
|
||||||
android:paddingHorizontal="45dp"
|
android:paddingHorizontal="45dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:background="@drawable/btn_outline"
|
android:background="@drawable/btn_outline"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
|
</FrameLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
app:cardCornerRadius="5dp"
|
app:cardCornerRadius="5dp"
|
||||||
app:cardPreventCornerOverlap="true">
|
app:cardPreventCornerOverlap="true">
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/toast_tv"
|
android:id="@+id/toast_tv"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
|
|||||||
Reference in New Issue
Block a user