Reset ViewModels on logout/account switch
This commit introduces a `ResetModel()` function to `AgentViewModel` and `MineAgentViewModel` to clear their state. This function is now called in `ResourceCleanupManager` and `AppState` during logout or when switching accounts to ensure that data from the previous session is not retained. Additionally, the search and group name input fields in `CreateGroupChatScreen` are now single-line.
This commit is contained in:
@@ -95,4 +95,14 @@ object AgentViewModel: ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置ViewModel状态,用于登出或切换账号时清理数据
|
||||
*/
|
||||
fun ResetModel() {
|
||||
agentItems = emptyList()
|
||||
errorMessage = null
|
||||
isRefreshing = false
|
||||
isLoading = false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -139,5 +139,23 @@ object MineAgentViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置ViewModel状态,用于登出或切换账号时清理数据
|
||||
*/
|
||||
fun ResetModel() {
|
||||
// 重置状态变量
|
||||
refreshing = false
|
||||
isLoading = false
|
||||
hasNext = true
|
||||
currentPage = 1
|
||||
error = null
|
||||
isFirstLoad = true
|
||||
|
||||
// 清除预加载的图片ID
|
||||
preloadedImageIds.clear()
|
||||
|
||||
// 清空PagingData
|
||||
_agentList.value = PagingData.empty()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user