diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/common/PermissionDeniedDialog.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/common/PermissionDeniedDialog.kt new file mode 100644 index 0000000000..0a488ded85 --- /dev/null +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/common/PermissionDeniedDialog.kt @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.location.impl.common + +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import io.element.android.libraries.designsystem.components.dialogs.ConfirmationDialog +import io.element.android.libraries.ui.strings.CommonStrings + +@Composable +internal fun PermissionDeniedDialog( + onContinue: () -> Unit, + onDismiss: () -> Unit, + appName: String, +) { + ConfirmationDialog( + content = stringResource(CommonStrings.error_missing_location_auth_android, appName), + onSubmitClicked = onContinue, + onDismiss = onDismiss, + submitText = stringResource(CommonStrings.action_continue), + cancelText = stringResource(CommonStrings.action_cancel), + ) +} diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/common/PermissionRationaleDialog.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/common/PermissionRationaleDialog.kt new file mode 100644 index 0000000000..4f4f19c6b3 --- /dev/null +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/common/PermissionRationaleDialog.kt @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.location.impl.common + +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import io.element.android.libraries.designsystem.components.dialogs.ConfirmationDialog +import io.element.android.libraries.ui.strings.CommonStrings + +@Composable +internal fun PermissionRationaleDialog( + onContinue: () -> Unit, + onDismiss: () -> Unit, + appName: String, +) { + ConfirmationDialog( + content = stringResource(CommonStrings.error_missing_location_rationale_android, appName), + onSubmitClicked = onContinue, + onDismiss = onDismiss, + submitText = stringResource(CommonStrings.action_continue), + cancelText = stringResource(CommonStrings.action_cancel), + ) +} diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/send/SendLocationView.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/send/SendLocationView.kt index 5bf4354f24..e06b60b1a7 100644 --- a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/send/SendLocationView.kt +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/send/SendLocationView.kt @@ -49,8 +49,9 @@ import io.element.android.features.location.api.internal.centerBottomEdge import io.element.android.features.location.api.internal.rememberTileStyleUrl import io.element.android.features.location.impl.common.MapDefaults import io.element.android.features.location.impl.R +import io.element.android.features.location.impl.common.PermissionDeniedDialog +import io.element.android.features.location.impl.common.PermissionRationaleDialog import io.element.android.libraries.designsystem.components.button.BackButton -import io.element.android.libraries.designsystem.components.dialogs.ConfirmationDialog import io.element.android.libraries.designsystem.preview.DayNightPreviews import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.theme.aliasScreenTitle @@ -232,33 +233,3 @@ internal fun SendLocationViewPreview( navigateUp = {}, ) } - -@Composable -private fun PermissionRationaleDialog( - onContinue: () -> Unit, - onDismiss: () -> Unit, - appName: String, -) { - ConfirmationDialog( - content = stringResource(CommonStrings.error_missing_location_rationale_android, appName), - onSubmitClicked = onContinue, - onDismiss = onDismiss, - submitText = stringResource(CommonStrings.action_continue), - cancelText = stringResource(CommonStrings.action_cancel), - ) -} - -@Composable -private fun PermissionDeniedDialog( - onContinue: () -> Unit, - onDismiss: () -> Unit, - appName: String, -) { - ConfirmationDialog( - content = stringResource(CommonStrings.error_missing_location_auth_android, appName), - onSubmitClicked = onContinue, - onDismiss = onDismiss, - submitText = stringResource(CommonStrings.action_continue), - cancelText = stringResource(CommonStrings.action_cancel), - ) -} diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationStateProvider.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationStateProvider.kt index fd1aeb1d27..36568bc99c 100644 --- a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationStateProvider.kt +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationStateProvider.kt @@ -33,6 +33,42 @@ class ShowLocationStateProvider : PreviewParameterProvider { appName = APP_NAME, eventSink = {}, ), + ShowLocationState( + ShowLocationState.Dialog.PermissionDenied, + Location(1.23, 2.34, 4f), + description = null, + hasLocationPermission = false, + isTrackMyLocation = false, + appName = APP_NAME, + eventSink = {}, + ), + ShowLocationState( + ShowLocationState.Dialog.PermissionRationale, + Location(1.23, 2.34, 4f), + description = null, + hasLocationPermission = false, + isTrackMyLocation = false, + appName = APP_NAME, + eventSink = {}, + ), + ShowLocationState( + ShowLocationState.Dialog.None, + Location(1.23, 2.34, 4f), + description = null, + hasLocationPermission = true, + isTrackMyLocation = false, + appName = APP_NAME, + eventSink = {}, + ), + ShowLocationState( + ShowLocationState.Dialog.None, + Location(1.23, 2.34, 4f), + description = null, + hasLocationPermission = true, + isTrackMyLocation = true, + appName = APP_NAME, + eventSink = {}, + ), ShowLocationState( ShowLocationState.Dialog.None, Location(1.23, 2.34, 4f), diff --git a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationView.kt b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationView.kt index fb4f3ac1f8..8426d8b7b8 100644 --- a/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationView.kt +++ b/features/location/impl/src/main/kotlin/io/element/android/features/location/impl/show/ShowLocationView.kt @@ -40,6 +40,8 @@ import com.mapbox.mapboxsdk.camera.CameraPosition import com.mapbox.mapboxsdk.geometry.LatLng import io.element.android.features.location.api.internal.rememberTileStyleUrl import io.element.android.features.location.impl.common.MapDefaults +import io.element.android.features.location.impl.common.PermissionDeniedDialog +import io.element.android.features.location.impl.common.PermissionRationaleDialog import io.element.android.libraries.designsystem.components.button.BackButton import io.element.android.libraries.designsystem.preview.ElementPreviewDark import io.element.android.libraries.designsystem.preview.ElementPreviewLight @@ -70,6 +72,20 @@ fun ShowLocationView( modifier: Modifier = Modifier, onBackPressed: () -> Unit = {}, ) { + when (state.permissionDialog) { + ShowLocationState.Dialog.None -> Unit + ShowLocationState.Dialog.PermissionDenied -> PermissionDeniedDialog( + onContinue = { state.eventSink(ShowLocationEvents.OpenAppSettings) }, + onDismiss = { state.eventSink(ShowLocationEvents.DismissDialog) }, + appName = state.appName, + ) + ShowLocationState.Dialog.PermissionRationale -> PermissionRationaleDialog( + onContinue = { state.eventSink(ShowLocationEvents.RequestPermissions) }, + onDismiss = { state.eventSink(ShowLocationEvents.DismissDialog) }, + appName = state.appName, + ) + } + val cameraPositionState = rememberCameraPositionState { position = CameraPosition.Builder() .target(LatLng(state.location.lat, state.location.lon)) @@ -116,14 +132,12 @@ fun ShowLocationView( ) }, floatingActionButton = { - if (state.hasLocationPermission) { - FloatingActionButton( - onClick = { state.eventSink(ShowLocationEvents.TrackMyLocation(true)) }, - ) { - when (state.isTrackMyLocation) { - false -> Icon(imageVector = Icons.Default.LocationSearching, contentDescription = null) - true -> Icon(imageVector = Icons.Default.MyLocation, contentDescription = null) - } + FloatingActionButton( + onClick = { state.eventSink(ShowLocationEvents.TrackMyLocation(true)) }, + ) { + when (state.isTrackMyLocation) { + false -> Icon(imageVector = Icons.Default.LocationSearching, contentDescription = null) + true -> Icon(imageVector = Icons.Default.MyLocation, contentDescription = null) } } },