From 5d22a063729af86a1d6fc9d98cc18f56d6c1c270 Mon Sep 17 00:00:00 2001 From: ABHISHEK PATHAK <51234843+myofficework000@users.noreply.github.com> Date: Fri, 30 Jun 2023 21:12:36 +0530 Subject: [PATCH] One bug need to fix in MVI clean code feature --- .../presentation/WeatherScreen.kt | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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() ) {