From 1e33a10fb48220a4ad14a73be12cf51c42042bf8 Mon Sep 17 00:00:00 2001 From: atsunatsu Date: Sun, 4 Oct 2026 02:32:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(satellites):=20All=20=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=90=8D=E5=8D=95=E4=B8=BA=E7=A9=BA=E6=97=B6=E5=9B=9E=E9=80=80?= =?UTF-8?q?=E4=B8=BA=E4=B8=8D=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CelesTrak 对重复下载(2 小时内数据未更新)返回 403,同步会把该源的 type id 名单写成空串,选 All 时 resolveTypeIds 得空集 → 列表一条不剩。 现在只有 "All"(= CelesTrak active 全集)在名单为空时回退为不筛选(显示 全部卫星);其它源名类型与三个虚拟类型(AMSAT Live FM/Linear、Live SSTV) 保持"空即显示空"。Sources 增加 allSourceType 常量并注明背景。 Tests: SelectionRepoSearchTest 新增 2 例(All 空→显示全部、其它源空→仍空) --- .../core/data/repository/SelectionRepo.kt | 10 ++++++++- .../repository/SelectionRepoSearchTest.kt | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SelectionRepo.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SelectionRepo.kt index a69f74d3..2f961397 100644 --- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SelectionRepo.kt +++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SelectionRepo.kt @@ -51,7 +51,15 @@ class SelectionRepo( null // null = no filtering } else { val ids = resolveTypeIds(types) - if (ids.isEmpty()) emptySet() else ids.toHashSet() + when { + ids.isNotEmpty() -> ids.toHashSet() + // "All" is the CelesTrak active group, i.e. the whole catalogue: an empty + // persisted list must mean "no filtering" (show every satellite), not an + // empty list. Its list can be empty simply because CelesTrak answered 403 + // to a repeated download inside the 2-hour update window. + Sources.allSourceType in types -> null + else -> emptySet() + } } currentItems.map { items -> if (catnumSet == null) items else items.filter { it.catnum in catnumSet } diff --git a/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/SelectionRepoSearchTest.kt b/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/SelectionRepoSearchTest.kt index 8a961265..5ad6d52f 100644 --- a/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/SelectionRepoSearchTest.kt +++ b/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/SelectionRepoSearchTest.kt @@ -23,6 +23,7 @@ import com.rtbishop.look4sat.core.domain.predict.OrbitalObject import com.rtbishop.look4sat.core.domain.repository.ISelectionRepo import com.rtbishop.look4sat.core.domain.repository.ISettingsRepo import com.rtbishop.look4sat.core.domain.source.ILocalSource +import com.rtbishop.look4sat.core.domain.source.Sources import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow @@ -241,6 +242,26 @@ class SelectionRepoSearchTest { assertEquals(sampleItems.map { it.catnum }.toSet(), results.map { it.catnum }.toSet()) } + @Test + fun `All with empty persisted ids falls back to no filtering`() = runTest { + // CelesTrak answers 403 to a repeated download inside its 2-hour update window, + // so the persisted "All" id list can be empty. Selecting All then means "all + // satellites" (no filtering) instead of blanking the list. + val repo = createRepo(sampleItems) + repo.setTypes(listOf(Sources.allSourceType)) + val results = repo.getEntriesFlow().first() + assertEquals(sampleItems.map { it.catnum }.toSet(), results.map { it.catnum }.toSet()) + } + + @Test + fun `other source type with empty persisted ids still shows empty`() = runTest { + // Only "All" falls back to no filtering; a regular source without persisted ids + // keeps the previous behaviour (empty list). + val repo = createRepo(sampleItems) + repo.setTypes(listOf("Amateur")) + assertTrue(repo.getEntriesFlow().first().isEmpty()) + } + @Test fun `getTypesList excludes only the Other placeholder`() = runTest { val repo = createRepo(sampleItems)