RoomInfoCoordinator: Add possibility to open an initial specific section.

This commit is contained in:
SBiOSoftWhare 2021-02-23 15:51:23 +01:00
parent a250f4db44
commit 19b87f493e
5 changed files with 99 additions and 17 deletions

View file

@ -28,6 +28,8 @@ final class RoomInfoCoordinator: NSObject, RoomInfoCoordinatorType {
private let navigationRouter: NavigationRouterType private let navigationRouter: NavigationRouterType
private let session: MXSession private let session: MXSession
private let room: MXRoom private let room: MXRoom
private let initialSection: RoomInfoSection
private weak var roomSettingsViewController: RoomSettingsViewController?
private lazy var segmentedViewController: SegmentedViewController = { private lazy var segmentedViewController: SegmentedViewController = {
let controller = SegmentedViewController() let controller = SegmentedViewController()
@ -68,6 +70,8 @@ final class RoomInfoCoordinator: NSObject, RoomInfoCoordinatorType {
], defaultSelected: 0) ], defaultSelected: 0)
controller.addMatrixSession(self.session) controller.addMatrixSession(self.session)
self.roomSettingsViewController = settings
_ = controller.view _ = controller.view
return controller return controller
@ -82,10 +86,11 @@ final class RoomInfoCoordinator: NSObject, RoomInfoCoordinatorType {
// MARK: - Setup // MARK: - Setup
init(session: MXSession, room: MXRoom) { init(parameters: RoomInfoCoordinatorParameters) {
self.navigationRouter = NavigationRouter(navigationController: RiotNavigationController()) self.navigationRouter = NavigationRouter(navigationController: RiotNavigationController())
self.session = session self.session = parameters.session
self.room = room self.room = parameters.room
self.initialSection = parameters.initialSection
} }
// MARK: - Public methods // MARK: - Public methods
@ -98,6 +103,17 @@ final class RoomInfoCoordinator: NSObject, RoomInfoCoordinatorType {
self.add(childCoordinator: rootCoordinator) self.add(childCoordinator: rootCoordinator)
self.navigationRouter.setRootModule(rootCoordinator) self.navigationRouter.setRootModule(rootCoordinator)
switch initialSection {
case .addParticipants:
self.showRoomDetails(with: .members, animated: false)
case .changeAvatar:
self.showRoomDetails(with: .settings(RoomSettingsViewControllerFieldAvatar), animated: false)
case .changeTopic:
self.showRoomDetails(with: .settings(RoomSettingsViewControllerFieldTopic), animated: false)
case .none:
break
}
} }
func toPresentable() -> UIViewController { func toPresentable() -> UIViewController {
@ -111,14 +127,23 @@ final class RoomInfoCoordinator: NSObject, RoomInfoCoordinatorType {
coordinator.delegate = self coordinator.delegate = self
return coordinator return coordinator
} }
private func showRoomDetails(with target: RoomInfoListTarget, animated: Bool) {
segmentedViewController.selectedIndex = target.tabIndex
if case .settings(let roomSettingsField) = target {
roomSettingsViewController?.selectedRoomSettingsField = roomSettingsField
}
navigationRouter.push(segmentedViewController, animated: animated, popCompletion: nil)
}
} }
// MARK: - RoomInfoListCoordinatorDelegate // MARK: - RoomInfoListCoordinatorDelegate
extension RoomInfoCoordinator: RoomInfoListCoordinatorDelegate { extension RoomInfoCoordinator: RoomInfoListCoordinatorDelegate {
func roomInfoListCoordinator(_ coordinator: RoomInfoListCoordinatorType, wantsToNavigateTo target: RoomInfoListTarget) { func roomInfoListCoordinator(_ coordinator: RoomInfoListCoordinatorType, wantsToNavigateTo target: RoomInfoListTarget) {
segmentedViewController.selectedIndex = target.rawValue self.showRoomDetails(with: target, animated: true)
navigationRouter.push(segmentedViewController, animated: true, popCompletion: nil)
} }
func roomInfoListCoordinatorDidCancel(_ coordinator: RoomInfoListCoordinatorType) { func roomInfoListCoordinatorDidCancel(_ coordinator: RoomInfoListCoordinatorType) {

View file

@ -31,8 +31,7 @@ final class RoomInfoCoordinatorBridgePresenter: NSObject {
// MARK: Private // MARK: Private
private let session: MXSession private let coordinatorParameters: RoomInfoCoordinatorParameters
private let room: MXRoom
private var coordinator: RoomInfoCoordinator? private var coordinator: RoomInfoCoordinator?
// MARK: Public // MARK: Public
@ -41,9 +40,8 @@ final class RoomInfoCoordinatorBridgePresenter: NSObject {
// MARK: - Setup // MARK: - Setup
init(session: MXSession, room: MXRoom) { init(parameters: RoomInfoCoordinatorParameters) {
self.session = session self.coordinatorParameters = parameters
self.room = room
super.init() super.init()
} }
@ -55,7 +53,7 @@ final class RoomInfoCoordinatorBridgePresenter: NSObject {
// } // }
func present(from viewController: UIViewController, animated: Bool) { func present(from viewController: UIViewController, animated: Bool) {
let roomInfoCoordinator = RoomInfoCoordinator(session: self.session, room: room) let roomInfoCoordinator = RoomInfoCoordinator(parameters: self.coordinatorParameters)
roomInfoCoordinator.delegate = self roomInfoCoordinator.delegate = self
let presentable = roomInfoCoordinator.toPresentable() let presentable = roomInfoCoordinator.toPresentable()
presentable.presentationController?.delegate = self presentable.presentationController?.delegate = self

View file

@ -0,0 +1,44 @@
//
// 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
@objc
enum RoomInfoSection: Int {
case none
case addParticipants
case changeAvatar
case changeTopic
}
@objcMembers
class RoomInfoCoordinatorParameters: NSObject {
let session: MXSession
let room: MXRoom
let initialSection: RoomInfoSection
init(session: MXSession, room: MXRoom, initialSection: RoomInfoSection) {
self.session = session
self.room = room
self.initialSection = initialSection
super.init()
}
convenience init(session: MXSession, room: MXRoom) {
self.init(session: session, room: room, initialSection: .none)
}
}

View file

@ -18,10 +18,25 @@
import Foundation import Foundation
enum RoomInfoListTarget: UInt { enum RoomInfoListTarget {
case settings = 2 case settings(_ field: RoomSettingsViewControllerField = RoomSettingsViewControllerFieldNone)
case members = 0 case members
case uploads = 1 case uploads
var tabIndex: UInt {
let tabIndex: UInt
switch self {
case .members:
tabIndex = 0
case .uploads:
tabIndex = 1
case .settings:
tabIndex = 2
}
return tabIndex
}
} }
/// RoomInfoListViewController view actions exposed to view model /// RoomInfoListViewController view actions exposed to view model

View file

@ -148,7 +148,7 @@ final class RoomInfoListViewController: UIViewController {
var tmpSections: [Section] = [] var tmpSections: [Section] = []
let rowSettings = Row(type: .default, icon: Asset.Images.settingsIcon.image, text: VectorL10n.roomDetailsSettings, accessoryType: .disclosureIndicator) { let rowSettings = Row(type: .default, icon: Asset.Images.settingsIcon.image, text: VectorL10n.roomDetailsSettings, accessoryType: .disclosureIndicator) {
self.viewModel.process(viewAction: .navigate(target: .settings)) self.viewModel.process(viewAction: .navigate(target: .settings()))
} }
let text = viewData.numberOfMembers == 1 ? VectorL10n.roomInfoListOneMember : VectorL10n.roomInfoListSeveralMembers(String(viewData.numberOfMembers)) let text = viewData.numberOfMembers == 1 ? VectorL10n.roomInfoListOneMember : VectorL10n.roomInfoListSeveralMembers(String(viewData.numberOfMembers))
let rowMembers = Row(type: .default, icon: Asset.Images.userIcon.image, text: text, accessoryType: .disclosureIndicator) { let rowMembers = Row(type: .default, icon: Asset.Images.userIcon.image, text: text, accessoryType: .disclosureIndicator) {