增量分页优化

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> <selectionStates>
<SelectionState runConfigName="app"> <SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" /> <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"> <Target type="DEFAULT_BOOT">
<handle> <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> </handle>
</Target> </Target>
</DropdownSelection> </DropdownSelection>
@@ -637,6 +637,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
if (displays.size > 1) return displays[1] if (displays.size > 1) return displays[1]
return null return null
} }
private val recognizeViewModel by lazy { viewModels<RecognizeViewModel>().value } private val recognizeViewModel by lazy { viewModels<RecognizeViewModel>().value }
private fun setupSecondaryDisplay() { private fun setupSecondaryDisplay() {
@@ -948,8 +949,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
} }
viewModel.getFaceIncrementList( viewModel.getFaceIncrementList(
pageNo = taskPageNo, pageNo = taskPageNo,
timestamp = timestamp timestamp = timestamp,
) { list -> onAllQueryFinished = {
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
},
onPageQueryFinished = { list ->
runOnUiThread { runOnUiThread {
if (list.isEmpty()) { if (list.isEmpty()) {
return@runOnUiThread return@runOnUiThread
@@ -958,6 +962,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
updateFaceData(list) updateFaceData(list)
} }
} }
)
} }
} }
@@ -247,7 +247,7 @@ interface ApiService {
@POST @POST
suspend fun uploadCollectFoodPics( 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/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>, @PartMap params: HashMap<String, RequestBody>,
@Part foodPics: List<MultipartBody.Part> @Part foodPics: List<MultipartBody.Part>
): ApiResponse<String> ): ApiResponse<String>
@@ -97,10 +97,10 @@ class UserViewModel : BaseViewModel() {
withContext(Dispatchers.Default) { withContext(Dispatchers.Default) {
val list: List<UserFaceModel> = response.data ?: emptyList() val list: List<UserFaceModel> = response.data ?: emptyList()
if (list.isEmpty()) { if (list.isEmpty()) {
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
ToastUtils.showToast("查询人脸数据为空") ToastUtils.showToast("查询人脸数据为空")
return@withContext return@withContext
} }
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
// val item = list.firstOrNull { it.userId == "1951105919342936066" } // val item = list.firstOrNull { it.userId == "1951105919342936066" }
// Timber.tag(TAG).d("getUserFaceCache userId = ${item?.userId}") // Timber.tag(TAG).d("getUserFaceCache userId = ${item?.userId}")
val faceEntity = list.map { val faceEntity = list.map {
@@ -111,6 +111,7 @@ class UserViewModel : BaseViewModel() {
currentPageNo++ currentPageNo++
getUserFaceCache(currentPageNo) getUserFaceCache(currentPageNo)
} else { } else {
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
_loadFaceResult.value = true _loadFaceResult.value = true
} }
} }
@@ -156,7 +157,8 @@ class UserViewModel : BaseViewModel() {
pageNo: Int = 1, pageNo: Int = 1,
pageSize: Int = PAGE_SIZE, pageSize: Int = PAGE_SIZE,
timestamp: Long, timestamp: Long,
block: (List<UserFaceModel>) -> Unit onAllQueryFinished:()->Unit,
onPageQueryFinished: (List<UserFaceModel>) -> Unit
) { ) {
Timber.tag(TAG).d("getFaceIncrementList") Timber.tag(TAG).d("getFaceIncrementList")
launch { launch {
@@ -168,7 +170,18 @@ class UserViewModel : BaseViewModel() {
if (parseResponse(response)) { if (parseResponse(response)) {
withContext(Dispatchers.Default) { withContext(Dispatchers.Default) {
val list: List<UserFaceModel> = response.data ?: emptyList() 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()
}
} }
} }
} }