refactor(chat): 优化加载视图显示逻辑
- 提取加载视图更新逻辑到独立方法 updateLoadingViews - 根据是否有问题内容决定是否显示加载动画 - 简化条件判断逻辑,提高代码可读性 - 保持滚动到底部功能的一致性调用
这个提交包含在:
父节点
e589fcd769
当前提交
9376f1665b
@ -35,6 +35,8 @@ class ChatActivity : BaseListFormLayoutNormalActivity<ChatItem, ChatVM, Activity
|
||||
|
||||
override fun initData() {
|
||||
super.initData()
|
||||
val question = intent.getStringExtra("question") ?: ""
|
||||
val hasQuestion = question.isNotEmpty()
|
||||
|
||||
// SSE 流式内容更新时持续滚底
|
||||
viewModel.result.observe(this) {
|
||||
@ -43,20 +45,26 @@ class ChatActivity : BaseListFormLayoutNormalActivity<ChatItem, ChatVM, Activity
|
||||
|
||||
// loading=true:显示旋转进度;loading=false:显示静态占位图
|
||||
val isLoading = viewModel.loading.value ?: false
|
||||
binding.loadingProgress.visibility = if (isLoading) View.VISIBLE else View.GONE
|
||||
binding.loadingIdleIcon.visibility = if (isLoading) View.GONE else View.VISIBLE
|
||||
updateLoadingViews(isLoading, hasQuestion)
|
||||
viewModel.loading.observe(this) { loading ->
|
||||
binding.loadingProgress.visibility = if (loading) View.VISIBLE else View.GONE
|
||||
binding.loadingIdleIcon.visibility = if (loading) View.GONE else View.VISIBLE
|
||||
updateLoadingViews(loading, hasQuestion)
|
||||
recyclerView.post { scrollToBottom() }
|
||||
}
|
||||
|
||||
val question = intent.getStringExtra("question") ?: ""
|
||||
if (question.isNotEmpty()) {
|
||||
if (hasQuestion) {
|
||||
viewModel.prepareTopic(question)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateLoadingViews(loading: Boolean, hasQuestion: Boolean) {
|
||||
if (!hasQuestion) {
|
||||
binding.loadingProgress.visibility = View.GONE
|
||||
binding.loadingIdleIcon.visibility = View.VISIBLE
|
||||
return
|
||||
}
|
||||
binding.loadingProgress.visibility = if (loading) View.VISIBLE else View.GONE
|
||||
binding.loadingIdleIcon.visibility = if (loading) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
||||
private fun recognizeAndChat() {
|
||||
// 识别由 AsrHelper 在 onFinalResult 中统一触发,此处无需主动发起
|
||||
}
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户