-
-
Save Arunshaik2001/eca86bb924797ba23c9ca47970b18cf6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OptIn(ExperimentalPermissionsApi::class) | |
@Composable | |
fun WearApp(locationUtil: LocationUtil) { | |
val listState = rememberScalingLazyListState() | |
Wear2Theme { | |
val locationPermissionsState = rememberMultiplePermissionsState( | |
listOf( | |
Manifest.permission.ACCESS_COARSE_LOCATION, | |
Manifest.permission.ACCESS_FINE_LOCATION, | |
) | |
) | |
val contentModifier = Modifier | |
.fillMaxWidth() | |
.padding(bottom = 8.dp) | |
val iconModifier = Modifier | |
.size(24.dp) | |
.wrapContentSize(align = Alignment.Center) | |
ScalingLazyColumn( | |
modifier = Modifier.fillMaxSize(), | |
contentPadding = PaddingValues( | |
top = 32.dp, | |
start = 8.dp, | |
end = 8.dp, | |
bottom = 32.dp | |
), | |
verticalArrangement = Arrangement.Bottom, | |
state = listState, | |
autoCentering = true | |
) { | |
if (locationPermissionsState.allPermissionsGranted){ | |
if (!locationUtil.dataLoaded.value) | |
item { TextWidget(contentModifier,"Thanks! I can access your exact location :D") } | |
else{ | |
item { CardWidget( | |
modifier = contentModifier, | |
title = locationUtil.data.value.name , | |
weatherDescription = locationUtil.data.value.weatherDescription, | |
time = locationUtil.data.value.time , temperature = 12.0) | |
} | |
} | |
} | |
else{ | |
val allPermissionsRevoked = | |
locationPermissionsState.permissions.size == | |
locationPermissionsState.revokedPermissions.size | |
val textToShow = if (!allPermissionsRevoked) { | |
"Yay! Thanks for letting me access your approximate location. " + | |
"But you know what would be great? If you allow me to know where you " + | |
"exactly are. Thank you!" | |
} else if (locationPermissionsState.shouldShowRationale) { | |
"Getting your exact location is important for this app. " + | |
"Please grant us fine location. Thank you :D" | |
} else { | |
"This feature requires location permission" | |
} | |
item { TextWidget(contentModifier,textToShow) } | |
item { ButtonWidget(contentModifier, iconModifier){ | |
locationPermissionsState.launchMultiplePermissionRequest() | |
} } | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment