refactor(utils): 重构 FoodVectorTool 并优化 zero() 提示控制
- 重构 FoodVectorTool:移除单例 pageNum 状态污染问题,分页逻辑下沉为私有 fetchPage,saveFoodVector 改为私有,PAGE_SIZE 移入内部定义,对外统一暴露 loadAndSaveFoodVector 接口 - 更新 InitActivity、MainActivity 调用方,移除重复的 onPageFinish 回调 - SensorScaleUtils.zero() 新增 isShowToastRemind 可选参数,支持按需显示标定成功提示 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,10 +13,7 @@ import com.sw.dualscreen.dialog.RemindDialog
|
||||
import com.sw.dualscreen.ext.clickWithDebounce
|
||||
import com.sw.dualscreen.ext.invisible
|
||||
import com.sw.dualscreen.ext.visible
|
||||
import com.sw.dualscreen.model.response.FoodVector
|
||||
import com.sw.dualscreen.objbox.Food
|
||||
import com.sw.dualscreen.objbox.FoodModule
|
||||
import com.sw.dualscreen.objbox.ObjectBox
|
||||
import com.sw.dualscreen.utils.FoodVectorTool
|
||||
import com.sw.dualscreen.utils.L
|
||||
import com.sw.dualscreen.utils.NetworkUtils
|
||||
@@ -42,43 +39,11 @@ class InitActivity : BaseActivity<ActivityInitBinding>() {
|
||||
}
|
||||
|
||||
private fun getCollectedFoodVector(block: () -> Unit) {
|
||||
// userViewModel.getCollectedFoodVector(
|
||||
// param = mutableMapOf(
|
||||
// "pageNum" to "$pageNum",
|
||||
// "pageSize" to "$PAGE_SIZE",
|
||||
// "version" to GlobalData.foodModelVersion
|
||||
// )
|
||||
// ) { items ->
|
||||
// if (items == null) {
|
||||
// getVectorErrorDialog()
|
||||
// return@getCollectedFoodVector
|
||||
// }
|
||||
// val list = items
|
||||
// if (pageNum == 1 && list.isEmpty()) {
|
||||
// block()
|
||||
// return@getCollectedFoodVector
|
||||
// }
|
||||
// if (list.size >= PAGE_SIZE) {
|
||||
// saveFoodVector(list)
|
||||
// pageNum++
|
||||
// getCollectedFoodVector(block)
|
||||
// return@getCollectedFoodVector
|
||||
// }
|
||||
// if (list.isNotEmpty()) {
|
||||
// saveFoodVector(list)
|
||||
// block()
|
||||
// }
|
||||
// }
|
||||
|
||||
FoodVectorTool.getFoodVector(
|
||||
userViewModel,
|
||||
onPageFinish = { list ->
|
||||
list?.let { FoodVectorTool.saveFoodVector(lifecycleScope,list) }
|
||||
}, successBlock = {
|
||||
block()
|
||||
}, failureBlock = {
|
||||
getVectorErrorDialog()
|
||||
}
|
||||
FoodVectorTool.loadAndSaveFoodVector(
|
||||
userViewModel = userViewModel,
|
||||
lifecycleScope = lifecycleScope,
|
||||
successBlock = { block() },
|
||||
failureBlock = { getVectorErrorDialog() }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -215,19 +215,16 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
lifecycleScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
FaceServer.getInstance().clearAllFaces()
|
||||
}
|
||||
withContext(Dispatchers.IO) {
|
||||
ObjectBox.removeAll()
|
||||
}
|
||||
FoodVectorTool.getFoodVector(
|
||||
FoodVectorTool.loadAndSaveFoodVector(
|
||||
userViewModel = viewModel,
|
||||
onPageFinish = { list ->
|
||||
list?.let { FoodVectorTool.saveFoodVector(lifecycleScope,list) }
|
||||
},
|
||||
lifecycleScope = lifecycleScope,
|
||||
successBlock = {
|
||||
viewModel.getUserFaceCache(pageNo = 1)
|
||||
}, failureBlock = {
|
||||
hideWaitingDialog() // 显示提示信息
|
||||
},
|
||||
failureBlock = {
|
||||
hideWaitingDialog()
|
||||
ToastUtils.showToast(it)
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user