Merge branch 'feature/4235_location_sharing_without_gps' into 'develop'

MESSENGER-4235 - location sharing without gps

See merge request bwmessenger/bundesmessenger/bundesmessenger-ios!88
This commit is contained in:
Frank Rotermund
2023-02-10 06:40:24 +00:00
2 changed files with 34 additions and 4 deletions
@@ -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)
}
}
}
@@ -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)
}
}
}
}