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