fix: 去掉dotViews lazy缓存,直接操作当前View

问题:by lazy只初始化一次,view重建后dotViews缓存的是旧View,
renderDots操作的是已销毁的View→红点不显示。

修复:renderDots直接使用dotPool/dotPunch/dotComplete(始终指向当前View)。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
dongliang
2026-04-29 20:17:43 +09:30
parent 20c8dc2fed
commit aea8351990

View File

@@ -71,10 +71,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
private lateinit var dotComplete: View
/** 当前应显示红点的卡片集合(累积,只有显式操作才移除) */
private val activeDotCards = mutableSetOf<Int>()
/** 红点 View 映射 */
private val dotViews: Map<Int, View> 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<FragmentHomeBinding>() {
/** 统一渲染红点:以 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 移除 + 通知管理器记录 */