mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-30 13:16:58 +02:00
Merge branch 'develop' into gil/5231_SP3-1_Update_room_settings_for_Spaces
# Conflicts: # Riot/Assets/en.lproj/Vector.strings # Riot/Generated/Strings.swift # Riot/Modules/Spaces/SpaceMembers/MemberList/SpaceMemberListViewController.swift # Riot/Modules/Spaces/SpaceRoomList/ExploreRoom/SpaceExploreRoomViewController.swift
This commit is contained in:
+120
@@ -0,0 +1,120 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
import Keys
|
||||
|
||||
struct LocationSharingCoordinatorParameters {
|
||||
let roomDataSource: MXKRoomDataSource
|
||||
let mediaManager: MXMediaManager
|
||||
let avatarData: AvatarInputProtocol
|
||||
let location: CLLocationCoordinate2D?
|
||||
}
|
||||
|
||||
final class LocationSharingCoordinator: Coordinator, Presentable {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let parameters: LocationSharingCoordinatorParameters
|
||||
private let locationSharingHostingController: UIViewController
|
||||
private var _locationSharingViewModel: Any? = nil
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
fileprivate var locationSharingViewModel: LocationSharingViewModel {
|
||||
return _locationSharingViewModel as! LocationSharingViewModel
|
||||
}
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var childCoordinators: [Coordinator] = []
|
||||
|
||||
var completion: (() -> Void)?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
init(parameters: LocationSharingCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
|
||||
let viewModel = LocationSharingViewModel(tileServerMapURL: BuildSettings.tileServerMapURL,
|
||||
avatarData: parameters.avatarData,
|
||||
location: parameters.location)
|
||||
let view = LocationSharingView(context: viewModel.context)
|
||||
.addDependency(AvatarService.instantiate(mediaManager: parameters.mediaManager))
|
||||
|
||||
_locationSharingViewModel = viewModel
|
||||
locationSharingHostingController = VectorHostingController(rootView: view)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
func start() {
|
||||
guard #available(iOS 14.0, *) else {
|
||||
MXLog.error("[LocationSharingCoordinator] start: Invalid iOS version, returning.")
|
||||
return
|
||||
}
|
||||
|
||||
locationSharingViewModel.completion = { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
|
||||
switch result {
|
||||
case .cancel:
|
||||
self.completion?()
|
||||
case .share(let latitude, let longitude):
|
||||
if let location = self.parameters.location {
|
||||
self.showActivityControllerForLocation(location)
|
||||
return
|
||||
}
|
||||
|
||||
self.locationSharingViewModel.dispatch(action: .startLoading)
|
||||
|
||||
self.parameters.roomDataSource.sendLocation(withLatitude: latitude,
|
||||
longitude: longitude,
|
||||
description: nil) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
|
||||
self.locationSharingViewModel.dispatch(action: .stopLoading(nil))
|
||||
self.completion?()
|
||||
} failure: { [weak self] error in
|
||||
guard let self = self else { return }
|
||||
|
||||
MXLog.error("[LocationSharingCoordinator] Failed sharing location with error: \(String(describing: error))")
|
||||
self.locationSharingViewModel.dispatch(action: .stopLoading(error))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Presentable
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
return locationSharingHostingController
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func showActivityControllerForLocation(_ location: CLLocationCoordinate2D) {
|
||||
let vc = UIActivityViewController(activityItems: [ShareToMapsAppActivity.urlForMapsAppType(.apple, location: location)],
|
||||
applicationActivities: [ShareToMapsAppActivity(type: .apple, location: location),
|
||||
ShareToMapsAppActivity(type: .google, location: location)])
|
||||
|
||||
locationSharingHostingController.present(vc, animated: true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension UIActivity.ActivityType {
|
||||
static let shareToMapsApp = UIActivity.ActivityType("Element.ShareToMapsApp")
|
||||
}
|
||||
|
||||
class ShareToMapsAppActivity: UIActivity {
|
||||
enum MapsAppType {
|
||||
case apple
|
||||
case google
|
||||
}
|
||||
|
||||
let type: MapsAppType
|
||||
let location: CLLocationCoordinate2D
|
||||
|
||||
private override init() {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
init(type: MapsAppType, location: CLLocationCoordinate2D) {
|
||||
self.type = type
|
||||
self.location = location
|
||||
}
|
||||
|
||||
static func urlForMapsAppType(_ type: MapsAppType, location: CLLocationCoordinate2D) -> URL {
|
||||
switch type {
|
||||
case .apple:
|
||||
return URL(string: "https://maps.apple.com?ll=\(location.latitude),\(location.longitude)&q=Pin")!
|
||||
case .google:
|
||||
return URL(string: "https://www.google.com/maps/search/?api=1&query=\(location.latitude),\(location.longitude)")!
|
||||
}
|
||||
}
|
||||
|
||||
override var activityTitle: String? {
|
||||
switch type {
|
||||
case .apple:
|
||||
return VectorL10n.locationSharingOpenAppleMaps
|
||||
case .google:
|
||||
return VectorL10n.locationSharingOpenGoogleMaps
|
||||
}
|
||||
}
|
||||
|
||||
var activityCategory: UIActivity.Category {
|
||||
return .action
|
||||
}
|
||||
|
||||
override var activityType: UIActivity.ActivityType {
|
||||
return .shareToMapsApp
|
||||
}
|
||||
|
||||
override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
override func prepare(withActivityItems activityItems: [Any]) {
|
||||
let url = Self.urlForMapsAppType(type, location: location)
|
||||
|
||||
UIApplication.shared.open(url, options: [:]) { [weak self] result in
|
||||
self?.activityDidFinish(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import Combine
|
||||
import CoreLocation
|
||||
|
||||
enum LocationSharingViewError {
|
||||
case failedLoadingMap
|
||||
case failedLocatingUser
|
||||
case invalidLocationAuthorization
|
||||
case failedSharingLocation
|
||||
}
|
||||
|
||||
enum LocationSharingStateAction {
|
||||
case error(LocationSharingViewError, LocationSharingViewModelCallback?)
|
||||
case startLoading
|
||||
case stopLoading(Error?)
|
||||
}
|
||||
|
||||
enum LocationSharingViewAction {
|
||||
case cancel
|
||||
case share
|
||||
}
|
||||
|
||||
typealias LocationSharingViewModelCallback = ((LocationSharingViewModelResult) -> Void)
|
||||
|
||||
enum LocationSharingViewModelResult {
|
||||
case cancel
|
||||
case share(latitude: Double, longitude: Double)
|
||||
}
|
||||
|
||||
@available(iOS 14, *)
|
||||
struct LocationSharingViewState: BindableState {
|
||||
let tileServerMapURL: URL
|
||||
let avatarData: AvatarInputProtocol
|
||||
let location: CLLocationCoordinate2D?
|
||||
|
||||
var showLoadingIndicator: Bool = false
|
||||
|
||||
var shareButtonVisible: Bool {
|
||||
return location == nil
|
||||
}
|
||||
|
||||
var shareButtonEnabled: Bool {
|
||||
!showLoadingIndicator
|
||||
}
|
||||
|
||||
let errorSubject = PassthroughSubject<LocationSharingViewError, Never>()
|
||||
|
||||
var bindings = LocationSharingViewStateBindings()
|
||||
}
|
||||
|
||||
struct LocationSharingViewStateBindings {
|
||||
var alertInfo: ErrorAlertInfo?
|
||||
var userLocation: CLLocationCoordinate2D?
|
||||
}
|
||||
|
||||
struct ErrorAlertInfo: Identifiable {
|
||||
enum AlertType {
|
||||
case mapLoadingError
|
||||
case userLocatingError
|
||||
case authorizationError
|
||||
case locationSharingError
|
||||
}
|
||||
|
||||
let id: AlertType
|
||||
let title: String
|
||||
let primaryButton: (title: String, action: (() -> Void)?)
|
||||
let secondaryButton: (title: String, action: (() -> Void)?)?
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import Keys
|
||||
import CoreLocation
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
enum MockLocationSharingScreenState: MockScreenState, CaseIterable {
|
||||
case shareUserLocation
|
||||
case displayExistingLocation
|
||||
|
||||
var screenType: Any.Type {
|
||||
MockLocationSharingScreenState.self
|
||||
}
|
||||
|
||||
var screenView: ([Any], AnyView) {
|
||||
|
||||
var location: CLLocationCoordinate2D?
|
||||
if self == .displayExistingLocation {
|
||||
location = CLLocationCoordinate2D(latitude: 51.4932641, longitude: -0.257096)
|
||||
}
|
||||
|
||||
let mapURL = URL(string: "https://api.maptiler.com/maps/streets/style.json?key=" + RiotKeys().mapTilerAPIKey)!
|
||||
let viewModel = LocationSharingViewModel(tileServerMapURL: mapURL,
|
||||
avatarData: AvatarInput(mxContentUri: "", matrixItemId: "", displayName: "Alice"),
|
||||
location: location)
|
||||
return ([viewModel],
|
||||
AnyView(LocationSharingView(context: viewModel.context)
|
||||
.addDependency(MockAvatarService.example)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
import CoreLocation
|
||||
|
||||
@available(iOS 14, *)
|
||||
typealias LocationSharingViewModelType = StateStoreViewModel< LocationSharingViewState,
|
||||
LocationSharingStateAction,
|
||||
LocationSharingViewAction >
|
||||
@available(iOS 14, *)
|
||||
class LocationSharingViewModel: LocationSharingViewModelType {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var completion: ((LocationSharingViewModelResult) -> Void)?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(tileServerMapURL: URL, avatarData: AvatarInputProtocol, location: CLLocationCoordinate2D? = nil) {
|
||||
let viewState = LocationSharingViewState(tileServerMapURL: tileServerMapURL, avatarData: avatarData, location: location)
|
||||
super.init(initialViewState: viewState)
|
||||
|
||||
state.errorSubject.sink { [weak self] error in
|
||||
guard let self = self else { return }
|
||||
self.dispatch(action: .error(error, self.completion))
|
||||
}.store(in: &cancellables)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
override func process(viewAction: LocationSharingViewAction) {
|
||||
switch viewAction {
|
||||
case .cancel:
|
||||
completion?(.cancel)
|
||||
case .share:
|
||||
if let location = state.location {
|
||||
completion?(.share(latitude: location.latitude, longitude: location.longitude))
|
||||
return
|
||||
}
|
||||
|
||||
guard let location = state.bindings.userLocation else {
|
||||
dispatch(action: .error(.failedLocatingUser, completion))
|
||||
return
|
||||
}
|
||||
|
||||
completion?(.share(latitude: location.latitude, longitude: location.longitude))
|
||||
}
|
||||
}
|
||||
|
||||
override class func reducer(state: inout LocationSharingViewState, action: LocationSharingStateAction) {
|
||||
switch action {
|
||||
case .error(let error, let completion):
|
||||
|
||||
switch error {
|
||||
case .failedLoadingMap:
|
||||
state.bindings.alertInfo = ErrorAlertInfo(id: .mapLoadingError,
|
||||
title: VectorL10n.locationSharingLoadingMapErrorTitle(AppInfo.current.displayName) ,
|
||||
primaryButton: (VectorL10n.ok, { completion?(.cancel) }),
|
||||
secondaryButton: nil)
|
||||
case .failedLocatingUser:
|
||||
state.bindings.alertInfo = ErrorAlertInfo(id: .userLocatingError,
|
||||
title: VectorL10n.locationSharingLocatingUserErrorTitle(AppInfo.current.displayName),
|
||||
primaryButton: (VectorL10n.ok, { completion?(.cancel) }),
|
||||
secondaryButton: nil)
|
||||
case .invalidLocationAuthorization:
|
||||
state.bindings.alertInfo = ErrorAlertInfo(id: .authorizationError,
|
||||
title: VectorL10n.locationSharingInvalidAuthorizationErrorTitle(AppInfo.current.displayName),
|
||||
primaryButton: (VectorL10n.locationSharingInvalidAuthorizationNotNow, { completion?(.cancel) }),
|
||||
secondaryButton: (VectorL10n.locationSharingInvalidAuthorizationSettings, {
|
||||
if let applicationSettingsURL = URL(string:UIApplication.openSettingsURLString) {
|
||||
UIApplication.shared.open(applicationSettingsURL)
|
||||
}
|
||||
}))
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
case .startLoading:
|
||||
state.showLoadingIndicator = true
|
||||
case .stopLoading(let error):
|
||||
state.showLoadingIndicator = false
|
||||
|
||||
if error != nil {
|
||||
state.bindings.alertInfo = ErrorAlertInfo(id: .locationSharingError,
|
||||
title: VectorL10n.locationSharingInvalidAuthorizationErrorTitle(AppInfo.current.displayName),
|
||||
primaryButton: (VectorL10n.ok, nil),
|
||||
secondaryButton: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import RiotSwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class LocationSharingUITests: XCTestCase {
|
||||
|
||||
private var app: XCUIApplication!
|
||||
|
||||
override func setUp() {
|
||||
continueAfterFailure = false
|
||||
|
||||
app = XCUIApplication()
|
||||
app.launch()
|
||||
}
|
||||
|
||||
func testInitialUserLocation() {
|
||||
goToScreenWithIdentifier(MockLocationSharingScreenState.shareUserLocation.title)
|
||||
|
||||
XCTAssertTrue(app.buttons["Cancel"].exists)
|
||||
XCTAssertTrue(app.buttons["Share"].exists)
|
||||
XCTAssertTrue(app.otherElements["Map"].exists)
|
||||
}
|
||||
|
||||
func testInitialExistingLocation() {
|
||||
goToScreenWithIdentifier(MockLocationSharingScreenState.displayExistingLocation.title)
|
||||
|
||||
XCTAssertTrue(app.buttons["Cancel"].exists)
|
||||
XCTAssertTrue(app.buttons["location share icon"].exists)
|
||||
XCTAssertTrue(app.otherElements["Map"].exists)
|
||||
}
|
||||
|
||||
// Need a delay when showing the map otherwise the simulator breaks
|
||||
private func goToScreenWithIdentifier(_ identifier: String) {
|
||||
app.goToScreenWithIdentifier(identifier)
|
||||
sleep(2)
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import Combine
|
||||
import CoreLocation
|
||||
|
||||
@testable import RiotSwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class LocationSharingViewModelTests: XCTestCase {
|
||||
|
||||
var cancellables = Set<AnyCancellable>()
|
||||
|
||||
func testInitialState() {
|
||||
let viewModel = buildViewModel(withLocation: false)
|
||||
|
||||
XCTAssertTrue(viewModel.context.viewState.shareButtonEnabled)
|
||||
XCTAssertTrue(viewModel.context.viewState.shareButtonVisible)
|
||||
XCTAssertFalse(viewModel.context.viewState.showLoadingIndicator)
|
||||
|
||||
XCTAssertNotNil(viewModel.context.viewState.tileServerMapURL)
|
||||
XCTAssertNotNil(viewModel.context.viewState.avatarData)
|
||||
|
||||
XCTAssertNil(viewModel.context.viewState.location)
|
||||
XCTAssertNil(viewModel.context.viewState.bindings.userLocation)
|
||||
XCTAssertNil(viewModel.context.viewState.bindings.alertInfo)
|
||||
}
|
||||
|
||||
func testCancellation() {
|
||||
let viewModel = buildViewModel(withLocation: false)
|
||||
|
||||
let expectation = self.expectation(description: "Cancellation completion should be invoked")
|
||||
|
||||
viewModel.completion = { result in
|
||||
switch result {
|
||||
case .share:
|
||||
XCTFail()
|
||||
case .cancel:
|
||||
expectation.fulfill()
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.context.send(viewAction: .cancel)
|
||||
|
||||
waitForExpectations(timeout: 3)
|
||||
}
|
||||
|
||||
func testShareNoUserLocation() {
|
||||
let viewModel = buildViewModel(withLocation: false)
|
||||
|
||||
XCTAssertNil(viewModel.context.viewState.bindings.userLocation)
|
||||
XCTAssertNil(viewModel.context.viewState.location)
|
||||
|
||||
viewModel.context.send(viewAction: .share)
|
||||
|
||||
XCTAssertNotNil(viewModel.context.viewState.bindings.alertInfo)
|
||||
XCTAssertEqual(viewModel.context.viewState.bindings.alertInfo?.id, .userLocatingError)
|
||||
}
|
||||
|
||||
func testShareExistingLocation() {
|
||||
let viewModel = buildViewModel(withLocation: true)
|
||||
|
||||
let expectation = self.expectation(description: "Share completion should be invoked")
|
||||
|
||||
viewModel.completion = { result in
|
||||
switch result {
|
||||
case .share(let latitude, let longitude):
|
||||
XCTAssertEqual(latitude, viewModel.context.viewState.location?.latitude)
|
||||
XCTAssertEqual(longitude, viewModel.context.viewState.location?.longitude)
|
||||
expectation.fulfill()
|
||||
case .cancel:
|
||||
XCTFail()
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertNil(viewModel.context.viewState.bindings.userLocation)
|
||||
XCTAssertNotNil(viewModel.context.viewState.location)
|
||||
|
||||
viewModel.context.send(viewAction: .share)
|
||||
|
||||
XCTAssertNil(viewModel.context.viewState.bindings.alertInfo)
|
||||
|
||||
waitForExpectations(timeout: 3)
|
||||
}
|
||||
|
||||
func testLoading() {
|
||||
let viewModel = buildViewModel(withLocation: false)
|
||||
|
||||
viewModel.dispatch(action: .startLoading)
|
||||
|
||||
XCTAssertFalse(viewModel.context.viewState.shareButtonEnabled)
|
||||
XCTAssertTrue(viewModel.context.viewState.showLoadingIndicator)
|
||||
|
||||
viewModel.dispatch(action: .stopLoading(nil))
|
||||
|
||||
XCTAssertTrue(viewModel.context.viewState.shareButtonEnabled)
|
||||
XCTAssertFalse(viewModel.context.viewState.showLoadingIndicator)
|
||||
}
|
||||
|
||||
func testInvalidLocationAuthorization() {
|
||||
let viewModel = buildViewModel(withLocation: false)
|
||||
|
||||
viewModel.context.viewState.errorSubject.send(.invalidLocationAuthorization)
|
||||
|
||||
XCTAssertNotNil(viewModel.context.alertInfo)
|
||||
XCTAssertEqual(viewModel.context.viewState.bindings.alertInfo?.id, .authorizationError)
|
||||
}
|
||||
|
||||
private func buildViewModel(withLocation: Bool) -> LocationSharingViewModel {
|
||||
LocationSharingViewModel(tileServerMapURL: URL(string: "http://empty.com")!,
|
||||
avatarData: AvatarInput(mxContentUri: "", matrixItemId: "", displayName: ""),
|
||||
location: (withLocation ? CLLocationCoordinate2D(latitude: 51.4932641, longitude: -0.257096) : nil))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
import Mapbox
|
||||
|
||||
@available(iOS 14, *)
|
||||
struct LocationSharingMapView: UIViewRepresentable {
|
||||
private struct Constants {
|
||||
static let mapZoomLevel = 15.0
|
||||
}
|
||||
|
||||
let tileServerMapURL: URL
|
||||
let avatarData: AvatarInputProtocol
|
||||
let location: CLLocationCoordinate2D?
|
||||
|
||||
let errorSubject: PassthroughSubject<LocationSharingViewError, Never>
|
||||
@Binding var userLocation: CLLocationCoordinate2D?
|
||||
|
||||
func makeUIView(context: Context) -> some UIView {
|
||||
let mapView = MGLMapView(frame: .zero, styleURL: tileServerMapURL)
|
||||
mapView.delegate = context.coordinator
|
||||
|
||||
mapView.logoView.isHidden = true
|
||||
mapView.attributionButton.isHidden = true
|
||||
|
||||
if let location = location {
|
||||
mapView.setCenter(location, zoomLevel: Constants.mapZoomLevel, animated: false)
|
||||
|
||||
let pointAnnotation = MGLPointAnnotation()
|
||||
pointAnnotation.coordinate = location
|
||||
mapView.addAnnotation(pointAnnotation)
|
||||
} else {
|
||||
mapView.showsUserLocation = true
|
||||
mapView.userTrackingMode = .follow
|
||||
}
|
||||
|
||||
return mapView
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: UIViewType, context: Context) {
|
||||
|
||||
}
|
||||
|
||||
func makeCoordinator() -> LocationSharingMapViewCoordinator {
|
||||
LocationSharingMapViewCoordinator(avatarData: avatarData,
|
||||
errorSubject: errorSubject,
|
||||
userLocation: $userLocation)
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14, *)
|
||||
class LocationSharingMapViewCoordinator: NSObject, MGLMapViewDelegate {
|
||||
|
||||
private let avatarData: AvatarInputProtocol
|
||||
private let errorSubject: PassthroughSubject<LocationSharingViewError, Never>
|
||||
@Binding var userLocation: CLLocationCoordinate2D?
|
||||
|
||||
init(avatarData: AvatarInputProtocol,
|
||||
errorSubject: PassthroughSubject<LocationSharingViewError, Never>,
|
||||
userLocation: Binding<CLLocationCoordinate2D?>) {
|
||||
self.avatarData = avatarData
|
||||
self.errorSubject = errorSubject
|
||||
self._userLocation = userLocation
|
||||
}
|
||||
|
||||
// MARK: - MGLMapViewDelegate
|
||||
|
||||
func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
|
||||
return UserLocationAnnotatonView(avatarData: avatarData)
|
||||
}
|
||||
|
||||
func mapViewDidFailLoadingMap(_ mapView: MGLMapView, withError error: Error) {
|
||||
errorSubject.send(.failedLoadingMap)
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MGLMapView, didFailToLocateUserWithError error: Error) {
|
||||
errorSubject.send(.failedLocatingUser)
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MGLMapView, didUpdate userLocation: MGLUserLocation?) {
|
||||
self.userLocation = userLocation?.coordinate
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MGLMapView, didChangeLocationManagerAuthorization manager: MGLLocationManager) {
|
||||
switch manager.authorizationStatus {
|
||||
case .restricted:
|
||||
fallthrough
|
||||
case .denied:
|
||||
errorSubject.send(.failedLocatingUser)
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14, *)
|
||||
private class UserLocationAnnotatonView: MGLUserLocationAnnotationView {
|
||||
|
||||
init(avatarData: AvatarInputProtocol) {
|
||||
super.init(frame: .zero)
|
||||
|
||||
guard let avatarImageView = UIHostingController(rootView: LocationSharingUserMarkerView(avatarData: avatarData)).view else {
|
||||
return
|
||||
}
|
||||
|
||||
addSubview(avatarImageView)
|
||||
|
||||
addConstraints([topAnchor.constraint(equalTo: avatarImageView.topAnchor),
|
||||
leadingAnchor.constraint(equalTo: avatarImageView.leadingAnchor),
|
||||
bottomAnchor.constraint(equalTo: avatarImageView.bottomAnchor),
|
||||
trailingAnchor.constraint(equalTo: avatarImageView.trailingAnchor)])
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct LocationSharingUserMarkerView: View {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@Environment(\.theme) private var theme: ThemeSwiftUI
|
||||
|
||||
// MARK: Public
|
||||
|
||||
let avatarData: AvatarInputProtocol
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .center) {
|
||||
Image(uiImage: Asset.Images.locationUserMarker.image)
|
||||
AvatarImage(avatarData: avatarData, size: .large)
|
||||
.offset(.init(width: 0.0, height: -1.5))
|
||||
}
|
||||
.accentColor(theme.colors.accent)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct LocationSharingUserMarkerView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let avatarData = AvatarInput(mxContentUri: "",
|
||||
matrixItemId: "",
|
||||
displayName: "Alice")
|
||||
|
||||
LocationSharingUserMarkerView(avatarData: avatarData)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import CoreLocation
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct LocationSharingView: View {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@Environment(\.theme) private var theme: ThemeSwiftUI
|
||||
|
||||
// MARK: Public
|
||||
|
||||
@ObservedObject var context: LocationSharingViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
LocationSharingMapView(tileServerMapURL: context.viewState.tileServerMapURL,
|
||||
avatarData: context.viewState.avatarData,
|
||||
location: context.viewState.location,
|
||||
errorSubject: context.viewState.errorSubject,
|
||||
userLocation: $context.userLocation)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
Button(VectorL10n.cancel, action: {
|
||||
context.send(viewAction: .cancel)
|
||||
})
|
||||
}
|
||||
ToolbarItem(placement: .principal) {
|
||||
Text(VectorL10n.locationSharingTitle)
|
||||
.font(.headline)
|
||||
.foregroundColor(theme.colors.primaryContent)
|
||||
}
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
if context.viewState.location != nil {
|
||||
Button {
|
||||
context.send(viewAction: .share)
|
||||
} label: {
|
||||
Image(uiImage: Asset.Images.locationShareIcon.image)
|
||||
}
|
||||
.disabled(!context.viewState.shareButtonEnabled)
|
||||
} else {
|
||||
Button(VectorL10n.locationSharingShareAction, action: {
|
||||
context.send(viewAction: .share)
|
||||
})
|
||||
.disabled(!context.viewState.shareButtonEnabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.ignoresSafeArea()
|
||||
.alert(item: $context.alertInfo) { info in
|
||||
if let secondaryButton = info.secondaryButton {
|
||||
return Alert(title: Text(info.title),
|
||||
primaryButton: .default(Text(info.primaryButton.title)) {
|
||||
info.primaryButton.action?()
|
||||
},
|
||||
secondaryButton: .default(Text(secondaryButton.title)) {
|
||||
secondaryButton.action?()
|
||||
})
|
||||
} else {
|
||||
return Alert(title: Text(info.title),
|
||||
dismissButton: .default(Text(info.primaryButton.title)) {
|
||||
info.primaryButton.action?()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
.accentColor(theme.colors.accent)
|
||||
.activityIndicator(show: context.viewState.showLoadingIndicator)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var activityIndicator: some View {
|
||||
if context.viewState.showLoadingIndicator {
|
||||
ActivityIndicator()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct LocationSharingView_Previews: PreviewProvider {
|
||||
static let stateRenderer = MockLocationSharingScreenState.stateRenderer
|
||||
static var previews: some View {
|
||||
stateRenderer.screenGroup()
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,10 @@ import UIKit
|
||||
import SwiftUI
|
||||
|
||||
struct PollEditFormCoordinatorParameters {
|
||||
let navigationRouter: NavigationRouterType?
|
||||
let room: MXRoom
|
||||
}
|
||||
|
||||
final class PollEditFormCoordinator: Coordinator {
|
||||
final class PollEditFormCoordinator: Coordinator, Presentable {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
@@ -42,9 +41,10 @@ final class PollEditFormCoordinator: Coordinator {
|
||||
|
||||
// MARK: Public
|
||||
|
||||
// Must be used only internally
|
||||
var childCoordinators: [Coordinator] = []
|
||||
|
||||
var completion: (() -> Void)?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
@@ -65,13 +65,11 @@ final class PollEditFormCoordinator: Coordinator {
|
||||
return
|
||||
}
|
||||
|
||||
parameters.navigationRouter?.present(pollEditFormHostingController, animated: true)
|
||||
|
||||
pollEditFormViewModel.completion = { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
switch result {
|
||||
case .cancel:
|
||||
self.parameters.navigationRouter?.dismissModule(animated: true, completion: nil)
|
||||
self.completion?()
|
||||
case .create(let question, let answerOptions):
|
||||
var options = [MXEventContentPollStartAnswerOption]()
|
||||
for answerOption in answerOptions {
|
||||
@@ -88,8 +86,8 @@ final class PollEditFormCoordinator: Coordinator {
|
||||
self.parameters.room.sendPollStart(withContent: pollStartContent, localEcho: nil) { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
|
||||
self.parameters.navigationRouter?.dismissModule(animated: true, completion: nil)
|
||||
self.pollEditFormViewModel.dispatch(action: .stopLoading(nil))
|
||||
self.completion?()
|
||||
} failure: { [weak self] error in
|
||||
guard let self = self else { return }
|
||||
|
||||
@@ -99,4 +97,10 @@ final class PollEditFormCoordinator: Coordinator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
return pollEditFormHostingController
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ struct PollEditForm: View {
|
||||
.alert(isPresented: $viewModel.showsFailureAlert) {
|
||||
Alert(title: Text(VectorL10n.pollEditFormPostFailureTitle),
|
||||
message: Text(VectorL10n.pollEditFormPostFailureSubtitle),
|
||||
dismissButton: .default(Text(VectorL10n.pollEditFormPostFailureAction)))
|
||||
dismissButton: .default(Text(VectorL10n.ok)))
|
||||
}
|
||||
.frame(minHeight: proxy.size.height) // Make the VStack fill the ScrollView's parent
|
||||
.toolbar {
|
||||
|
||||
@@ -27,7 +27,7 @@ struct PollTimelineCoordinatorParameters {
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
final class PollTimelineCoordinator: Coordinator, PollAggregatorDelegate {
|
||||
final class PollTimelineCoordinator: Coordinator, Presentable, PollAggregatorDelegate {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ struct PollTimelineView: View {
|
||||
.alert(isPresented: $viewModel.showsClosingFailureAlert) {
|
||||
Alert(title: Text(VectorL10n.pollTimelineNotClosedTitle),
|
||||
message: Text(VectorL10n.pollTimelineNotClosedSubtitle),
|
||||
dismissButton: .default(Text(VectorL10n.pollTimelineNotClosedAction)))
|
||||
dismissButton: .default(Text(VectorL10n.ok)))
|
||||
}
|
||||
}
|
||||
.disabled(poll.closed)
|
||||
@@ -62,7 +62,7 @@ struct PollTimelineView: View {
|
||||
.alert(isPresented: $viewModel.showsAnsweringFailureAlert) {
|
||||
Alert(title: Text(VectorL10n.pollTimelineVoteNotRegisteredTitle),
|
||||
message: Text(VectorL10n.pollTimelineVoteNotRegisteredSubtitle),
|
||||
dismissButton: .default(Text(VectorL10n.pollTimelineVoteNotRegisteredAction)))
|
||||
dismissButton: .default(Text(VectorL10n.ok)))
|
||||
}
|
||||
}
|
||||
.padding([.horizontal, .top], 2.0)
|
||||
|
||||
@@ -26,7 +26,7 @@ protocol UserSuggestionCoordinatorDelegate: AnyObject {
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
final class UserSuggestionCoordinator: Coordinator {
|
||||
final class UserSuggestionCoordinator: Coordinator, Presentable {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
|
||||
Reference in New Issue
Block a user