an error if the currently selected source isn't available for the region closes #960

This commit is contained in:
PranshulGG committed 2026-07-16 10:05:17 +05:30
1 parent 2bbb2c8537
commit cd7ba2d878
5 files changed
+62 -4

No files matched your search

@@ -107,4 +107,10 @@ private val weatherSourcesGlobal = listOf(
fun getWeatherSourcesGlobal(): List<WeatherSource> {
return weatherSourcesGlobal
}
fun WeatherSource.isSupportedFor(countryCode: String?): Boolean {
val source = weatherSourcesByCountry[countryCode] ?: emptyList()
return source.isNotEmpty()
}
@@ -1,6 +1,7 @@
package com.pranshulgg.weather_master_app.feature.main
import android.util.Log
import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.ExperimentalMaterial3Api
@@ -32,6 +33,7 @@ import com.pranshulgg.weather_master_app.core.ui.snackbar.SnackbarManager
import com.pranshulgg.weather_master_app.feature.intro.IntroScreen
import com.pranshulgg.weather_master_app.feature.locations.LocationsScreen
import com.pranshulgg.weather_master_app.feature.main.ui.MainScreenBottomSheets
import com.pranshulgg.weather_master_app.feature.main.ui.MainScreenDialogs
import com.pranshulgg.weather_master_app.feature.main.ui.NavigationDrawer
import com.pranshulgg.weather_master_app.feature.shared.WeatherViewModel
import com.pranshulgg.weather_master_app.feature.shared.ui.SharedBottomSheet
@@ -47,14 +49,16 @@ data class MainScreenWeatherUiState(
val blocks: List<WeatherBlock> = WeatherBlock.getDefault(),
val isInitialized: Boolean = false,
val airQuality: AirQuality? = null,
val isAirQualityLoading: Boolean = false
val isAirQualityLoading: Boolean = false,
val isUnsupportedSource: Boolean = false
)
data class MainScreenUiState(
val isWeatherSourcesForLocationSheetOpen: Boolean = false,
val isWeatherSourcesInfoForLocationSheetOpen: Boolean = false,
val isNewVersionAvailable: Boolean = false,
val lastestVersionUrl: String = "https://github.com/PranshulGG/WeatherMaster/releases/latest"
val lastestVersionUrl: String = "https://github.com/PranshulGG/WeatherMaster/releases/latest",
val isUnsupportedSourceDialogOpen: Boolean = false
)
@OptIn(ExperimentalMaterial3Api::class)
@@ -92,6 +96,7 @@ fun MainScreen(navController: NavController) {
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
val scope = rememberCoroutineScope()
val closeDrawer = {
scope.launch { drawerState.close() }
}
@@ -103,6 +108,12 @@ fun MainScreen(navController: NavController) {
closeDrawer()
}
LaunchedEffect(uiState.isUnsupportedSource) {
if (uiState.isUnsupportedSource) {
viewModel.showUnsupportedSelectedSourceDialog()
}
}
LaunchedEffect(mainScreenUiState.isNewVersionAvailable) {
if (mainScreenUiState.isNewVersionAvailable) {
SnackbarManager.show(
@@ -182,6 +193,13 @@ fun MainScreen(navController: NavController) {
// WEATHER SOURCES INFO DIALOG
MainScreenBottomSheets.WeatherSourcesInfoForLocationSheet(viewModel, activeLocation, sheetState)
// SOURCE NOT AVAILABLE
MainScreenDialogs.UnsupportedSelectedSourceDialog(
mainScreenUiState.isUnsupportedSourceDialogOpen,
onDismiss =
viewModel::hideUnsupportedSelectedSourceDialog,
onConfirm = { viewModel.showWeatherSourcesForLocationSheet(uiState.isLoading) })
}
@@ -49,6 +49,14 @@ class MainScreenViewModel @Inject constructor(
_uiState.value = _uiState.value.copy(isWeatherSourcesInfoForLocationSheetOpen = false)
}
fun hideUnsupportedSelectedSourceDialog() {
_uiState.value = _uiState.value.copy(isUnsupportedSourceDialogOpen = false)
}
fun showUnsupportedSelectedSourceDialog() {
_uiState.value = _uiState.value.copy(isUnsupportedSourceDialogOpen = true)
}
private suspend fun checkForUpdates() {
val isNewAvailable = try {
githubRepository.isNewVersionAvailable(
@@ -0,0 +1,24 @@
package com.pranshulgg.weather_master_app.feature.main.ui
import androidx.compose.runtime.Composable
import com.pranshulgg.weather_master_app.core.ui.components.TextAlertDialog
object MainScreenDialogs {
@Composable
fun UnsupportedSelectedSourceDialog(
show: Boolean,
onDismiss: () -> Unit,
onConfirm: () -> Unit
) {
TextAlertDialog(
show,
onDismiss = onDismiss,
onConfirm = onConfirm,
confirmText = "Change",
title = "Source not supported",
message = "The currently selected source is not supported in your region. Please choose a different source"
)
}
}
@@ -14,6 +14,7 @@ import com.pranshulgg.weather_master_app.core.model.domain.toMessageRes
import com.pranshulgg.weather_master_app.core.model.domain.weather.Weather
import com.pranshulgg.weather_master_app.core.model.domain.weather.WeatherBlock
import com.pranshulgg.weather_master_app.core.model.sources.WeatherSource
import com.pranshulgg.weather_master_app.core.model.sources.isSupportedFor
import com.pranshulgg.weather_master_app.core.model.weather.WeatherResult
import com.pranshulgg.weather_master_app.core.model.weather.airquality.AirQualityResult
import com.pranshulgg.weather_master_app.core.network.github.GithubRepository
@@ -117,7 +118,7 @@ class WeatherViewModel @Inject constructor(
setLoading(true)
weatherJob?.cancel()
val startTime = System.currentTimeMillis()
_uiState.value = _uiState.value.copy(isError = false)
_uiState.value = _uiState.value.copy(isError = false, isUnsupportedSource = false)
weatherJob = viewModelScope.launch {
@@ -253,7 +254,8 @@ class WeatherViewModel @Inject constructor(
_uiState.value = _uiState.value.copy(
isError = true,
weather = result.cacheWeather
weather = result.cacheWeather,
isUnsupportedSource = !location.source.isSupportedFor(location.countryCode?.uppercase())
)
}