From ee3db85233ece486e4774aa249336d55815be455 Mon Sep 17 00:00:00 2001 From: reveler-hub Date: Fri, 4 Sep 2026 17:57:47 +1200 Subject: [PATCH] Fix alerts-only country-recommended sources leaking into weather picker WeatherSourcesForLocationSheet's recommendedSources list wasn't filtered by Capability.WEATHER (unlike its globalSources list), so an alerts-only source recommended for a country could appear, and even get auto-selected, as a weather source. Every country's recommended source has so far also been a weather source, so this never surfaced until an alerts-only country-recommended source existed. Also make new-location alert-source selection fall back to the country's recommended alerts source when the chosen weather source isn't itself alerts-capable, instead of only pairing alerts when the weather source happens to be self-paired. --- .../feature/search/SearchScreenViewModel.kt | 5 ++++- .../feature/shared/ui/SharedBottomSheets.kt | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/feature/search/SearchScreenViewModel.kt b/app/src/main/java/com/pranshulgg/weather_master_app/feature/search/SearchScreenViewModel.kt index d17eef1ea..eed76391a 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/feature/search/SearchScreenViewModel.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/feature/search/SearchScreenViewModel.kt @@ -9,6 +9,7 @@ import androidx.lifecycle.viewModelScope import com.pranshulgg.weather_master_app.R import com.pranshulgg.weather_master_app.core.model.sources.Capability import com.pranshulgg.weather_master_app.core.model.sources.SearchSource +import com.pranshulgg.weather_master_app.core.model.sources.getSourcesForCountry import com.pranshulgg.weather_master_app.core.model.domain.location.Location import com.pranshulgg.weather_master_app.core.model.domain.toAppException import com.pranshulgg.weather_master_app.core.model.domain.toMessageRes @@ -84,7 +85,9 @@ class SearchScreenViewModel @Inject constructor( val alertSource = if (Capability.ALERTS in weatherSource.capabilities) { weatherSource } else { - resolved.alertSource + getSourcesForCountry(resolved.countryCode?.uppercase()) + .firstOrNull { Capability.ALERTS in it.capabilities } + ?: resolved.alertSource } locationsRepo.saveLocation(resolved.copy(source = weatherSource, alertSource = alertSource)) onBack() diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/ui/SharedBottomSheets.kt b/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/ui/SharedBottomSheets.kt index 82435d0ed..b6be39e9f 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/ui/SharedBottomSheets.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/feature/shared/ui/SharedBottomSheets.kt @@ -55,6 +55,7 @@ object SharedBottomSheet { ) { if (show) { val recommendedSources = getSourcesForCountry(countryCode?.uppercase()) + .filter { Capability.WEATHER in it.capabilities } val globalSources = getSourcesGlobal().filter { Capability.WEATHER in it.capabilities } val isApiKeyAvailable: (Source) -> Boolean = { source ->