diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/topbars/FeedFilterSpinner.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/topbars/FeedFilterSpinner.kt index ed4d1888e..62f721767 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/topbars/FeedFilterSpinner.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/topbars/FeedFilterSpinner.kt @@ -113,12 +113,6 @@ fun FeedFilterSpinner( } } - val locationPermissionState = rememberPermissionState(Manifest.permission.ACCESS_COARSE_LOCATION) - - LaunchedEffect(locationPermissionState.status.isGranted) { - Amethyst.instance.locationManager.setLocationPermission(locationPermissionState.status.isGranted) - } - val accessibilityDescription = if (selected != null) { stringRes(R.string.feed_filter_selected, currentText) @@ -137,6 +131,7 @@ fun FeedFilterSpinner( Text(currentText) if (selected?.code is TopFilter.AroundMe) { + val locationPermissionState = rememberPermissionState(Manifest.permission.ACCESS_COARSE_LOCATION) if (!locationPermissionState.status.isGranted) { LaunchedEffect(locationPermissionState) { locationPermissionState.launchPermissionRequest() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/LoggedInPage.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/LoggedInPage.kt index 9dcee3f72..d1f44cea2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/LoggedInPage.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/LoggedInPage.kt @@ -29,6 +29,7 @@ import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.rememberCoroutineScope import androidx.lifecycle.compose.LifecycleResumeEffect @@ -98,12 +99,24 @@ fun LoggedInPage( // Register token with the Push Notification Provider. NotificationRegistration(accountViewModel) + WatchLocationPermissions() + AppNavigation( accountViewModel = accountViewModel, accountSessionManager = accountSessionManager, ) } +@OptIn(ExperimentalPermissionsApi::class) +@Composable +fun WatchLocationPermissions() { + val locationPermissionState = rememberPermissionState(Manifest.permission.ACCESS_COARSE_LOCATION) + + LaunchedEffect(locationPermissionState.status.isGranted) { + Amethyst.instance.locationManager.setLocationPermission(locationPermissionState.status.isGranted) + } +} + @Composable fun ObserveAntiSpamFilterSettings(accountViewModel: AccountViewModel) { val isSpamActive by accountViewModel.account.settings.syncedSettings.security.filterSpamFromStrangers