Adding method to show dialog when permission is missing
This commit is contained in:
parent
9c6cd9f630
commit
6f6bb3dbfe
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 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 im.vector.app.features.location
|
||||||
|
|
||||||
|
interface ILocationSharingNavigator {
|
||||||
|
fun quit()
|
||||||
|
fun goToAppSettings()
|
||||||
|
}
|
|
@ -50,6 +50,8 @@ class LocationSharingFragment @Inject constructor(
|
||||||
|
|
||||||
private val viewModel: LocationSharingViewModel by fragmentViewModel()
|
private val viewModel: LocationSharingViewModel by fragmentViewModel()
|
||||||
|
|
||||||
|
private val viewNavigator: ILocationSharingNavigator by lazy { LocationSharingNavigator(activity) }
|
||||||
|
|
||||||
// Keep a ref to handle properly the onDestroy callback
|
// Keep a ref to handle properly the onDestroy callback
|
||||||
private var mapView: WeakReference<MapView>? = null
|
private var mapView: WeakReference<MapView>? = null
|
||||||
|
|
||||||
|
@ -78,7 +80,7 @@ class LocationSharingFragment @Inject constructor(
|
||||||
viewModel.observeViewEvents {
|
viewModel.observeViewEvents {
|
||||||
when (it) {
|
when (it) {
|
||||||
LocationSharingViewEvents.LocationNotAvailableError -> handleLocationNotAvailableError()
|
LocationSharingViewEvents.LocationNotAvailableError -> handleLocationNotAvailableError()
|
||||||
LocationSharingViewEvents.Close -> activity?.finish()
|
LocationSharingViewEvents.Close -> viewNavigator.quit()
|
||||||
is LocationSharingViewEvents.ZoomToUserLocation -> handleZoomToUserLocationEvent(it)
|
is LocationSharingViewEvents.ZoomToUserLocation -> handleZoomToUserLocationEvent(it)
|
||||||
}.exhaustive
|
}.exhaustive
|
||||||
}
|
}
|
||||||
|
@ -138,12 +140,24 @@ class LocationSharingFragment @Inject constructor(
|
||||||
.setTitle(R.string.location_not_available_dialog_title)
|
.setTitle(R.string.location_not_available_dialog_title)
|
||||||
.setMessage(R.string.location_not_available_dialog_content)
|
.setMessage(R.string.location_not_available_dialog_content)
|
||||||
.setPositiveButton(R.string.ok) { _, _ ->
|
.setPositiveButton(R.string.ok) { _, _ ->
|
||||||
activity?.finish()
|
viewNavigator.quit()
|
||||||
}
|
}
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleMissingBackgroundLocationPermission() {
|
||||||
|
MaterialAlertDialogBuilder(requireActivity())
|
||||||
|
.setTitle(R.string.location_in_background_missing_permission_dialog_title)
|
||||||
|
.setMessage(R.string.location_in_background_missing_permission_dialog_content)
|
||||||
|
.setPositiveButton(R.string.settings) { _, _ ->
|
||||||
|
viewNavigator.goToAppSettings()
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.action_not_now, null)
|
||||||
|
.setCancelable(false)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
private fun initLocateButton() {
|
private fun initLocateButton() {
|
||||||
views.mapView.locateButton.setOnClickListener {
|
views.mapView.locateButton.setOnClickListener {
|
||||||
viewModel.handle(LocationSharingAction.ZoomToUserLocation)
|
viewModel.handle(LocationSharingAction.ZoomToUserLocation)
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 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 im.vector.app.features.location
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import im.vector.app.core.utils.openAppSettingsPage
|
||||||
|
|
||||||
|
class LocationSharingNavigator constructor(val activity: Activity?): ILocationSharingNavigator {
|
||||||
|
|
||||||
|
override fun quit() {
|
||||||
|
activity?.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun goToAppSettings() {
|
||||||
|
activity?.let { openAppSettingsPage(it) }
|
||||||
|
}
|
||||||
|
}
|
|
@ -2937,6 +2937,8 @@
|
||||||
<string name="a11y_location_share_option_user_live_icon">Share live location</string>
|
<string name="a11y_location_share_option_user_live_icon">Share live location</string>
|
||||||
<string name="location_share_option_pinned">Share this location</string>
|
<string name="location_share_option_pinned">Share this location</string>
|
||||||
<string name="a11y_location_share_option_pinned_icon">Share this location</string>
|
<string name="a11y_location_share_option_pinned_icon">Share this location</string>
|
||||||
|
<string name="location_in_background_missing_permission_dialog_title">Allow access</string>
|
||||||
|
<string name="location_in_background_missing_permission_dialog_content">If you’d like to share your Live location, ${app_name} needs location access when the app is in the background.\nWe will only access your location for the duration that you choose.</string>
|
||||||
<string name="location_not_available_dialog_title">${app_name} could not access your location</string>
|
<string name="location_not_available_dialog_title">${app_name} could not access your location</string>
|
||||||
<string name="location_not_available_dialog_content">${app_name} could not access your location. Please try again later.</string>
|
<string name="location_not_available_dialog_content">${app_name} could not access your location. Please try again later.</string>
|
||||||
<string name="location_share_external">Open with</string>
|
<string name="location_share_external">Open with</string>
|
||||||
|
|
Loading…
Reference in New Issue