mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
RoomInfoCoordinator: Add possibility to open an initial specific section.
This commit is contained in:
parent
a250f4db44
commit
19b87f493e
5 changed files with 99 additions and 17 deletions
|
@ -28,6 +28,8 @@ final class RoomInfoCoordinator: NSObject, RoomInfoCoordinatorType {
|
|||
private let navigationRouter: NavigationRouterType
|
||||
private let session: MXSession
|
||||
private let room: MXRoom
|
||||
private let initialSection: RoomInfoSection
|
||||
private weak var roomSettingsViewController: RoomSettingsViewController?
|
||||
|
||||
private lazy var segmentedViewController: SegmentedViewController = {
|
||||
let controller = SegmentedViewController()
|
||||
|
@ -68,6 +70,8 @@ final class RoomInfoCoordinator: NSObject, RoomInfoCoordinatorType {
|
|||
], defaultSelected: 0)
|
||||
controller.addMatrixSession(self.session)
|
||||
|
||||
self.roomSettingsViewController = settings
|
||||
|
||||
_ = controller.view
|
||||
|
||||
return controller
|
||||
|
@ -82,10 +86,11 @@ final class RoomInfoCoordinator: NSObject, RoomInfoCoordinatorType {
|
|||
|
||||
// MARK: - Setup
|
||||
|
||||
init(session: MXSession, room: MXRoom) {
|
||||
init(parameters: RoomInfoCoordinatorParameters) {
|
||||
self.navigationRouter = NavigationRouter(navigationController: RiotNavigationController())
|
||||
self.session = session
|
||||
self.room = room
|
||||
self.session = parameters.session
|
||||
self.room = parameters.room
|
||||
self.initialSection = parameters.initialSection
|
||||
}
|
||||
|
||||
// MARK: - Public methods
|
||||
|
@ -96,8 +101,19 @@ final class RoomInfoCoordinator: NSObject, RoomInfoCoordinatorType {
|
|||
rootCoordinator.start()
|
||||
|
||||
self.add(childCoordinator: 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 {
|
||||
|
@ -111,14 +127,23 @@ final class RoomInfoCoordinator: NSObject, RoomInfoCoordinatorType {
|
|||
coordinator.delegate = self
|
||||
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
|
||||
extension RoomInfoCoordinator: RoomInfoListCoordinatorDelegate {
|
||||
|
||||
func roomInfoListCoordinator(_ coordinator: RoomInfoListCoordinatorType, wantsToNavigateTo target: RoomInfoListTarget) {
|
||||
segmentedViewController.selectedIndex = target.rawValue
|
||||
navigationRouter.push(segmentedViewController, animated: true, popCompletion: nil)
|
||||
self.showRoomDetails(with: target, animated: true)
|
||||
}
|
||||
|
||||
func roomInfoListCoordinatorDidCancel(_ coordinator: RoomInfoListCoordinatorType) {
|
||||
|
|
|
@ -31,8 +31,7 @@ final class RoomInfoCoordinatorBridgePresenter: NSObject {
|
|||
|
||||
// MARK: Private
|
||||
|
||||
private let session: MXSession
|
||||
private let room: MXRoom
|
||||
private let coordinatorParameters: RoomInfoCoordinatorParameters
|
||||
private var coordinator: RoomInfoCoordinator?
|
||||
|
||||
// MARK: Public
|
||||
|
@ -41,9 +40,8 @@ final class RoomInfoCoordinatorBridgePresenter: NSObject {
|
|||
|
||||
// MARK: - Setup
|
||||
|
||||
init(session: MXSession, room: MXRoom) {
|
||||
self.session = session
|
||||
self.room = room
|
||||
init(parameters: RoomInfoCoordinatorParameters) {
|
||||
self.coordinatorParameters = parameters
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
@ -55,7 +53,7 @@ final class RoomInfoCoordinatorBridgePresenter: NSObject {
|
|||
// }
|
||||
|
||||
func present(from viewController: UIViewController, animated: Bool) {
|
||||
let roomInfoCoordinator = RoomInfoCoordinator(session: self.session, room: room)
|
||||
let roomInfoCoordinator = RoomInfoCoordinator(parameters: self.coordinatorParameters)
|
||||
roomInfoCoordinator.delegate = self
|
||||
let presentable = roomInfoCoordinator.toPresentable()
|
||||
presentable.presentationController?.delegate = self
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -18,10 +18,25 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
enum RoomInfoListTarget: UInt {
|
||||
case settings = 2
|
||||
case members = 0
|
||||
case uploads = 1
|
||||
enum RoomInfoListTarget {
|
||||
case settings(_ field: RoomSettingsViewControllerField = RoomSettingsViewControllerFieldNone)
|
||||
case members
|
||||
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
|
||||
|
|
|
@ -148,7 +148,7 @@ final class RoomInfoListViewController: UIViewController {
|
|||
var tmpSections: [Section] = []
|
||||
|
||||
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 rowMembers = Row(type: .default, icon: Asset.Images.userIcon.image, text: text, accessoryType: .disclosureIndicator) {
|
||||
|
|
Loading…
Reference in a new issue