5858: Modification of the event send according to coordinate type

This commit is contained in:
MaximeE
2022-03-31 16:52:16 +02:00
parent e6538d8023
commit 31fedfa215
11 changed files with 71 additions and 29 deletions
@@ -17,6 +17,7 @@
import SwiftUI
import Combine
import CoreLocation
import MatrixSDK
@available(iOS 14, *)
typealias LocationSharingViewModelType = StateStoreViewModel<LocationSharingViewState,
@@ -35,21 +36,21 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie
// MARK: - Setup
init(mapStyleURL: URL, avatarData: AvatarInputProtocol, location: CLLocationCoordinate2D? = nil, isLiveLocationSharingEnabled: Bool = false) {
init(mapStyleURL: URL, avatarData: AvatarInputProtocol, location: CLLocationCoordinate2D? = nil, coordinateType: MXEventAssetType, isLiveLocationSharingEnabled: Bool = false) {
var userAnnotation: UserLocationAnnotation?
var sharedAnnotation: UserLocationAnnotation?
var annotations: [UserLocationAnnotation] = []
var highlightedAnnotation: UserLocationAnnotation?
var showsUserLocation: Bool = false
// Displaying an existing location
if let userCoordinate = location {
let userLocationAnnotation = UserLocationAnnotation(avatarData: avatarData, coordinate: userCoordinate)
if let sharedCoordinate = location {
let sharedLocationAnnotation = UserLocationAnnotation(avatarData: avatarData, coordinate: sharedCoordinate, coordinateType: coordinateType)
annotations.append(userLocationAnnotation)
highlightedAnnotation = userLocationAnnotation
annotations.append(sharedLocationAnnotation)
highlightedAnnotation = sharedLocationAnnotation
userAnnotation = userLocationAnnotation
sharedAnnotation = sharedLocationAnnotation
} else {
// Share current location
showsUserLocation = true
@@ -57,7 +58,7 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie
let viewState = LocationSharingViewState(mapStyleURL: mapStyleURL,
userAvatarData: avatarData,
userAnnotation: userAnnotation,
sharedAnnotation: sharedAnnotation,
annotations: annotations,
highlightedAnnotation: highlightedAnnotation,
showsUserLocation: showsUserLocation,
@@ -79,8 +80,8 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie
completion?(.cancel)
case .share:
// Share existing location
if let location = state.userAnnotation?.coordinate {
completion?(.share(latitude: location.latitude, longitude: location.longitude))
if let location = state.sharedAnnotation?.coordinate {
completion?(.share(latitude: location.latitude, longitude: location.longitude, coordinateType: .generic))
return
}
@@ -90,14 +91,14 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie
return
}
completion?(.share(latitude: location.latitude, longitude: location.longitude))
completion?(.share(latitude: location.latitude, longitude: location.longitude, coordinateType: .user))
case .sharePinLocation:
guard let pinLocation = state.bindings.pinLocation else {
processError(.failedLocatingUser)
return
}
completion?(.share(latitude: pinLocation.latitude, longitude: pinLocation.longitude))
completion?(.share(latitude: pinLocation.latitude, longitude: pinLocation.longitude, coordinateType: .pin))
case .goToUserLocation:
state.bindings.pinLocation = nil
}