优化
This commit is contained in:
@@ -419,16 +419,17 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
// private val dealyMillis = 10 * 60 * 1000L
|
// private val dealyMillis = 10 * 60 * 1000L
|
||||||
private val initialDelay = 5 * 60 * 1000L
|
private val initialDelay = 5 * 60 * 1000L
|
||||||
private val dealyMillis = 5 * 60 * 1000L
|
private val dealyMillis = 5 * 60 * 1000L
|
||||||
fun startFaceTask() {
|
fun startFaceTask(block: (List<String?>) -> Unit) {
|
||||||
faceTaskJob =
|
faceTaskJob =
|
||||||
intervalExecutor.startIntervalTaskWithInitialDelay(initialDelay, dealyMillis) {
|
intervalExecutor.startIntervalTaskWithInitialDelay(initialDelay, dealyMillis) {
|
||||||
getFaceIncrementList()
|
getFaceIncrementList(action = block)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var faceTimestamp = 0L
|
private var faceTimestamp = 0L
|
||||||
|
|
||||||
//private var taskPageNo = 1
|
//private var taskPageNo = 1
|
||||||
private fun getFaceIncrementList(pageNo: Int = 1) {
|
private fun getFaceIncrementList(pageNo: Int = 1, action:(List<String?>)-> Unit) {
|
||||||
val timestamp = SpTool.lastFaceTimestamp
|
val timestamp = SpTool.lastFaceTimestamp
|
||||||
if (timestamp == 0L) {
|
if (timestamp == 0L) {
|
||||||
return
|
return
|
||||||
@@ -443,6 +444,8 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
return@runOnUiThread
|
return@runOnUiThread
|
||||||
}
|
}
|
||||||
updateFaceData(list)
|
updateFaceData(list)
|
||||||
|
val userIdList = list.map { it.userId }
|
||||||
|
action(userIdList)
|
||||||
//if (list.size >= settingViewModel.PAGE_SIZE) {
|
//if (list.size >= settingViewModel.PAGE_SIZE) {
|
||||||
// faceTimestamp = list.last().faceUpdateTimestamp ?: 0
|
// faceTimestamp = list.last().faceUpdateTimestamp ?: 0
|
||||||
// taskPageNo++
|
// taskPageNo++
|
||||||
@@ -461,22 +464,26 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
private fun updateFaceData(list: List<UserFaceModel>) {
|
private fun updateFaceData(list: List<UserFaceModel>) {
|
||||||
Thread {
|
Thread {
|
||||||
val faceList = mutableListOf<FaceEntity>()
|
val faceList = mutableListOf<FaceEntity>()
|
||||||
|
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
||||||
try {
|
try {
|
||||||
list.forEach { model ->
|
list.forEach { model ->
|
||||||
if (model.faceDeleted == true) {
|
if (model.faceDeleted == true) {
|
||||||
//删除数据
|
//删除数据
|
||||||
FaceDatabase.getInstance(this).faceDao().deleteFaceById(model.userId)
|
faceDao.deleteFaceById(model.userId)
|
||||||
} else {
|
} else {
|
||||||
//保存数据
|
val faceData = faceDao.queryByUserName(model.userId)
|
||||||
val faceEntity = FaceEntity(
|
if (faceData == null) {
|
||||||
model.userId,
|
//保存数据
|
||||||
null,
|
val faceEntity = FaceEntity(
|
||||||
Base64.decode(model.faceFeatureStr)
|
model.userId,
|
||||||
).also {
|
null,
|
||||||
//1-会员、2-临时用户
|
Base64.decode(model.faceFeatureStr)
|
||||||
it.userType = if (model.isMember) "1" else "2"
|
).also {
|
||||||
|
//1-会员、2-临时用户
|
||||||
|
it.userType = if (model.isMember) "1" else "2"
|
||||||
|
}
|
||||||
|
faceList.add(faceEntity)
|
||||||
}
|
}
|
||||||
faceList.add(faceEntity)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
@@ -53,10 +53,11 @@ class DeviceInitActivity : BaseActivity<ActivityDeviceInitBinding>() {
|
|||||||
userViewModel.getUserFaceCache { status, msg ->
|
userViewModel.getUserFaceCache { status, msg ->
|
||||||
getDeviceConfig()
|
getDeviceConfig()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
getDeviceConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getDeviceConfig()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDeviceConfig() {
|
private fun getDeviceConfig() {
|
||||||
|
|||||||
@@ -138,7 +138,9 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
//开启人脸增量数据定时任务
|
//开启人脸增量数据定时任务
|
||||||
startFaceTask()
|
startFaceTask {
|
||||||
|
loadLogInfo("collectFace增量接口数据用户id:${Gson().toJson(it)}")
|
||||||
|
}
|
||||||
|
|
||||||
val soundMap = hashMapOf<String, Int>()
|
val soundMap = hashMapOf<String, Int>()
|
||||||
soundMap[COLLECT_SUCCESS] = R.raw.collect_success
|
soundMap[COLLECT_SUCCESS] = R.raw.collect_success
|
||||||
@@ -827,31 +829,33 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
private var currentUserId: String? = null
|
private var currentUserId: String? = null
|
||||||
|
|
||||||
private fun saveFaceInfo(faceModel: UserFaceModel) {
|
private fun saveFaceInfo(faceModel: UserFaceModel) {
|
||||||
try {
|
Thread {
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------8,保存人脸取特征数据-----------")
|
try {
|
||||||
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
loadLogInfo("collectFace,saveFaceInfo: ----------8,保存人脸取特征数据-----------")
|
||||||
val faceEntity = FaceEntity(
|
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
||||||
faceModel.userId,
|
val faceEntity = FaceEntity(
|
||||||
null,
|
faceModel.userId,
|
||||||
Base64.decode(faceModel.faceFeatureStr)
|
null,
|
||||||
).also {
|
Base64.decode(faceModel.faceFeatureStr)
|
||||||
//1-会员、2-临时用户
|
).also {
|
||||||
it.userType = if (faceModel.isMember) "1" else "2"
|
//1-会员、2-临时用户
|
||||||
|
it.userType = if (faceModel.isMember) "1" else "2"
|
||||||
|
}
|
||||||
|
faceDao.insert(faceEntity)
|
||||||
|
loadLogInfo("collectFace,saveFaceInfo: ----------10,人脸数据保存完成-----------")
|
||||||
|
recognizeViewModel.refreshFaceList()
|
||||||
|
loadLogInfo("collectFace,saveFaceInfo: ----------11,刷新人脸数据-----------")
|
||||||
|
runOnUiThread { recognizeViewModel.onPreviewFrame(ByteArray(1382400), true) }
|
||||||
|
loadLogInfo("---------------------------------")
|
||||||
|
collectCount = 0
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
loadLogInfo("collectFace,saveFaceInfo: ----------13,人脸采集异常:${e.message}-----------")
|
||||||
|
collectCount++
|
||||||
|
loadLogInfo("collectFace,saveFaceInfo: ----------14,${collectCount}次人脸采集异常:${e.message}-----------")
|
||||||
|
ToastUtils.showToast("人脸采集异常:${e.message}")
|
||||||
}
|
}
|
||||||
faceDao.insert(faceEntity)
|
}.start()
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------10,人脸数据保存完成-----------")
|
|
||||||
recognizeViewModel.refreshFaceList()
|
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------11,刷新人脸数据-----------")
|
|
||||||
runOnUiThread { recognizeViewModel.onPreviewFrame(ByteArray(1382400), true) }
|
|
||||||
loadLogInfo("---------------------------------")
|
|
||||||
collectCount = 0
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------13,人脸采集异常:${e.message}-----------")
|
|
||||||
collectCount++
|
|
||||||
loadLogInfo("collectFace,saveFaceInfo: ----------14,${collectCount}次人脸采集异常:${e.message}-----------")
|
|
||||||
ToastUtils.showToast("人脸采集异常:${e.message}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var collectCount = 0
|
private var collectCount = 0
|
||||||
|
|||||||
@@ -26,9 +26,11 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvContent"
|
android:id="@+id/tvContent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="30dp"
|
android:layout_marginTop="30dp"
|
||||||
|
android:layout_marginHorizontal="50dp"
|
||||||
|
android:gravity="center"
|
||||||
tools:text="解绑后该用户将无法使用餐盘柜"
|
tools:text="解绑后该用户将无法使用餐盘柜"
|
||||||
android:textColor="#ff999999"
|
android:textColor="#ff999999"
|
||||||
android:textSize="24sp"/>
|
android:textSize="24sp"/>
|
||||||
|
|||||||
@@ -1,31 +1,29 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<RelativeLayout
|
<LinearLayout
|
||||||
android:layout_width="240dp"
|
android:layout_width="240dp"
|
||||||
android:layout_height="80dp"
|
android:layout_height="80dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
android:background="@drawable/dialog_waiting">
|
android:background="@drawable/dialog_waiting">
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
|
android:indeterminateTint="@color/teal_200"
|
||||||
|
android:indeterminateTintMode="src_atop" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvTip"
|
android:id="@+id/tvTip"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_marginStart="30dp"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:text="请稍等"
|
android:text="请稍等"
|
||||||
android:textSize="22sp" />
|
android:textSize="22sp" />
|
||||||
|
|
||||||
<ProgressBar
|
</LinearLayout>
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_marginRight="30dp"
|
|
||||||
android:layout_toLeftOf="@id/tvTip"
|
|
||||||
android:indeterminateTint="@color/teal_200"
|
|
||||||
android:indeterminateTintMode="src_atop" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
Reference in New Issue
Block a user