SP3.1: Update room settings for Spaces element-ios#5231

- Changed the Room Settings screen according to the new design
- Implemented the room access flow
- Added room upgrade support
- Implemented the room suggestion screen
This commit is contained in:
Gil Eluard
2022-01-13 15:53:45 +01:00
parent 085fc7d5b0
commit ce226cff8a
78 changed files with 3755 additions and 196 deletions
@@ -0,0 +1,133 @@
// File created from FlowTemplate
// $ createRootCoordinator.sh RoomAccessCoordinator RoomAccess
/*
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 UIKit
/// Actions returned by the coordinator callback
enum RoomAccessCoordinatorCoordinatorAction {
case done(String)
case cancel
}
@objcMembers
final class RoomAccessCoordinator: Coordinator {
// MARK: - Properties
// MARK: Private
private let parameters: RoomAccessCoordinatorParameters
private var navigationRouter: NavigationRouterType {
return self.parameters.navigationRouter
}
// MARK: Public
// Must be used only internally
var childCoordinators: [Coordinator] = []
var callback: ((RoomAccessCoordinatorCoordinatorAction) -> Void)?
// MARK: - Setup
init(parameters: RoomAccessCoordinatorParameters) {
self.parameters = parameters
}
// MARK: - Public
func start() {
if #available(iOS 14.0, *) {
MXLog.debug("[RoomAccessCoordinator] did start.")
let rootCoordinator = self.createRoomAccessTypeCoordinator()
rootCoordinator.start()
self.add(childCoordinator: rootCoordinator)
if self.navigationRouter.modules.isEmpty == false {
self.navigationRouter.push(rootCoordinator, animated: true, popCompletion: { [weak self] in
self?.remove(childCoordinator: rootCoordinator)
})
} else {
self.navigationRouter.setRootModule(rootCoordinator) { [weak self] in
self?.remove(childCoordinator: rootCoordinator)
}
}
}
}
func toPresentable() -> UIViewController {
return self.navigationRouter.toPresentable()
}
// MARK: - Private
@available(iOS 14.0, *)
func pushScreen(with coordinator: Coordinator & Presentable) {
add(childCoordinator: coordinator)
self.navigationRouter.push(coordinator, animated: true, popCompletion: { [weak self] in
self?.remove(childCoordinator: coordinator)
})
coordinator.start()
}
@available(iOS 14.0, *)
private func createRoomAccessTypeCoordinator() -> RoomAccessTypeChooserCoordinator {
let coordinator: RoomAccessTypeChooserCoordinator = RoomAccessTypeChooserCoordinator(parameters: RoomAccessTypeChooserCoordinatorParameters(roomId: parameters.room.roomId, session: parameters.room.mxSession))
coordinator.callback = { [weak self] result in
guard let self = self else { return }
switch result {
case .done(let roomId):
self.callback?(.done(roomId))
case .cancel:
self.callback?(.cancel)
case .spaceSelection(let roomId, _):
self.pushScreen(with: self.createRestrictedAccessSpaceChooserCoordinator(with: roomId))
}
}
return coordinator
}
@available(iOS 14.0, *)
private func createRestrictedAccessSpaceChooserCoordinator(with roomId: String) -> MatrixItemChooserCoordinator {
let paramaters = MatrixItemChooserCoordinatorParameters(
session: parameters.room.mxSession,
viewProvider: RoomRestrictedAccessSpaceChooserViewProvider(navTitle: VectorL10n.roomAccessSettingsScreenNavTitle),
itemsProcessor: RoomRestrictedAccessSpaceChooserItemsProcessor(roomId: roomId, session: parameters.room.mxSession))
let coordinator = MatrixItemChooserCoordinator(parameters: paramaters)
coordinator.completion = { [weak self] result in
guard let self = self else { return }
switch result {
case .back:
self.navigationRouter.popModule(animated: true)
case .cancel:
self.callback?(.cancel)
case .done:
self.callback?(.done(roomId))
}
}
return coordinator
}
}
@@ -0,0 +1,94 @@
//
// 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 UIKit
@objc protocol RoomAccessCoordinatorBridgePresenterDelegate {
func roomAccessCoordinatorBridgePresenterDelegateDidCancel(_ coordinatorBridgePresenter: RoomAccessCoordinatorBridgePresenter)
func roomAccessCoordinatorBridgePresenterDelegate(_ coordinatorBridgePresenter: RoomAccessCoordinatorBridgePresenter, didCompleteRoomWithId roomId: String)
}
/// RoomNotificationSettingsCoordinatorBridgePresenter enables to start RoomNotificationSettingsCoordinator from a view controller.
/// This bridge is used while waiting for global usage of coordinator pattern.
/// It breaks the Coordinator abstraction and it has been introduced for Objective-C compatibility (mainly for integration in legacy view controllers).
/// Each bridge should be removed once the underlying Coordinator has been integrated by another Coordinator.
@objcMembers
final class RoomAccessCoordinatorBridgePresenter: NSObject {
// MARK: - Properties
// MARK: Private
private let room: MXRoom
private var coordinator: RoomAccessCoordinator?
// MARK: Public
weak var delegate: RoomAccessCoordinatorBridgePresenterDelegate?
// MARK: - Setup
init(room: MXRoom) {
self.room = room
super.init()
}
// MARK: - Public
func present(from viewController: UIViewController, animated: Bool) {
let navigationRouter = NavigationRouter()
let coordinator = RoomAccessCoordinator(parameters: RoomAccessCoordinatorParameters(room: room, navigationRouter: navigationRouter))
coordinator.callback = { [weak self] result in
guard let self = self else { return }
switch result {
case .cancel:
self.delegate?.roomAccessCoordinatorBridgePresenterDelegateDidCancel(self)
case .done(let roomId):
self.delegate?.roomAccessCoordinatorBridgePresenterDelegate(self, didCompleteRoomWithId: roomId)
}
}
let presentable = coordinator.toPresentable()
presentable.presentationController?.delegate = self
navigationRouter.setRootModule(presentable)
viewController.present(navigationRouter.toPresentable(), animated: animated, completion: nil)
coordinator.start()
self.coordinator = coordinator
}
func dismiss(animated: Bool, completion: (() -> Void)?) {
guard let coordinator = self.coordinator else {
return
}
coordinator.toPresentable().dismiss(animated: animated) {
self.coordinator = nil
if let completion = completion {
completion()
}
}
}
}
// MARK: - UIAdaptivePresentationControllerDelegate
extension RoomAccessCoordinatorBridgePresenter: UIAdaptivePresentationControllerDelegate {
func roomNotificationSettingsCoordinatorDidComplete(_ presentationController: UIPresentationController) {
self.delegate?.roomAccessCoordinatorBridgePresenterDelegateDidCancel(self)
}
}
@@ -0,0 +1,35 @@
// File created from FlowTemplate
// $ createRootCoordinator.sh RoomAccessCoordinator RoomAccess
/*
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
/// RoomAccessCoordinator input parameters
struct RoomAccessCoordinatorParameters {
/// The Matrix room
let room: MXRoom
/// The navigation router that manage physical navigation
let navigationRouter: NavigationRouterType
init(room: MXRoom,
navigationRouter: NavigationRouterType? = nil) {
self.room = room
self.navigationRouter = navigationRouter ?? NavigationRouter(navigationController: RiotNavigationController())
}
}