增量分页优化
This commit is contained in:
@@ -637,6 +637,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
if (displays.size > 1) return displays[1]
|
||||
return null
|
||||
}
|
||||
|
||||
private val recognizeViewModel by lazy { viewModels<RecognizeViewModel>().value }
|
||||
|
||||
private fun setupSecondaryDisplay() {
|
||||
@@ -948,16 +949,20 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
}
|
||||
viewModel.getFaceIncrementList(
|
||||
pageNo = taskPageNo,
|
||||
timestamp = timestamp
|
||||
) { list ->
|
||||
runOnUiThread {
|
||||
if (list.isEmpty()) {
|
||||
return@runOnUiThread
|
||||
}
|
||||
timestamp = timestamp,
|
||||
onAllQueryFinished = {
|
||||
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
|
||||
updateFaceData(list)
|
||||
},
|
||||
onPageQueryFinished = { list ->
|
||||
runOnUiThread {
|
||||
if (list.isEmpty()) {
|
||||
return@runOnUiThread
|
||||
}
|
||||
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
|
||||
updateFaceData(list)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -247,7 +247,7 @@ interface ApiService {
|
||||
@POST
|
||||
suspend fun uploadCollectFoodPics(
|
||||
// @Url url: String = "http://192.168.1.201:14801/terminal/neglect/dishCollectionVectorData/add",
|
||||
@Url url: String = "http://192.168.1.201:14801/terminal/neglect/boothMachine/app/dishCollectionVectorData/add",
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/boothMachine/app/dishCollectionVectorData/add",
|
||||
@PartMap params: HashMap<String, RequestBody>,
|
||||
@Part foodPics: List<MultipartBody.Part>
|
||||
): ApiResponse<String>
|
||||
|
||||
@@ -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