mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 17:42:45 +02:00
b298dedc22
Merge commit 'f823ab9aae70e8d15ed7cc079210dd9bbbb6c8e1' into feature/foss_update_1_11_19 * commit 'f823ab9aae70e8d15ed7cc079210dd9bbbb6c8e1': finish version++ version++ comments update submodule remove obsolete tests removed unused code update submodule fix Libolm removal update license macro update license Prepare for new sprint # Conflicts: # Config/AppVersion.xcconfig # IDETemplateMacros.plist # LICENSE # README.md # Riot/Categories/MXSession+Riot.m # Riot/Managers/EncryptionKeyManager/EncryptionKeyManager.swift # Riot/Managers/KeyValueStorage/Extensions/Keychain.swift # Riot/Managers/KeyValueStorage/KeyValueStore.swift # Riot/Managers/KeyValueStorage/KeychainStore.swift # Riot/Managers/KeyValueStorage/MemoryStore.swift # Riot/Managers/PushNotification/PushNotificationService.m # Riot/Managers/Settings/RiotSettings.swift # Riot/Managers/Settings/Shared/RiotSharedSettings.swift # Riot/Modules/Analytics/AnalyticsUIElement.swift # Riot/Modules/Application/AppCoordinator.swift # Riot/Modules/Application/LegacyAppDelegate.h # Riot/Modules/Application/LegacyAppDelegate.m # Riot/Modules/Authentication/Legacy/AuthenticationViewController.h # Riot/Modules/Authentication/Legacy/AuthenticationViewController.m # Riot/Modules/Authentication/Legacy/Views/AuthInputsView.h # Riot/Modules/Authentication/Legacy/Views/AuthInputsView.m # Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m # Riot/Modules/Common/Recents/RecentsViewController.m # Riot/Modules/Common/WebViewController/WebViewViewController.m # Riot/Modules/Contacts/Details/ContactDetailsViewController.m # Riot/Modules/Contacts/Views/ContactTableViewCell.m # Riot/Modules/Favorites/FavouritesViewController.h # Riot/Modules/Favorites/FavouritesViewController.m # Riot/Modules/GlobalSearch/UnifiedSearchViewController.m # Riot/Modules/People/PeopleViewController.h # Riot/Modules/People/PeopleViewController.m # Riot/Modules/Room/ContextualMenu/ReactionsMenu/ReactionsMenuViewModel.swift # Riot/Modules/Room/DataSources/RoomDataSource.m # Riot/Modules/Room/Files/RoomFilesViewController.m # Riot/Modules/Room/Members/Detail/RoomMemberDetailsViewController.m # Riot/Modules/Room/Members/RoomParticipantsViewController.m # Riot/Modules/Room/RoomViewController.m # Riot/Modules/Room/Settings/RoomSettingsViewController.m # Riot/Modules/Room/TimelineCells/RoomCreationIntro/RoomCreationIntroCell.swift # Riot/Modules/Room/TimelineCells/RoomCreationIntro/RoomCreationIntroCellContentView.swift # Riot/Modules/Room/TimelineCells/RoomCreationIntro/RoomCreationIntroViewData.swift # Riot/Modules/Room/TimelineCells/RoomTimelineCellIdentifier.h # Riot/Modules/Rooms/RoomsViewController.h # Riot/Modules/Rooms/ShowDirectory/Cells/Network/DirectoryNetworkTableHeaderFooterView.swift # Riot/Modules/Rooms/ShowDirectory/Cells/Room/DirectoryRoomTableViewCell.swift # Riot/Modules/Rooms/ShowDirectory/PublicRoomsDirectoryViewModel.swift # Riot/Modules/Secrets/Recover/RecoverWithKey/SecretsRecoveryWithKeyCoordinator.swift # Riot/Modules/Secrets/Recover/RecoverWithKey/SecretsRecoveryWithKeyViewController.swift # Riot/Modules/Secrets/Recover/RecoverWithPassphrase/SecretsRecoveryWithPassphraseCoordinator.swift # Riot/Modules/Secrets/Recover/RecoverWithPassphrase/SecretsRecoveryWithPassphraseViewController.swift # Riot/Modules/Secrets/Recover/SecretsRecoveryCoordinator.swift # Riot/Modules/SecureBackup/Setup/Intro/SecureBackupSetupIntroViewController.swift # Riot/Modules/SecureBackup/Setup/Intro/SecureBackupSetupIntroViewModel.swift # Riot/Modules/SecureBackup/Setup/Intro/SecureBackupSetupIntroViewModelType.swift # Riot/Modules/SetPinCode/PinCodePreferences.swift # Riot/Modules/SetPinCode/SetupBiometrics/BiometricsAuthenticationPresenter.swift # Riot/Modules/Settings/Security/ManageSession/ManageSessionViewController.m # Riot/Modules/Settings/Security/SecurityViewController.m # Riot/Modules/Settings/SettingsViewController.m # Riot/Modules/SplitView/SplitViewCoordinator.swift # Riot/Modules/SplitView/SplitViewCoordinatorType.swift # Riot/Modules/StartChat/StartChatViewController.m # Riot/Modules/TabBar/MasterTabBarController.h # Riot/Modules/TabBar/MasterTabBarController.m # Riot/Utils/EventFormatter.m # Riot/Utils/HTMLFormatter.swift # Riot/Utils/Tools.m # RiotNSE/NotificationService.swift
245 lines
9.0 KiB
Swift
245 lines
9.0 KiB
Swift
//
|
|
// Copyright 2021-2024 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
// Please see LICENSE in the repository root for full details.
|
|
//
|
|
|
|
import Combine
|
|
import Mapbox
|
|
import SwiftUI
|
|
|
|
/*
|
|
Behavior mode of the current user's location, can be hidden, only shown and shown following the user
|
|
*/
|
|
enum ShowUserLocationMode {
|
|
case follow
|
|
case show
|
|
case hide
|
|
}
|
|
|
|
struct LocationSharingMapView: UIViewRepresentable {
|
|
// MARK: - Constants
|
|
|
|
private enum Constants {
|
|
static let mapZoomLevel = 15.0
|
|
}
|
|
|
|
// MARK: - Properties
|
|
|
|
/// Map style URL (https://docs.mapbox.com/api/maps/styles/)
|
|
let tileServerMapURL: URL
|
|
|
|
/// Map annotations
|
|
let annotations: [LocationAnnotation]
|
|
|
|
/// Map annotation to focus on
|
|
let highlightedAnnotation: LocationAnnotation?
|
|
|
|
/// Current user avatar data, used to replace current location annotation view with the user avatar
|
|
let userAvatarData: AvatarInputProtocol?
|
|
|
|
/// Behavior mode of the current user's location, can be hidden, only shown and shown following the user
|
|
var showsUserLocationMode: ShowUserLocationMode = .hide
|
|
|
|
/// True to indicate that a touch on user annotation can show a callout
|
|
var userAnnotationCanShowCallout = false
|
|
|
|
/// Last user location if `showsUserLocation` has been enabled
|
|
@Binding var userLocation: CLLocationCoordinate2D?
|
|
|
|
/// Coordinate of the center of the map
|
|
@Binding var mapCenterCoordinate: CLLocationCoordinate2D?
|
|
|
|
/// Called when an annotation callout view is tapped
|
|
var onCalloutTap: ((MGLAnnotation) -> Void)?
|
|
|
|
/// Publish view errors if any
|
|
let errorSubject: PassthroughSubject<LocationSharingViewError, Never>
|
|
|
|
/// Called when the user pan on the map
|
|
var userDidPan: (() -> Void)?
|
|
|
|
// bwi #5379: for copyright attribution
|
|
var attributionsChanged: ((LocationSharingAttribution) -> Void)?
|
|
|
|
// MARK: - UIViewRepresentable
|
|
|
|
func makeUIView(context: Context) -> MGLMapView {
|
|
let mapView = makeMapView()
|
|
mapView.delegate = context.coordinator
|
|
let panGesture = UIPanGestureRecognizer(target: context.coordinator, action: #selector(context.coordinator.didPan))
|
|
panGesture.delegate = context.coordinator
|
|
mapView.addGestureRecognizer(panGesture)
|
|
return mapView
|
|
}
|
|
|
|
func updateUIView(_ mapView: MGLMapView, context: Context) {
|
|
mapView.vc_removeAllAnnotations()
|
|
mapView.addAnnotations(annotations)
|
|
|
|
/*
|
|
if there is an highlighted annotation,
|
|
and the current user's location it's either hidden or only shown,
|
|
we can center to the highlighted annotation
|
|
*/
|
|
if let highlightedAnnotation = highlightedAnnotation, showsUserLocationMode != .follow {
|
|
mapView.setCenter(highlightedAnnotation.coordinate, zoomLevel: Constants.mapZoomLevel, animated: true)
|
|
}
|
|
|
|
switch showsUserLocationMode {
|
|
case .follow:
|
|
mapView.showsUserLocation = true
|
|
mapView.userTrackingMode = .follow
|
|
case .show:
|
|
mapView.showsUserLocation = true
|
|
mapView.userTrackingMode = .none
|
|
case .hide:
|
|
mapView.showsUserLocation = false
|
|
mapView.userTrackingMode = .none
|
|
}
|
|
}
|
|
|
|
func makeCoordinator() -> Coordinator {
|
|
Coordinator(self)
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private func makeMapView() -> MGLMapView {
|
|
let mapView = MGLMapView(frame: .zero, styleURL: tileServerMapURL)
|
|
|
|
mapView.logoView.isHidden = true
|
|
mapView.attributionButton.isHidden = true
|
|
|
|
return mapView
|
|
}
|
|
}
|
|
|
|
// MARK: - Coordinator
|
|
|
|
extension LocationSharingMapView {
|
|
class Coordinator: NSObject, MGLMapViewDelegate, UIGestureRecognizerDelegate {
|
|
// MARK: - Properties
|
|
|
|
var locationSharingMapView: LocationSharingMapView
|
|
|
|
// MARK: - Setup
|
|
|
|
init(_ locationSharingMapView: LocationSharingMapView) {
|
|
self.locationSharingMapView = locationSharingMapView
|
|
}
|
|
|
|
// MARK: - MGLMapViewDelegate
|
|
|
|
func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
|
|
if let userLocationAnnotation = annotation as? UserLocationAnnotation {
|
|
return LocationAnnotationView(userLocationAnnotation: userLocationAnnotation)
|
|
} else if let pinLocationAnnotation = annotation as? PinLocationAnnotation {
|
|
return LocationAnnotationView(pinLocationAnnotation: pinLocationAnnotation)
|
|
} else if annotation is MGLUserLocation {
|
|
if let currentUserAvatarData = locationSharingMapView.userAvatarData {
|
|
// Replace default current location annotation view with a UserLocationAnnotatonView when the map is center on user location
|
|
return LocationAnnotationView(avatarData: currentUserAvatarData)
|
|
} else {
|
|
return LocationAnnotationView(userPinLocationAnnotation: annotation)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
|
|
// bwi #5379: set copyright to info from style json if available. Needs reevaluation if there is more than one source
|
|
|
|
var attribution = LocationSharingAttribution()
|
|
|
|
for source in style.sources {
|
|
if let tileSource = source as? MGLRasterTileSource {
|
|
for attributionInfo in tileSource.attributionInfos {
|
|
attribution.copyrightTexts.append(attributionInfo.title.plainTextString())
|
|
attribution.copyrightLinks.append(attributionInfo.url)
|
|
}
|
|
}
|
|
}
|
|
|
|
locationSharingMapView.attributionsChanged?(attribution)
|
|
}
|
|
|
|
func mapViewDidFailLoadingMap(_ mapView: MGLMapView, withError error: Error) {
|
|
locationSharingMapView.errorSubject.send(.failedLoadingMap)
|
|
}
|
|
|
|
func mapView(_ mapView: MGLMapView, didUpdate userLocation: MGLUserLocation?) {
|
|
locationSharingMapView.userLocation = userLocation?.coordinate
|
|
}
|
|
|
|
func mapView(_ mapView: MGLMapView, didChangeLocationManagerAuthorization manager: MGLLocationManager) {
|
|
guard mapView.showsUserLocation else {
|
|
return
|
|
}
|
|
|
|
switch manager.authorizationStatus {
|
|
case .restricted:
|
|
fallthrough
|
|
case .denied:
|
|
locationSharingMapView.errorSubject.send(.invalidLocationAuthorization)
|
|
// bwi: center map if gps is not available
|
|
centerMapOnDefaultPosition(mapView: mapView)
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
|
|
func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {
|
|
locationSharingMapView.mapCenterCoordinate = mapView.centerCoordinate
|
|
}
|
|
|
|
// MARK: Callout
|
|
|
|
func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
|
|
annotation is UserLocationAnnotation && locationSharingMapView.userAnnotationCanShowCallout
|
|
}
|
|
|
|
func mapView(_ mapView: MGLMapView, calloutViewFor annotation: MGLAnnotation) -> MGLCalloutView? {
|
|
if let userLocationAnnotation = annotation as? UserLocationAnnotation {
|
|
return UserAnnotationCalloutView(userLocationAnnotation: userLocationAnnotation)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func mapView(_ mapView: MGLMapView, tapOnCalloutFor annotation: MGLAnnotation) {
|
|
locationSharingMapView.onCalloutTap?(annotation)
|
|
// Hide the callout
|
|
mapView.deselectAnnotation(annotation, animated: true)
|
|
}
|
|
|
|
// MARK: UIGestureRecognizer
|
|
|
|
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
|
gestureRecognizer is UIPanGestureRecognizer
|
|
}
|
|
|
|
@objc
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - MGLMapView convenient methods
|
|
|
|
extension MGLMapView {
|
|
func vc_removeAllAnnotations() {
|
|
guard let annotations = annotations else {
|
|
return
|
|
}
|
|
removeAnnotations(annotations)
|
|
}
|
|
}
|