Loading cardinal-android/app/src/main/java/earth/maps/cardinal/ui/directions/DirectionsScreen.kt +47 −25 Original line number Diff line number Diff line Loading @@ -122,31 +122,16 @@ fun DirectionsScreen( val coroutineScope = rememberCoroutineScope() // Auto-retry location request when permissions are granted LaunchedEffect(hasLocationPermission, pendingLocationRequest) { if (hasLocationPermission && pendingLocationRequest != null) { val targetField = pendingLocationRequest!! pendingLocationRequest = null // Clear the pending request // Automatically fetch location for the target field coroutineScope.launch { val myLocationPlace = viewModel.getCurrentLocationAsPlace() myLocationPlace?.let { place -> // Update the appropriate place based on which field was focused if (targetField == FieldFocusState.FROM) { viewModel.updateFromPlace(place) } else { viewModel.updateToPlace(place) } // Clear focus state after selection AutoRetryMyLocation( hasLocationPermission = hasLocationPermission, pendingLocationRequest = pendingLocationRequest, coroutineScope = coroutineScope, viewModel = viewModel, appPreferences = appPreferences, onCompletion = { fieldFocusState = FieldFocusState.NONE } } } else if (hasLocationPermission && appPreferences.continuousLocationTracking.value) { coroutineScope.launch { viewModel.initializeDeparture() } } } ) Column( modifier = Modifier Loading @@ -165,7 +150,10 @@ fun DirectionsScreen( }, savedPlaces = savedPlaces, hasLocationPermission = hasLocationPermission, onRequestLocationPermission = onRequestLocationPermission, onRequestLocationPermission = { pendingLocationRequest = fieldFocusState onRequestLocationPermission() }, coroutineScope = coroutineScope ) } else { Loading @@ -186,6 +174,40 @@ fun DirectionsScreen( } } @Composable private fun AutoRetryMyLocation( hasLocationPermission: Boolean, pendingLocationRequest: FieldFocusState?, coroutineScope: CoroutineScope, viewModel: DirectionsViewModel, appPreferences: AppPreferenceRepository, onCompletion: () -> Unit, ) { LaunchedEffect(hasLocationPermission, pendingLocationRequest) { if (hasLocationPermission && pendingLocationRequest != null) { val targetField = pendingLocationRequest // Automatically fetch location for the target field coroutineScope.launch { val myLocationPlace = viewModel.getCurrentLocationAsPlace() myLocationPlace?.let { place -> // Update the appropriate place based on which field was focused if (targetField == FieldFocusState.FROM) { viewModel.updateFromPlace(place) } else { viewModel.updateToPlace(place) } onCompletion() } } } else if (hasLocationPermission && appPreferences.continuousLocationTracking.value) { coroutineScope.launch { viewModel.initializeDeparture() } } } } @Composable private fun DirectionsScreenFullUI( viewModel: DirectionsViewModel, Loading Loading
cardinal-android/app/src/main/java/earth/maps/cardinal/ui/directions/DirectionsScreen.kt +47 −25 Original line number Diff line number Diff line Loading @@ -122,31 +122,16 @@ fun DirectionsScreen( val coroutineScope = rememberCoroutineScope() // Auto-retry location request when permissions are granted LaunchedEffect(hasLocationPermission, pendingLocationRequest) { if (hasLocationPermission && pendingLocationRequest != null) { val targetField = pendingLocationRequest!! pendingLocationRequest = null // Clear the pending request // Automatically fetch location for the target field coroutineScope.launch { val myLocationPlace = viewModel.getCurrentLocationAsPlace() myLocationPlace?.let { place -> // Update the appropriate place based on which field was focused if (targetField == FieldFocusState.FROM) { viewModel.updateFromPlace(place) } else { viewModel.updateToPlace(place) } // Clear focus state after selection AutoRetryMyLocation( hasLocationPermission = hasLocationPermission, pendingLocationRequest = pendingLocationRequest, coroutineScope = coroutineScope, viewModel = viewModel, appPreferences = appPreferences, onCompletion = { fieldFocusState = FieldFocusState.NONE } } } else if (hasLocationPermission && appPreferences.continuousLocationTracking.value) { coroutineScope.launch { viewModel.initializeDeparture() } } } ) Column( modifier = Modifier Loading @@ -165,7 +150,10 @@ fun DirectionsScreen( }, savedPlaces = savedPlaces, hasLocationPermission = hasLocationPermission, onRequestLocationPermission = onRequestLocationPermission, onRequestLocationPermission = { pendingLocationRequest = fieldFocusState onRequestLocationPermission() }, coroutineScope = coroutineScope ) } else { Loading @@ -186,6 +174,40 @@ fun DirectionsScreen( } } @Composable private fun AutoRetryMyLocation( hasLocationPermission: Boolean, pendingLocationRequest: FieldFocusState?, coroutineScope: CoroutineScope, viewModel: DirectionsViewModel, appPreferences: AppPreferenceRepository, onCompletion: () -> Unit, ) { LaunchedEffect(hasLocationPermission, pendingLocationRequest) { if (hasLocationPermission && pendingLocationRequest != null) { val targetField = pendingLocationRequest // Automatically fetch location for the target field coroutineScope.launch { val myLocationPlace = viewModel.getCurrentLocationAsPlace() myLocationPlace?.let { place -> // Update the appropriate place based on which field was focused if (targetField == FieldFocusState.FROM) { viewModel.updateFromPlace(place) } else { viewModel.updateToPlace(place) } onCompletion() } } } else if (hasLocationPermission && appPreferences.continuousLocationTracking.value) { coroutineScope.launch { viewModel.initializeDeparture() } } } } @Composable private fun DirectionsScreenFullUI( viewModel: DirectionsViewModel, Loading