增量分页优化
This commit is contained in:
@@ -97,10 +97,10 @@ class UserViewModel : BaseViewModel() {
|
||||
withContext(Dispatchers.Default) {
|
||||
val list: List<UserFaceModel> = response.data ?: emptyList()
|
||||
if (list.isEmpty()) {
|
||||
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
|
||||
ToastUtils.showToast("查询人脸数据为空")
|
||||
return@withContext
|
||||
}
|
||||
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
|
||||
// val item = list.firstOrNull { it.userId == "1951105919342936066" }
|
||||
// Timber.tag(TAG).d("getUserFaceCache userId = ${item?.userId}")
|
||||
val faceEntity = list.map {
|
||||
@@ -111,6 +111,7 @@ class UserViewModel : BaseViewModel() {
|
||||
currentPageNo++
|
||||
getUserFaceCache(currentPageNo)
|
||||
} else {
|
||||
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
|
||||
_loadFaceResult.value = true
|
||||
}
|
||||
}
|
||||
@@ -156,7 +157,8 @@ class UserViewModel : BaseViewModel() {
|
||||
pageNo: Int = 1,
|
||||
pageSize: Int = PAGE_SIZE,
|
||||
timestamp: Long,
|
||||
block: (List<UserFaceModel>) -> Unit
|
||||
onAllQueryFinished:()->Unit,
|
||||
onPageQueryFinished: (List<UserFaceModel>) -> Unit
|
||||
) {
|
||||
Timber.tag(TAG).d("getFaceIncrementList")
|
||||
launch {
|
||||
@@ -168,7 +170,18 @@ class UserViewModel : BaseViewModel() {
|
||||
if (parseResponse(response)) {
|
||||
withContext(Dispatchers.Default) {
|
||||
val list: List<UserFaceModel> = response.data ?: emptyList()
|
||||
block(list)
|
||||
onPageQueryFinished(list)
|
||||
if (list.size >= pageSize) {
|
||||
getFaceIncrementList(
|
||||
pageNo = pageNo + 1,
|
||||
pageSize = pageSize,
|
||||
timestamp = timestamp,
|
||||
onAllQueryFinished = onAllQueryFinished,
|
||||
onPageQueryFinished = onPageQueryFinished
|
||||
)
|
||||
} else {
|
||||
onAllQueryFinished()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user