diff --git a/.idea/misc.xml b/.idea/misc.xml index 5d1e5db..2a00070 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -35,6 +35,9 @@ + + + diff --git a/app/src/main/java/ch/mathieubroillet/jarvis/android/nav/Navigation.kt b/app/src/main/java/ch/mathieubroillet/jarvis/android/nav/Navigation.kt index 63eb35d..8e69554 100644 --- a/app/src/main/java/ch/mathieubroillet/jarvis/android/nav/Navigation.kt +++ b/app/src/main/java/ch/mathieubroillet/jarvis/android/nav/Navigation.kt @@ -8,11 +8,22 @@ import androidx.navigation.compose.rememberNavController import ch.mathieubroillet.jarvis.android.pages.DisplayMainPage import ch.mathieubroillet.jarvis.android.pages.DisplayPermissionsPage import ch.mathieubroillet.jarvis.android.pages.DisplaySettingsPage +import com.google.accompanist.permissions.ExperimentalPermissionsApi +import com.google.accompanist.permissions.rememberMultiplePermissionsState +@OptIn(ExperimentalPermissionsApi::class) @Composable fun Navigation() { val navController = rememberNavController() - NavHost(navController = navController, startDestination = Screen.MainScreen.route) { + + val permissions = listOf(android.Manifest.permission.RECORD_AUDIO) + val permissionState = rememberMultiplePermissionsState(permissions) + + + NavHost( + navController = navController, + startDestination = if (permissionState.allPermissionsGranted) Screen.MainScreen.route else Screen.PermissionsScreen.route + ) { composable(route = Screen.MainScreen.route) { MainScreen(navController = navController) } diff --git a/app/src/main/java/ch/mathieubroillet/jarvis/android/pages/PermissionsPage.kt b/app/src/main/java/ch/mathieubroillet/jarvis/android/pages/PermissionsPage.kt index acdef74..a87cc64 100644 --- a/app/src/main/java/ch/mathieubroillet/jarvis/android/pages/PermissionsPage.kt +++ b/app/src/main/java/ch/mathieubroillet/jarvis/android/pages/PermissionsPage.kt @@ -30,7 +30,11 @@ fun DisplayPermissionsPage(navController: NavController) { @Composable fun PermissionsBase(navController: NavController) { - Column(Modifier.padding(bottom = 25.dp)) { + Column( + Modifier + .padding(bottom = 25.dp) + .fillMaxSize() + ) { Row { Icon( painter = painterResource(id = R.drawable.ic_baseline_shield_24), diff --git a/app/src/main/java/ch/mathieubroillet/jarvis/android/utils/PermissionsUtils.kt b/app/src/main/java/ch/mathieubroillet/jarvis/android/utils/PermissionsUtils.kt index 85e892e..0bf135c 100644 --- a/app/src/main/java/ch/mathieubroillet/jarvis/android/utils/PermissionsUtils.kt +++ b/app/src/main/java/ch/mathieubroillet/jarvis/android/utils/PermissionsUtils.kt @@ -14,14 +14,14 @@ import com.google.accompanist.permissions.rememberPermissionState @OptIn(ExperimentalPermissionsApi::class) @Composable fun requestPermission(permission: String) { - val cameraPermissionState = rememberPermissionState(permission = permission) + val permissionState = rememberPermissionState(permission = permission) val context = LocalContext.current PermissionRequired( - permissionState = cameraPermissionState, + permissionState = permissionState, permissionNotGrantedContent = { Button(onClick = { - cameraPermissionState.launchPermissionRequest() + permissionState.launchPermissionRequest() }) { Text(text = stringResource(id = R.string.permissions_page_grant_permission)) }