diff --git a/Riot/Modules/Room/RoomInfo/RoomInfoCoordinator.swift b/Riot/Modules/Room/RoomInfo/RoomInfoCoordinator.swift index f73d1e46f..eab814e60 100644 --- a/Riot/Modules/Room/RoomInfo/RoomInfoCoordinator.swift +++ b/Riot/Modules/Room/RoomInfo/RoomInfoCoordinator.swift @@ -19,7 +19,7 @@ import UIKit @objcMembers -final class RoomInfoCoordinator: RoomInfoCoordinatorType { +final class RoomInfoCoordinator: NSObject, RoomInfoCoordinatorType { // MARK: - Properties @@ -29,6 +29,46 @@ final class RoomInfoCoordinator: RoomInfoCoordinatorType { private let session: MXSession private let room: MXRoom + private lazy var segmentedViewController: SegmentedViewController = { + let controller = SegmentedViewController() + + let participants = RoomParticipantsViewController() + participants.finalizeInit() + participants.enableMention = true + participants.mxRoom = self.room + participants.delegate = self + + let files = RoomFilesViewController() + files.finalizeInit() + MXKRoomDataSource.load(withRoomId: self.room.roomId, andMatrixSession: self.session) { (dataSource) in + guard let dataSource = dataSource as? MXKRoomDataSource else { return } + dataSource.filterMessagesWithURL = true + dataSource.finalizeInitialization() + files.hasRoomDataSourceOwnership = true + files.displayRoom(dataSource) + } + + let settings = RoomSettingsViewController() + settings.finalizeInit() + settings.initWith(self.session, andRoomId: self.room.roomId) + + controller.title = VectorL10n.roomDetailsTitle + controller.initWithTitles([ + VectorL10n.roomDetailsPeople, + VectorL10n.roomDetailsFiles, + VectorL10n.roomDetailsSettings + ], viewControllers: [ + participants, + files, + settings + ], defaultSelected: 0) + controller.addMatrixSession(self.session) + + _ = controller.view + + return controller + }() + // MARK: Public // Must be used only internally @@ -72,8 +112,9 @@ final class RoomInfoCoordinator: RoomInfoCoordinatorType { // MARK: - RoomInfoListCoordinatorDelegate extension RoomInfoCoordinator: RoomInfoListCoordinatorDelegate { - func roomInfoListCoordinator(_ coordinator: RoomInfoListCoordinatorType, wantsToNavigate viewController: UIViewController) { - navigationRouter.push(viewController, animated: true, popCompletion: nil) + func roomInfoListCoordinator(_ coordinator: RoomInfoListCoordinatorType, wantsToNavigateTo target: RoomInfoListTarget) { + segmentedViewController.selectedIndex = target.rawValue + navigationRouter.push(segmentedViewController, animated: true, popCompletion: nil) } func roomInfoListCoordinatorDidCancel(_ coordinator: RoomInfoListCoordinatorType) { @@ -81,3 +122,11 @@ extension RoomInfoCoordinator: RoomInfoListCoordinatorDelegate { } } + +extension RoomInfoCoordinator: RoomParticipantsViewControllerDelegate { + + func roomParticipantsViewController(_ roomParticipantsViewController: RoomParticipantsViewController!, mention member: MXRoomMember!) { + + } + +} diff --git a/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListCoordinator.swift b/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListCoordinator.swift index 1e555f0d0..0dfa1be56 100644 --- a/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListCoordinator.swift +++ b/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListCoordinator.swift @@ -63,8 +63,8 @@ final class RoomInfoListCoordinator: RoomInfoListCoordinatorType { // MARK: - RoomInfoListViewModelCoordinatorDelegate extension RoomInfoListCoordinator: RoomInfoListViewModelCoordinatorDelegate { - func roomInfoListViewModel(_ viewModel: RoomInfoListViewModelType, wantsToNavigate viewController: UIViewController) { - self.delegate?.roomInfoListCoordinator(self, wantsToNavigate: viewController) + func roomInfoListViewModel(_ viewModel: RoomInfoListViewModelType, wantsToNavigateTo target: RoomInfoListTarget) { + self.delegate?.roomInfoListCoordinator(self, wantsToNavigateTo: target) } func roomInfoListViewModelDidCancel(_ viewModel: RoomInfoListViewModelType) { diff --git a/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListCoordinatorType.swift b/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListCoordinatorType.swift index 07e671ee4..db953c40b 100644 --- a/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListCoordinatorType.swift +++ b/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListCoordinatorType.swift @@ -19,7 +19,7 @@ import Foundation protocol RoomInfoListCoordinatorDelegate: class { - func roomInfoListCoordinator(_ coordinator: RoomInfoListCoordinatorType, wantsToNavigate viewController: UIViewController) + func roomInfoListCoordinator(_ coordinator: RoomInfoListCoordinatorType, wantsToNavigateTo target: RoomInfoListTarget) func roomInfoListCoordinatorDidCancel(_ coordinator: RoomInfoListCoordinatorType) } diff --git a/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewAction.swift b/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewAction.swift index a456d7fb2..fd75ff422 100644 --- a/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewAction.swift +++ b/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewAction.swift @@ -18,10 +18,10 @@ import Foundation -enum RoomInfoListTarget { - case settings - case members - case uploads +enum RoomInfoListTarget: UInt { + case settings = 2 + case members = 0 + case uploads = 1 } /// RoomInfoListViewController view actions exposed to view model diff --git a/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewModel.swift b/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewModel.swift index 14af21e28..26235896b 100644 --- a/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewModel.swift +++ b/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewModel.swift @@ -27,46 +27,6 @@ final class RoomInfoListViewModel: NSObject, RoomInfoListViewModelType { private let session: MXSession private let room: MXRoom - private lazy var segmentedViewController: SegmentedViewController = { - let controller = SegmentedViewController() - - let participants = RoomParticipantsViewController() - participants.finalizeInit() - participants.enableMention = true - participants.mxRoom = self.room - participants.delegate = self - - let files = RoomFilesViewController() - files.finalizeInit() - MXKRoomDataSource.load(withRoomId: self.room.roomId, andMatrixSession: self.session) { (dataSource) in - guard let dataSource = dataSource as? MXKRoomDataSource else { return } - dataSource.filterMessagesWithURL = true - dataSource.finalizeInitialization() - files.hasRoomDataSourceOwnership = true - files.displayRoom(dataSource) - } - - let settings = RoomSettingsViewController() - settings.finalizeInit() - settings.initWith(self.session, andRoomId: self.room.roomId) - - controller.title = VectorL10n.roomDetailsTitle - controller.initWithTitles([ - VectorL10n.roomDetailsPeople, - VectorL10n.roomDetailsFiles, - VectorL10n.roomDetailsSettings - ], viewControllers: [ - participants, - files, - settings - ], defaultSelected: 0) - controller.addMatrixSession(self.session) - - _ = controller.view - - return controller - }() - // MARK: Public weak var viewDelegate: RoomInfoListViewModelViewDelegate? @@ -133,20 +93,7 @@ final class RoomInfoListViewModel: NSObject, RoomInfoListViewModelType { } private func navigate(to target: RoomInfoListTarget) { - switch target { - case .settings: - let controller = segmentedViewController - controller.selectedIndex = 2 - self.coordinatorDelegate?.roomInfoListViewModel(self, wantsToNavigate: controller) - case .members: - let controller = segmentedViewController - controller.selectedIndex = 0 - self.coordinatorDelegate?.roomInfoListViewModel(self, wantsToNavigate: controller) - case .uploads: - let controller = segmentedViewController - controller.selectedIndex = 1 - self.coordinatorDelegate?.roomInfoListViewModel(self, wantsToNavigate: controller) - } + self.coordinatorDelegate?.roomInfoListViewModel(self, wantsToNavigateTo: target) } private func leave() { @@ -211,11 +158,3 @@ extension RoomInfoListViewModel: RoomInfoBasicTableViewCellVM { } } - -extension RoomInfoListViewModel: RoomParticipantsViewControllerDelegate { - - func roomParticipantsViewController(_ roomParticipantsViewController: RoomParticipantsViewController!, mention member: MXRoomMember!) { - - } - -} diff --git a/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewModelType.swift b/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewModelType.swift index 13076f2e4..4f5a8ec82 100644 --- a/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewModelType.swift +++ b/Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewModelType.swift @@ -24,7 +24,7 @@ protocol RoomInfoListViewModelViewDelegate: class { protocol RoomInfoListViewModelCoordinatorDelegate: class { func roomInfoListViewModelDidCancel(_ viewModel: RoomInfoListViewModelType) - func roomInfoListViewModel(_ viewModel: RoomInfoListViewModelType, wantsToNavigate viewController: UIViewController) + func roomInfoListViewModel(_ viewModel: RoomInfoListViewModelType, wantsToNavigateTo target: RoomInfoListTarget) } /// Protocol describing the view model used by `RoomInfoListViewController`