mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-25 02:52:45 +02:00
5858: Modification of the event send according to coordinate type
This commit is contained in:
+5
-2
@@ -17,12 +17,14 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
import MatrixSDK
|
||||
|
||||
struct LocationSharingCoordinatorParameters {
|
||||
let roomDataSource: MXKRoomDataSource
|
||||
let mediaManager: MXMediaManager
|
||||
let avatarData: AvatarInputProtocol
|
||||
let location: CLLocationCoordinate2D?
|
||||
let coordinateType: MXEventAssetType
|
||||
}
|
||||
|
||||
final class LocationSharingCoordinator: Coordinator, Presentable {
|
||||
@@ -50,6 +52,7 @@ final class LocationSharingCoordinator: Coordinator, Presentable {
|
||||
let viewModel = LocationSharingViewModel(mapStyleURL: BuildSettings.tileServerMapStyleURL,
|
||||
avatarData: parameters.avatarData,
|
||||
location: parameters.location,
|
||||
coordinateType: parameters.coordinateType,
|
||||
isLiveLocationSharingEnabled: BuildSettings.liveLocationSharingEnabled)
|
||||
let view = LocationSharingView(context: viewModel.context)
|
||||
.addDependency(AvatarService.instantiate(mediaManager: parameters.mediaManager))
|
||||
@@ -71,7 +74,7 @@ final class LocationSharingCoordinator: Coordinator, Presentable {
|
||||
switch result {
|
||||
case .cancel:
|
||||
self.completion?()
|
||||
case .share(let latitude, let longitude):
|
||||
case .share(let latitude, let longitude, let coordinateType):
|
||||
|
||||
// Show share sheet on existing location display
|
||||
if let location = self.parameters.location {
|
||||
@@ -81,7 +84,7 @@ final class LocationSharingCoordinator: Coordinator, Presentable {
|
||||
|
||||
self.locationSharingViewModel.startLoading()
|
||||
|
||||
self.parameters.roomDataSource.sendLocation(withLatitude: latitude, longitude: longitude, description: nil) { [weak self] _ in
|
||||
self.parameters.roomDataSource.sendLocation(withLatitude: latitude, longitude: longitude, description: nil, coordinateType: coordinateType) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
|
||||
self.locationSharingViewModel.stopLoading()
|
||||
|
||||
@@ -18,6 +18,7 @@ import Foundation
|
||||
import SwiftUI
|
||||
import Combine
|
||||
import CoreLocation
|
||||
import MatrixSDK
|
||||
|
||||
enum LocationSharingViewAction {
|
||||
case cancel
|
||||
@@ -28,7 +29,7 @@ enum LocationSharingViewAction {
|
||||
|
||||
enum LocationSharingViewModelResult {
|
||||
case cancel
|
||||
case share(latitude: Double, longitude: Double)
|
||||
case share(latitude: Double, longitude: Double, coordinateType: MXEventAssetType)
|
||||
}
|
||||
|
||||
enum LocationSharingViewError {
|
||||
@@ -47,8 +48,8 @@ struct LocationSharingViewState: BindableState {
|
||||
/// Current user avatarData
|
||||
let userAvatarData: AvatarInputProtocol
|
||||
|
||||
/// User map annotation to display existing location
|
||||
let userAnnotation: UserLocationAnnotation?
|
||||
/// Shared annotation to display existing location
|
||||
let sharedAnnotation: UserLocationAnnotation?
|
||||
|
||||
/// Map annotations to display on map
|
||||
var annotations: [UserLocationAnnotation]
|
||||
@@ -74,7 +75,7 @@ struct LocationSharingViewState: BindableState {
|
||||
}
|
||||
|
||||
var displayExistingLocation: Bool {
|
||||
return userAnnotation != nil
|
||||
return sharedAnnotation != nil
|
||||
}
|
||||
|
||||
var shareButtonEnabled: Bool {
|
||||
|
||||
@@ -38,6 +38,7 @@ enum MockLocationSharingScreenState: MockScreenState, CaseIterable {
|
||||
let viewModel = LocationSharingViewModel(mapStyleURL: mapStyleURL,
|
||||
avatarData: AvatarInput(mxContentUri: "", matrixItemId: "alice:matrix.org", displayName: "Alice"),
|
||||
location: location,
|
||||
coordinateType: .user,
|
||||
isLiveLocationSharingEnabled: true)
|
||||
return ([viewModel],
|
||||
AnyView(LocationSharingView(context: viewModel.context)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
import Foundation
|
||||
import Mapbox
|
||||
import MatrixSDK
|
||||
|
||||
class UserLocationAnnotation: NSObject, MGLAnnotation {
|
||||
|
||||
@@ -25,13 +26,17 @@ class UserLocationAnnotation: NSObject, MGLAnnotation {
|
||||
|
||||
let coordinate: CLLocationCoordinate2D
|
||||
|
||||
let coordinateType: MXEventAssetType
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(avatarData: AvatarInputProtocol,
|
||||
coordinate: CLLocationCoordinate2D) {
|
||||
coordinate: CLLocationCoordinate2D,
|
||||
coordinateType: MXEventAssetType) {
|
||||
|
||||
self.coordinate = coordinate
|
||||
self.avatarData = avatarData
|
||||
self.coordinateType = coordinateType
|
||||
|
||||
super.init()
|
||||
}
|
||||
|
||||
@@ -118,8 +118,8 @@ extension LocationSharingMapView {
|
||||
|
||||
if let userLocationAnnotation = annotation as? UserLocationAnnotation {
|
||||
return UserLocationAnnotatonView(userLocationAnnotation: userLocationAnnotation)
|
||||
} else if annotation is MGLUserLocation, let currentUserAvatarData = locationSharingMapView.userAvatarData {
|
||||
// Replace default current location annotation view with a UserLocationAnnotatonView
|
||||
} else if annotation is MGLUserLocation && locationSharingMapView.mapCenterCoordinate == nil, let currentUserAvatarData = locationSharingMapView.userAvatarData {
|
||||
// Replace default current location annotation view with a UserLocationAnnotatonView when the map is center on user location
|
||||
return UserLocationAnnotatonView(avatarData: currentUserAvatarData)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,14 @@ class UserLocationAnnotatonView: MGLUserLocationAnnotationView {
|
||||
// TODO: Use a reuseIdentifier
|
||||
super.init(annotation: userLocationAnnotation, reuseIdentifier: nil)
|
||||
|
||||
self.addUserMarkerView(with: userLocationAnnotation.avatarData)
|
||||
switch userLocationAnnotation.coordinateType {
|
||||
case .user:
|
||||
self.addUserMarkerView(with: userLocationAnnotation.avatarData)
|
||||
case .pin, .generic:
|
||||
self.addPinMarkerView()
|
||||
@unknown default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
@@ -55,12 +62,26 @@ class UserLocationAnnotatonView: MGLUserLocationAnnotationView {
|
||||
}).view else {
|
||||
return
|
||||
}
|
||||
addMarkerView(with: avatarImageView)
|
||||
}
|
||||
|
||||
private func addPinMarkerView() {
|
||||
guard let pinImageView = UIHostingController(rootView: LocationSharingMarkerView(backgroundColor: theme.colors.accent) {
|
||||
Image(uiImage: Asset.Images.locationPinIcon.image)
|
||||
.resizable()
|
||||
.shapedBorder(color: theme.colors.accent, borderWidth: 3, shape: Circle())
|
||||
}).view else {
|
||||
return
|
||||
}
|
||||
addMarkerView(with: pinImageView)
|
||||
}
|
||||
|
||||
private func addMarkerView(with imageView: UIView) {
|
||||
addSubview(imageView)
|
||||
|
||||
addSubview(avatarImageView)
|
||||
|
||||
addConstraints([topAnchor.constraint(equalTo: avatarImageView.topAnchor),
|
||||
leadingAnchor.constraint(equalTo: avatarImageView.leadingAnchor),
|
||||
bottomAnchor.constraint(equalTo: avatarImageView.bottomAnchor),
|
||||
trailingAnchor.constraint(equalTo: avatarImageView.trailingAnchor)])
|
||||
addConstraints([topAnchor.constraint(equalTo: imageView.topAnchor),
|
||||
leadingAnchor.constraint(equalTo: imageView.leadingAnchor),
|
||||
bottomAnchor.constraint(equalTo: imageView.bottomAnchor),
|
||||
trailingAnchor.constraint(equalTo: imageView.trailingAnchor)])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user