MESSENGER-4235 - location sharing without gps

This commit is contained in:
JanNiklas Grabowski
2023-02-09 17:50:33 +01:00
parent e3011a670c
commit eae05b3093
2 changed files with 34 additions and 4 deletions
@@ -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)
}
}
}
}