2 Commits
Author SHA1 Message Date
lvmengandClaude Sonnet 4.6 c23c215941 fix: 修复 noDataWatchdogTask 潜在的内存泄漏问题
在 Runnable 中添加生命周期检查,防止 Activity 销毁后任务继续执行。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-01 17:58:22 +08:00
lvmengandClaude Sonnet 4.6 3d67dd2c2d refactor: 优化货架列表转换逻辑并支持奇数长度处理
- 移除 subList 创建,直接通过索引访问元素
- 修复奇数长度列表的处理逻辑
- 保持单次循环,提升性能

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-01 17:53:00 +08:00
@@ -231,11 +231,15 @@ class HomeActivity : BaseActivity() {
return
}
list.clear()
val subList01 = tempList.subList(0, tempList.size / 2)
val subList02 = tempList.subList(tempList.size / 2, tempList.size)
repeat(tempList.size / 2) { index ->
list.add(subList01[index].also { it.deviceId = App.deviceId })
list.add(subList02[index].also { it.deviceId = App.deviceId })
val leftSize = (tempList.size + 1) / 2 // 左列长度(向上取整)
val rightSize = tempList.size / 2 // 右列长度(向下取整)
repeat(rightSize) { index ->
list.add(tempList[index].also { it.deviceId = App.deviceId })
list.add(tempList[leftSize + index].also { it.deviceId = App.deviceId })
}
// 处理奇数长度:左列比右列多一个
if (tempList.size % 2 != 0) {
list.add(tempList[rightSize].also { it.deviceId = App.deviceId })
}
shelfAdapter.notifyDataSetChanged()
}
@@ -269,6 +273,9 @@ class HomeActivity : BaseActivity() {
*/
private val noDataWatchdogTask = object : Runnable {
override fun run() {
// 生命周期检查,防止 Activity 销毁后继续执行
if (isFinishing || isDestroyed) return
val elapsed = System.currentTimeMillis() - lastDataReceivedTime
if (elapsed >= 5 * 60 * 1000L) {
if (noDataWarningDialog == null) {