diff --git a/RiotSwiftUI/Modules/LocationSharing/MapView/View/LocationSharingMapView.swift b/RiotSwiftUI/Modules/LocationSharing/MapView/View/LocationSharingMapView.swift index 9b5073b33..5bfc1daf2 100644 --- a/RiotSwiftUI/Modules/LocationSharing/MapView/View/LocationSharingMapView.swift +++ b/RiotSwiftUI/Modules/LocationSharing/MapView/View/LocationSharingMapView.swift @@ -151,6 +151,8 @@ extension LocationSharingMapView { fallthrough case .denied: locationSharingMapView.errorSubject.send(.invalidLocationAuthorization) + // bwi: center map if gps is not available + centerMapOnDefaultPosition(mapView: mapView) default: break } @@ -190,6 +192,11 @@ extension LocationSharingMapView { func didPan() { locationSharingMapView.userDidPan?() } + + // bwi: center map on default position (Germany) + func centerMapOnDefaultPosition(mapView: MGLMapView) { + mapView.setVisibleCoordinateBounds(MGLCoordinateBounds(sw: CLLocationCoordinate2D(latitude: CLLocationDegrees(47.11216018072962), longitude: CLLocationDegrees(6.124326657878219)), ne: CLLocationCoordinate2D(latitude: 54.928634747516774, longitude: 14.641747314488596)), animated: true) + } } } diff --git a/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/LocationSharingViewModel.swift b/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/LocationSharingViewModel.swift index 39dbea5c8..5f66e6146 100644 --- a/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/LocationSharingViewModel.swift +++ b/RiotSwiftUI/Modules/LocationSharing/StartLocationSharing/LocationSharingViewModel.swift @@ -60,7 +60,8 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie case .share: // Share current user location guard let location = state.bindings.userLocation else { - processError(.failedLocatingUser) + // bwi: check if app has gps access and show the desired error + showMissingLocationError() return } @@ -73,8 +74,13 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie completion?(.share(latitude: pinLocation.latitude, longitude: pinLocation.longitude, coordinateType: .pin)) case .goToUserLocation: - state.showsUserLocation = true - state.isPinDropSharing = false + // bwi: check if userLocation is available + if state.bindings.userLocation == nil { + showMissingLocationError() + } else { + state.showsUserLocation = true + state.isPinDropSharing = false + } case .startLiveSharing: startLiveLocationSharing() case .shareLiveLocation(let timeout): @@ -140,10 +146,11 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie state.bindings.alertInfo = AlertInfo(id: .userLocatingError, title: VectorL10n.locationSharingLocatingUserErrorTitle(AppInfo.current.displayName), primaryButton: (VectorL10n.ok, primaryButtonCompletion)) + // bwi: The user should be able to set a location without GPS case .invalidLocationAuthorization: state.bindings.alertInfo = AlertInfo(id: .authorizationError, title: VectorL10n.locationSharingInvalidAuthorizationErrorTitle(AppInfo.current.displayName), - primaryButton: (VectorL10n.locationSharingInvalidAuthorizationNotNow, primaryButtonCompletion), + primaryButton: (VectorL10n.locationSharingInvalidAuthorizationNotNow, {return}), secondaryButton: (VectorL10n.locationSharingInvalidAuthorizationSettings, { UIApplication.shared.vc_openSettings() })) @@ -196,4 +203,20 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie } }) } + + private func showMissingLocationError() { + locationSharingService.requestAuthorization { [weak self] authorizationStatus in + guard let self = self else { + return + } + switch authorizationStatus { + case .denied, .unknown: + self.processError(.invalidLocationAuthorization) + case .authorizedAlways: + self.processError(.failedLocatingUser) + case .authorizedInForeground: + self.processError(.failedLocatingUser) + } + } + } }