From 8d88100b15a8d96079ce661098c5ac60bea1c06b Mon Sep 17 00:00:00 2001 From: QIU Date: Mon, 3 Aug 2026 16:41:14 +0000 Subject: [PATCH] feat(settings): custom URL now overrides the online-update default source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "Custom URL" dialog's two URL fields now control the default source used by the online update, per the user's intent (one-time setup, no extra steps per update): - Defaults are real URLs now: TLE = Celestrak "All" (active group CSV), transceivers = SatNOGS API. The example.com placeholders are gone. - updateFromRemote(): the "All" TLE entry and the "SatNOGS" entry are replaced by the user's URLs when the corresponding custom toggle is ON and the URL is non-blank; otherwise the real defaults are used. The old "Other" appended-source logic is removed - the toggle now means "use my URL for this source" instead of "download an extra source". Each source (TLE / transceivers) is independent. - Each URL field gained a reset (loop) icon button on the right that restores the default URL text (new ic_reset drawable, Autorenew vector). Strings added in en/zh/tr. Test updated: custom TLE URL data now lands under the "All" type instead of "Other". Verified: core:data tests pass, settings + app compile. Version stays 4.4.8 (覆盖 per user). --- .../core/data/repository/DatabaseRepo.kt | 7 +++++-- .../core/data/repository/SettingsRepo.kt | 5 +++-- .../core/data/repository/DatabaseRepoTest.kt | 3 ++- .../look4sat/core/domain/source/Sources.kt | 4 ++++ .../src/main/res/drawable/ic_reset.xml | 11 ++++++++++ .../src/main/res/values-tr/strings.xml | 1 + .../src/main/res/values/strings.xml | 1 + .../feature/settings/SettingsDialog.kt | 20 +++++++++++++++++++ 8 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 core/presentation/src/main/res/drawable/ic_reset.xml diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/DatabaseRepo.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/DatabaseRepo.kt index 8decc7a6..5b0a0998 100644 --- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/DatabaseRepo.kt +++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/DatabaseRepo.kt @@ -69,11 +69,14 @@ class DatabaseRepo( val dataSourcesSettings = settingsRepo.dataSourcesSettings.value val tleUrls = buildMap { putAll(Sources.satelliteDataUrls) - if (dataSourcesSettings.useCustomTLE) put(customSourceType, dataSourcesSettings.tleUrl) + // 开关开且 URL 非空 -> All 用自定义 URL;否则用默认 URL(在线更新默认源) + put("All", if (dataSourcesSettings.useCustomTLE && dataSourcesSettings.tleUrl.isNotBlank()) + dataSourcesSettings.tleUrl else Sources.defaultTleUrl) }.filterValues { it.isNotBlank() } val radioUrls = buildMap { putAll(Sources.transceiversDataUrls) - if (dataSourcesSettings.useCustomTransceivers) put(customSourceType, dataSourcesSettings.transceiversUrl) + put("SatNOGS", if (dataSourcesSettings.useCustomTransceivers && dataSourcesSettings.transceiversUrl.isNotBlank()) + dataSourcesSettings.transceiversUrl else Sources.defaultTransceiversUrl) }.filterValues { it.isNotBlank() } // launch all network requests concurrently val tleJobs = tleUrls.values.map { url -> async { url to remoteSource.getNetworkStream(url) } } diff --git a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SettingsRepo.kt b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SettingsRepo.kt index 815fb997..77651950 100644 --- a/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SettingsRepo.kt +++ b/core/data/src/main/java/com/rtbishop/look4sat/core/data/repository/SettingsRepo.kt @@ -29,6 +29,7 @@ import com.rtbishop.look4sat.core.domain.model.OtherSettings import com.rtbishop.look4sat.core.domain.model.PassesSettings import com.rtbishop.look4sat.core.domain.model.RCSettings import com.rtbishop.look4sat.core.domain.model.RadioControlSettings +import com.rtbishop.look4sat.core.domain.source.Sources import com.rtbishop.look4sat.core.domain.predict.GeoPos import com.rtbishop.look4sat.core.domain.repository.ISettingsRepo import com.rtbishop.look4sat.core.domain.utility.positionToQth @@ -393,8 +394,8 @@ class SettingsRepo( private fun getDataSourcesSettings(): DataSourcesSettings = DataSourcesSettings( useCustomTLE = preferences.getBoolean(keyUseCustomTle, false), useCustomTransceivers = preferences.getBoolean(keyUseCustomTransceivers, false), - tleUrl = preferences.getString(keyTleUrl, "https://example.com/tle.txt") ?: "", - transceiversUrl = preferences.getString(keyTransceiversUrl, "https://example.com/radio.json") ?: "" + tleUrl = preferences.getString(keyTleUrl, Sources.defaultTleUrl) ?: "", + transceiversUrl = preferences.getString(keyTransceiversUrl, Sources.defaultTransceiversUrl) ?: "" ) //endregion diff --git a/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/DatabaseRepoTest.kt b/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/DatabaseRepoTest.kt index a14ede56..57d33998 100644 --- a/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/DatabaseRepoTest.kt +++ b/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/DatabaseRepoTest.kt @@ -102,7 +102,8 @@ class DatabaseRepoTest { repository.updateFromRemote() assertTrue(localSource.insertedEntries.any { it.catnum == 25544 }) - assertEquals(listOf(25544), settingsRepo.satelliteTypeIdsByType["Other"]) + // 新语义: 开关开 + URL 非空 -> All 源用自定义 URL, 数据归入 All 类型 + assertEquals(listOf(25544), settingsRepo.satelliteTypeIdsByType["All"]) } private fun validCsvStream(): InputStream = """ diff --git a/core/domain/src/main/java/com/rtbishop/look4sat/core/domain/source/Sources.kt b/core/domain/src/main/java/com/rtbishop/look4sat/core/domain/source/Sources.kt index 17c91e34..ddc4a0de 100644 --- a/core/domain/src/main/java/com/rtbishop/look4sat/core/domain/source/Sources.kt +++ b/core/domain/src/main/java/com/rtbishop/look4sat/core/domain/source/Sources.kt @@ -18,6 +18,10 @@ package com.rtbishop.look4sat.core.domain.source object Sources { + // 在线更新的默认 URL(用户可通过"自定义URL"对话框修改/重置) + val defaultTleUrl = "https://celestrak.org/NORAD/elements/gp.php?GROUP=active&FORMAT=csv" + val defaultTransceiversUrl = "https://db.satnogs.org/api/transmitters/?format=json&status=active" + val satelliteDataUrls = mapOf( "All" to "https://celestrak.org/NORAD/elements/gp.php?GROUP=active&FORMAT=csv", "Amateur" to "https://celestrak.org/NORAD/elements/gp.php?GROUP=amateur&FORMAT=csv", diff --git a/core/presentation/src/main/res/drawable/ic_reset.xml b/core/presentation/src/main/res/drawable/ic_reset.xml new file mode 100644 index 00000000..6dcfedb1 --- /dev/null +++ b/core/presentation/src/main/res/drawable/ic_reset.xml @@ -0,0 +1,11 @@ + + + + diff --git a/core/presentation/src/main/res/values-tr/strings.xml b/core/presentation/src/main/res/values-tr/strings.xml index ab64b518..6e116397 100644 --- a/core/presentation/src/main/res/values-tr/strings.xml +++ b/core/presentation/src/main/res/values-tr/strings.xml @@ -147,6 +147,7 @@ Özel TLE URL Özel transceiver URL URL (HTTPS) + Varsayılan URL\'ye sıfırla Veri aktarımı Ağ diff --git a/core/presentation/src/main/res/values/strings.xml b/core/presentation/src/main/res/values/strings.xml index b4f0d5c1..030581dd 100644 --- a/core/presentation/src/main/res/values/strings.xml +++ b/core/presentation/src/main/res/values/strings.xml @@ -161,6 +161,7 @@ Custom TLE URL Custom transceivers URL URL (HTTPS) + Reset to default URL Data output Network diff --git a/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsDialog.kt b/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsDialog.kt index c0897b4d..203df29d 100644 --- a/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsDialog.kt +++ b/feature/settings/src/main/java/com/rtbishop/look4sat/feature/settings/SettingsDialog.kt @@ -30,6 +30,8 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.material3.FilterChip +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Switch import androidx.compose.material3.Text @@ -41,11 +43,13 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource +import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.rtbishop.look4sat.core.domain.model.RCSettings +import com.rtbishop.look4sat.core.domain.source.Sources import com.rtbishop.look4sat.core.domain.model.RadioControlSettings import com.rtbishop.look4sat.core.presentation.CardButton import com.rtbishop.look4sat.core.presentation.LocalSpacing @@ -203,6 +207,14 @@ fun DataSourcesDialog( singleLine = true, modifier = Modifier.fillMaxWidth(), enabled = isEnabledCustomTle.value, + trailingIcon = { + IconButton(onClick = { urlTle.value = Sources.defaultTleUrl }) { + Icon( + painter = painterResource(id = R.drawable.ic_reset), + contentDescription = stringResource(id = R.string.prefs_data_reset_url) + ) + } + }, ) Spacer(modifier = Modifier.height(6.dp)) Row( @@ -232,6 +244,14 @@ fun DataSourcesDialog( singleLine = true, modifier = Modifier.fillMaxWidth(), enabled = isEnabledCustomTransceivers.value, + trailingIcon = { + IconButton(onClick = { urlTransceivers.value = Sources.defaultTransceiversUrl }) { + Icon( + painter = painterResource(id = R.drawable.ic_reset), + contentDescription = stringResource(id = R.string.prefs_data_reset_url) + ) + } + }, ) Spacer(modifier = Modifier.height(12.dp)) }