diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code_with_mvi_mvvm/presentation/WeatherScreen.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code_with_mvi_mvvm/presentation/WeatherScreen.kt index 5565a2d8..9c50c648 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code_with_mvi_mvvm/presentation/WeatherScreen.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code_with_mvi_mvvm/presentation/WeatherScreen.kt @@ -9,6 +9,11 @@ import androidx.compose.foundation.layout.height import androidx.compose.material.CircularProgressIndicator import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -16,12 +21,27 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.example.jetpack_compose_all_in_one.ui.theme.Blue10 import com.example.jetpack_compose_all_in_one.ui.theme.L1BoxColor2 +import com.example.jetpack_compose_all_in_one.utils.requestAllLocation +import com.google.accompanist.permissions.ExperimentalPermissionsApi - +@OptIn(ExperimentalPermissionsApi::class) @Composable fun WeatherScreen( viewModel: WeatherViewModel ) { + var isLocationAvailable by remember { mutableStateOf(false) } + val requestingLocation = requestAllLocation { isLocationAvailable = it } + + LaunchedEffect(Unit) { + requestingLocation.launchMultiplePermissionRequest() + } + + LaunchedEffect(isLocationAvailable) { + if (isLocationAvailable) { + viewModel.loadWeatherInfo() + } + } + Box( modifier = Modifier.fillMaxSize() ) {