From aea8351990b16bb11afd9d0ecf4716ba89c2698e Mon Sep 17 00:00:00 2001 From: dongliang Date: Wed, 29 Apr 2026 20:17:43 +0930 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8E=BB=E6=8E=89dotViews=20lazy?= =?UTF-8?q?=E7=BC=93=E5=AD=98=EF=BC=8C=E7=9B=B4=E6=8E=A5=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E5=BD=93=E5=89=8DView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:by lazy只初始化一次,view重建后dotViews缓存的是旧View, renderDots操作的是已销毁的View→红点不显示。 修复:renderDots直接使用dotPool/dotPunch/dotComplete(始终指向当前View)。 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../java/com/xiaoqu/watch/ui/home/HomeFragment.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/xiaoqu/watch/ui/home/HomeFragment.kt b/app/src/main/java/com/xiaoqu/watch/ui/home/HomeFragment.kt index c31ae8d..e89a2db 100644 --- a/app/src/main/java/com/xiaoqu/watch/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/xiaoqu/watch/ui/home/HomeFragment.kt @@ -71,10 +71,6 @@ class HomeFragment : BaseFragment() { private lateinit var dotComplete: View /** 当前应显示红点的卡片集合(累积,只有显式操作才移除) */ private val activeDotCards = mutableSetOf() - /** 红点 View 映射 */ - private val dotViews: Map by lazy { - mapOf(2 to dotPool, 3 to dotPunch, 4 to dotComplete) - } // ===== 设置页 View 引用 ===== private lateinit var tvAvatarLetter: TextView @@ -575,9 +571,10 @@ class HomeFragment : BaseFragment() { /** 统一渲染红点:以 activeDotCards 为唯一数据源 */ private fun renderDots() { - dotViews.forEach { (status, dot) -> - dot.visibility = if (status in activeDotCards) View.VISIBLE else View.GONE - } + dotPool.visibility = if (2 in activeDotCards) View.VISIBLE else View.GONE + dotPunch.visibility = if (3 in activeDotCards) View.VISIBLE else View.GONE + dotComplete.visibility = if (4 in activeDotCards) View.VISIBLE else View.GONE + Timber.d("首页: renderDots 完成 pool=${dotPool.visibility==View.VISIBLE} punch=${dotPunch.visibility==View.VISIBLE} complete=${dotComplete.visibility==View.VISIBLE}") } /** 标记某个分类已查看:从 activeDotCards 移除 + 通知管理器记录 */