From e8e67b74cd1c6f38ad46003b0732e0b5543e1161 Mon Sep 17 00:00:00 2001 From: QIU Date: Wed, 26 Aug 2026 01:35:02 +0000 Subject: [PATCH] fix(sources): the custom-source switch stopped turning itself off Two defects in how the data source settings were read. The switch reported a state nobody had chosen. `useCustomTLE` was ANDed with `tleUrl != Sources.defaultTleUrl`, so an operator who enabled custom sources and then typed the default URL by hand saw the switch flip itself off. It now reports what they set. The example.com placeholder rewrite ran on every read. A 4.4.7-era build could persist `https://example.com/tle.txt`, and the fix for that rewrote the value each time it was read - so the stored value and the returned value disagreed indefinitely and nothing ever settled it. It is now a one-time migration following migrateRCFormats, which writes the correction back and records that it has run. Not addressed here, and the reason the settings screen still misleads: a custom TLE URL replaces only the source keyed "All" and the other 27 hardcoded sources are still fetched unconditionally, so "use custom sources" actually means "my source plus 27 others". Which way that should go is a decision about intent rather than a defect to patch, and upstream fetches all of its sources unconditionally, which is where the behaviour came from. --- .../core/data/repository/SettingsRepo.kt | 46 +++++++++++++++---- 1 file changed, 36 insertions(+), 10 deletions(-) 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 d908e63a..a7daad2a 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 @@ -455,18 +455,44 @@ class SettingsRepo( _dataSourcesSettings.value = settings } + /** Placeholders a 4.4.7-era build could persist. Neither is a reachable address. */ + private val placeholderTleUrl = "https://example.com/tle.txt" + private val placeholderRadioUrl = "https://example.com/radio.json" + private val keyPlaceholderUrlsMigrated = "placeholderUrlsMigrated" + + /** + * Replace the example.com placeholders an old build could store. + * + * Runs once, following the pattern of migrateRCFormats. This used to be a rewrite applied on + * every read, so the stored value and the returned value disagreed indefinitely and nothing + * ever settled the difference. + */ + private fun migratePlaceholderUrls() { + if (preferences.getBoolean(keyPlaceholderUrlsMigrated, false)) return + preferences.edit { + if (preferences.getString(keyTleUrl, null) == placeholderTleUrl) { + putString(keyTleUrl, Sources.defaultTleUrl) + putBoolean(keyUseCustomTle, false) + } + if (preferences.getString(keyTransceiversUrl, null) == placeholderRadioUrl) { + putString(keyTransceiversUrl, Sources.defaultTransceiversUrl) + putBoolean(keyUseCustomTransceivers, false) + } + putBoolean(keyPlaceholderUrlsMigrated, true) + } + } + private fun getDataSourcesSettings(): DataSourcesSettings { - // 4.4.8 fix: legacy example.com placeholder URLs count as unconfigured -> replaced with the real default URL and the switch forced off, - // otherwise the online All/SatNOGS sources would point at the wrong address and fail to update - val storedTleUrl = preferences.getString(keyTleUrl, Sources.defaultTleUrl) ?: Sources.defaultTleUrl - val storedTxUrl = preferences.getString(keyTransceiversUrl, Sources.defaultTransceiversUrl) ?: Sources.defaultTransceiversUrl - val tleUrl = if (storedTleUrl == "https://example.com/tle.txt") Sources.defaultTleUrl else storedTleUrl - val txUrl = if (storedTxUrl == "https://example.com/radio.json") Sources.defaultTransceiversUrl else storedTxUrl + migratePlaceholderUrls() + // The switch is reported as the operator set it. It used to be ANDed with + // `url != default`, so typing the default URL by hand switched custom sources off by + // itself and the settings screen showed a state nobody had chosen. return DataSourcesSettings( - useCustomTLE = preferences.getBoolean(keyUseCustomTle, false) && tleUrl != Sources.defaultTleUrl, - useCustomTransceivers = preferences.getBoolean(keyUseCustomTransceivers, false) && txUrl != Sources.defaultTransceiversUrl, - tleUrl = tleUrl, - transceiversUrl = txUrl + useCustomTLE = preferences.getBoolean(keyUseCustomTle, false), + useCustomTransceivers = preferences.getBoolean(keyUseCustomTransceivers, false), + tleUrl = preferences.getString(keyTleUrl, Sources.defaultTleUrl) ?: Sources.defaultTleUrl, + transceiversUrl = preferences.getString(keyTransceiversUrl, Sources.defaultTransceiversUrl) + ?: Sources.defaultTransceiversUrl ) }