Skip to content

Commit 5d22a06

Browse files
One bug need to fix in MVI clean code feature
1 parent db279bc commit 5d22a06

File tree

1 file changed

+21
-1
lines changed
  • app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code_with_mvi_mvvm/presentation

1 file changed

+21
-1
lines changed

app/src/main/java/com/example/jetpack_compose_all_in_one/android_architectures/clean_code_with_mvi_mvvm/presentation/WeatherScreen.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,39 @@ import androidx.compose.foundation.layout.height
99
import androidx.compose.material.CircularProgressIndicator
1010
import androidx.compose.material3.Text
1111
import androidx.compose.runtime.Composable
12+
import androidx.compose.runtime.LaunchedEffect
13+
import androidx.compose.runtime.getValue
14+
import androidx.compose.runtime.mutableStateOf
15+
import androidx.compose.runtime.remember
16+
import androidx.compose.runtime.setValue
1217
import androidx.compose.ui.Alignment
1318
import androidx.compose.ui.Modifier
1419
import androidx.compose.ui.graphics.Color
1520
import androidx.compose.ui.text.style.TextAlign
1621
import androidx.compose.ui.unit.dp
1722
import com.example.jetpack_compose_all_in_one.ui.theme.Blue10
1823
import com.example.jetpack_compose_all_in_one.ui.theme.L1BoxColor2
24+
import com.example.jetpack_compose_all_in_one.utils.requestAllLocation
25+
import com.google.accompanist.permissions.ExperimentalPermissionsApi
1926

20-
27+
@OptIn(ExperimentalPermissionsApi::class)
2128
@Composable
2229
fun WeatherScreen(
2330
viewModel: WeatherViewModel
2431
) {
32+
var isLocationAvailable by remember { mutableStateOf(false) }
33+
val requestingLocation = requestAllLocation { isLocationAvailable = it }
34+
35+
LaunchedEffect(Unit) {
36+
requestingLocation.launchMultiplePermissionRequest()
37+
}
38+
39+
LaunchedEffect(isLocationAvailable) {
40+
if (isLocationAvailable) {
41+
viewModel.loadWeatherInfo()
42+
}
43+
}
44+
2545
Box(
2646
modifier = Modifier.fillMaxSize()
2747
) {

0 commit comments

Comments
 (0)