mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 08:32:53 +02:00
Move segmented view controller to coordinator
This commit is contained in:
@@ -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!) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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!) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user