优化AI页面资源管理和数据加载
- AgentViewModel:
- 新增 `refreshAgentData` 方法用于刷新推荐Agent数据。
- 新增 `ensureDataLoaded` 方法用于检查推荐Agent数据是否为空,如果为空则重新加载。
- ResourceCleanupManager:
- `cleanupPageResources` 方法新增 `preserveRecommendedData` 参数,用于控制是否保留推荐数据。
- 新增 `cleanupAiPageCompletely` 方法,用于完全清理AI页面资源(包括推荐数据),主要用于登出等场景。
- Agent.kt:
- 在页面进入时调用 `viewModel.ensureDataLoaded()` 确保推荐Agent数据已加载。
- 页面退出时不再清理推荐Agent数据,只在完全登出或需要彻底清理时才清理。
此更改旨在:
- 避免不必要的推荐Agent数据重复加载。
- 优化AI页面退出时的资源清理逻辑,仅在需要时才清理推荐数据。
This commit is contained in:
@@ -62,7 +62,7 @@ object ResourceCleanupManager {
|
||||
// 重置Index相关ViewModel
|
||||
IndexViewModel.ResetModel()
|
||||
|
||||
// 重置AI相关ViewModel
|
||||
// 重置AI相关ViewModel(完全清理,包括推荐数据)
|
||||
AgentViewModel.ResetModel()
|
||||
|
||||
HotAgentViewModel.let {
|
||||
@@ -210,11 +210,15 @@ object ResourceCleanupManager {
|
||||
/**
|
||||
* 清理特定页面的资源
|
||||
* @param pageType 页面类型
|
||||
* @param preserveRecommendedData 是否保留推荐数据,默认为true
|
||||
*/
|
||||
fun cleanupPageResources(pageType: String) {
|
||||
fun cleanupPageResources(pageType: String, preserveRecommendedData: Boolean = true) {
|
||||
when (pageType) {
|
||||
"ai" -> {
|
||||
AgentViewModel.ResetModel()
|
||||
// 如果需要保留推荐数据,则不重置AgentViewModel(它包含推荐Agent数据)
|
||||
if (!preserveRecommendedData) {
|
||||
AgentViewModel.ResetModel()
|
||||
}
|
||||
HotAgentViewModel.let {
|
||||
it.agentList = emptyList()
|
||||
it.refreshing = false
|
||||
@@ -243,4 +247,11 @@ object ResourceCleanupManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 完全清理AI页面资源(包括推荐数据),用于登出等场景
|
||||
*/
|
||||
fun cleanupAiPageCompletely() {
|
||||
cleanupPageResources("ai", preserveRecommendedData = false)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user