人脸全量接口只首次请求
This commit is contained in:
@@ -153,7 +153,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
isPageVisible = true
|
||||
addBackEventListener()
|
||||
initView()
|
||||
viewModel.getUserFaceCache(pageNo = 1)
|
||||
if (SpTool.firstGetFace) {
|
||||
viewModel.getUserFaceCache(pageNo = 1)
|
||||
}
|
||||
setupCamera()
|
||||
initData()
|
||||
registerKeyEvent()
|
||||
@@ -921,10 +923,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
fun startFaceTask() {
|
||||
faceTaskJob =
|
||||
intervalExecutor.startIntervalTaskWithInitialDelay(initialDelay, dealyMillis) {
|
||||
val timestamp = SpTool.getLastFaceTimestamp()
|
||||
if (timestamp == 0L) {
|
||||
return@startIntervalTaskWithInitialDelay
|
||||
}
|
||||
val timestamp = SpTool.lastFaceTimestamp
|
||||
//if (timestamp == 0L) {
|
||||
// return@startIntervalTaskWithInitialDelay
|
||||
//}
|
||||
viewModel.getFaceIncrementList(
|
||||
// pageNo = taskPageNo,
|
||||
timestamp = timestamp,
|
||||
|
||||
@@ -1,19 +1,30 @@
|
||||
package com.sw.dualscreen.utils;
|
||||
package com.sw.dualscreen.utils
|
||||
|
||||
import com.sw.dualscreen.MyApp;
|
||||
import com.sw.dualscreen.MyApp
|
||||
import com.sw.dualscreen.utils.SPUtil.Companion.getInstance
|
||||
|
||||
public class SpTool {
|
||||
object SpTool {
|
||||
const val LAST_FACE_TIMESTAMP: String = "faceTimestamp"
|
||||
|
||||
public static final String LAST_FACE_TIMESTAMP = "faceTimestamp";
|
||||
const val IS_FIRST_GET_FACE = "isFirstGetFace"
|
||||
|
||||
public static long getLastFaceTimestamp() {
|
||||
return SPUtil.Companion.getInstance(MyApp.getContext(), "default_sp").get(LAST_FACE_TIMESTAMP, 0L);
|
||||
}
|
||||
private var spUtil: SPUtil? = null
|
||||
|
||||
public static void setLastFaceTimestamp(long timestamp) {
|
||||
SPUtil.Companion.getInstance(MyApp.getContext(), "default_sp").put(LAST_FACE_TIMESTAMP, timestamp);
|
||||
init {
|
||||
spUtil = getInstance(MyApp.instance!!, "default_sp")
|
||||
}
|
||||
|
||||
|
||||
var lastFaceTimestamp: Long
|
||||
get() = spUtil?.get(LAST_FACE_TIMESTAMP, 0L)?:0L
|
||||
set(timestamp) {
|
||||
spUtil?.put(LAST_FACE_TIMESTAMP, timestamp)
|
||||
}
|
||||
|
||||
var firstGetFace: Boolean
|
||||
get() = spUtil?.get(IS_FIRST_GET_FACE, true)?:true
|
||||
set(value) {
|
||||
spUtil?.boolean(IS_FIRST_GET_FACE, value)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ class UserViewModel : BaseViewModel() {
|
||||
launch {
|
||||
_loadFaceResult.value = false
|
||||
//获取全量数据时,时间戳改为0
|
||||
SpTool.setLastFaceTimestamp(0)
|
||||
SpTool.lastFaceTimestamp = 0
|
||||
val response = repository.getUserFaceCache(currentPageNo)
|
||||
if (parseResponse(response)) {
|
||||
// 获取成功一次后缓存状态
|
||||
@@ -107,8 +107,8 @@ class UserViewModel : BaseViewModel() {
|
||||
ToastUtils.showToast("查询人脸数据为空")
|
||||
return@withContext
|
||||
}
|
||||
val item = list.map { it.member }
|
||||
Timber.tag(TAG).d("getUserFaceCache item = ${item}")
|
||||
//val item = list.map { it.member }
|
||||
//Timber.tag(TAG).d("getUserFaceCache item = $item")
|
||||
val faceEntity = list.map {
|
||||
FaceEntity(it.userId, null, Base64.decode(it.faceFeatureStr)).also { item->
|
||||
item.userType = if (it.member) "1" else "2"
|
||||
@@ -127,7 +127,7 @@ class UserViewModel : BaseViewModel() {
|
||||
//非空最后一条数据的是时间戳,空使用上次list最后一条时间戳
|
||||
lastFaceTimestamp = list.last().faceUpdateTimestamp ?: 0L
|
||||
}
|
||||
SpTool.setLastFaceTimestamp(lastFaceTimestamp)
|
||||
SpTool.lastFaceTimestamp = lastFaceTimestamp
|
||||
_loadFaceResult.value = true
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ class UserViewModel : BaseViewModel() {
|
||||
//非空实现最后一条数据的是时间戳,空使用上次list最后一条时间戳
|
||||
lastFaceTimestamp = list.last().faceUpdateTimestamp ?: 0L
|
||||
}
|
||||
SpTool.setLastFaceTimestamp(lastFaceTimestamp)
|
||||
SpTool.lastFaceTimestamp = lastFaceTimestamp
|
||||
onAllQueryFinished()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user