增量分页优化

This commit is contained in:
2025-12-29 14:08:04 +08:00
parent bb4230419a
commit 7374f279b4
4 changed files with 32 additions and 14 deletions
+2 -2
View File
@@ -4,10 +4,10 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2025-12-17T09:12:02.352767500Z">
<DropdownSelection timestamp="2025-12-26T06:22:06.750685100Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="Default" identifier="serial=192.168.1.118:5555;connection=50c01ec0" />
<DeviceId pluginId="Default" identifier="serial=192.168.1.2:5555;connection=bfafe870" />
</handle>
</Target>
</DropdownSelection>
@@ -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()
}
}
}
}