mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
Display thread when row tapped
This commit is contained in:
parent
40236a8e0b
commit
08f43e5bcb
8 changed files with 88 additions and 7 deletions
|
@ -136,9 +136,6 @@ final class RoomCoordinator: NSObject, RoomCoordinatorProtocol {
|
|||
}
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
if parameters.threadId != nil {
|
||||
return self.navigationRouter?.toPresentable() ?? self.roomViewController
|
||||
}
|
||||
return self.roomViewController
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,10 @@ extension ThreadListCoordinator: ThreadListViewModelCoordinatorDelegate {
|
|||
self.delegate?.threadListCoordinatorDidLoadThreads(self)
|
||||
}
|
||||
|
||||
func threadListViewModelDidSelectThread(_ viewModel: ThreadListViewModelProtocol, thread: MXThread) {
|
||||
self.delegate?.threadListCoordinatorDidSelectThread(self, thread: thread)
|
||||
}
|
||||
|
||||
func threadListViewModelDidCancel(_ viewModel: ThreadListViewModelProtocol) {
|
||||
self.delegate?.threadListCoordinatorDidCancel(self)
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import Foundation
|
|||
|
||||
protocol ThreadListCoordinatorDelegate: AnyObject {
|
||||
func threadListCoordinatorDidLoadThreads(_ coordinator: ThreadListCoordinatorProtocol)
|
||||
func threadListCoordinatorDidSelectThread(_ coordinator: ThreadListCoordinatorProtocol, thread: MXThread)
|
||||
func threadListCoordinatorDidCancel(_ coordinator: ThreadListCoordinatorProtocol)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,9 @@ import Foundation
|
|||
/// ThreadListViewController view actions exposed to view model
|
||||
enum ThreadListViewAction {
|
||||
case loadData
|
||||
case complete
|
||||
case showFilterTypes
|
||||
case selectFilterType(_ type: ThreadListFilterType)
|
||||
case complete
|
||||
case selectThread(_ index: Int)
|
||||
case cancel
|
||||
}
|
||||
|
|
|
@ -114,7 +114,9 @@ final class ThreadListViewController: UIViewController {
|
|||
titleView.mode = .allThreads
|
||||
titleView.viewDelegate = self
|
||||
titleView.configure(withViewModel: viewModel.titleViewModel)
|
||||
navigationItem.titleView = titleView
|
||||
navigationItem.leftItemsSupplementBackButton = true
|
||||
navigationItem.backBarButtonItem = UIBarButtonItem(title: nil, style: .plain, target: nil, action: nil)
|
||||
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: titleView)
|
||||
|
||||
self.threadsTableView.tableFooterView = UIView()
|
||||
self.threadsTableView.register(cellType: ThreadTableViewCell.self)
|
||||
|
@ -231,6 +233,8 @@ extension ThreadListViewController: UITableViewDelegate {
|
|||
|
||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
|
||||
viewModel.process(viewAction: .selectThread(indexPath.row))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -63,13 +63,15 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
|
|||
switch viewAction {
|
||||
case .loadData:
|
||||
loadData()
|
||||
case .complete:
|
||||
coordinatorDelegate?.threadListViewModelDidLoadThreads(self)
|
||||
case .showFilterTypes:
|
||||
viewState = .showingFilterTypes
|
||||
case .selectFilterType(let type):
|
||||
selectedFilterType = type
|
||||
loadData()
|
||||
case .complete:
|
||||
coordinatorDelegate?.threadListViewModelDidLoadThreads(self)
|
||||
case .selectThread(let index):
|
||||
selectThread(index)
|
||||
case .cancel:
|
||||
cancelOperations()
|
||||
coordinatorDelegate?.threadListViewModelDidCancel(self)
|
||||
|
@ -226,6 +228,14 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
|
|||
}
|
||||
}
|
||||
|
||||
private func selectThread(_ index: Int) {
|
||||
guard index < threads.count else {
|
||||
return
|
||||
}
|
||||
let thread = threads[index]
|
||||
coordinatorDelegate?.threadListViewModelDidSelectThread(self, thread: thread)
|
||||
}
|
||||
|
||||
private func cancelOperations() {
|
||||
self.currentOperation?.cancel()
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ protocol ThreadListViewModelViewDelegate: AnyObject {
|
|||
|
||||
protocol ThreadListViewModelCoordinatorDelegate: AnyObject {
|
||||
func threadListViewModelDidLoadThreads(_ viewModel: ThreadListViewModelProtocol)
|
||||
func threadListViewModelDidSelectThread(_ viewModel: ThreadListViewModelProtocol, thread: MXThread)
|
||||
func threadListViewModelDidCancel(_ viewModel: ThreadListViewModelProtocol)
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ final class ThreadsCoordinator: NSObject, ThreadsCoordinatorProtocol {
|
|||
// MARK: Private
|
||||
|
||||
private let parameters: ThreadsCoordinatorParameters
|
||||
private var selectedThreadCoordinator: RoomCoordinator?
|
||||
|
||||
private var navigationRouter: NavigationRouterType {
|
||||
return self.parameters.navigationRouter
|
||||
|
@ -42,6 +43,11 @@ final class ThreadsCoordinator: NSObject, ThreadsCoordinatorProtocol {
|
|||
|
||||
init(parameters: ThreadsCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
super.init()
|
||||
NotificationCenter.default.addObserver(self,
|
||||
selector: #selector(didPopModule(_:)),
|
||||
name: NavigationRouter.didPopModule,
|
||||
object: nil)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
@ -73,6 +79,21 @@ final class ThreadsCoordinator: NSObject, ThreadsCoordinatorProtocol {
|
|||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@objc
|
||||
private func didPopModule(_ notification: Notification) {
|
||||
guard let userInfo = notification.userInfo,
|
||||
let module = userInfo[NavigationRouter.NotificationUserInfoKey.module] as? Presentable,
|
||||
let selectedThreadCoordinator = selectedThreadCoordinator else {
|
||||
return
|
||||
}
|
||||
|
||||
if module.toPresentable() == selectedThreadCoordinator.toPresentable() {
|
||||
selectedThreadCoordinator.delegate = nil
|
||||
remove(childCoordinator: selectedThreadCoordinator)
|
||||
self.selectedThreadCoordinator = nil
|
||||
}
|
||||
}
|
||||
|
||||
private func createThreadListCoordinator() -> ThreadListCoordinator {
|
||||
let coordinatorParameters = ThreadListCoordinatorParameters(session: self.parameters.session,
|
||||
|
@ -81,6 +102,19 @@ final class ThreadsCoordinator: NSObject, ThreadsCoordinatorProtocol {
|
|||
coordinator.delegate = self
|
||||
return coordinator
|
||||
}
|
||||
|
||||
private func createThreadCoordinator(forThread thread: MXThread) -> RoomCoordinator {
|
||||
let parameters = RoomCoordinatorParameters(navigationRouter: navigationRouter,
|
||||
navigationRouterStore: nil,
|
||||
session: parameters.session,
|
||||
roomId: parameters.roomId,
|
||||
eventId: nil,
|
||||
threadId: thread.identifier,
|
||||
displayConfiguration: .forThreads)
|
||||
let coordinator = RoomCoordinator(parameters: parameters)
|
||||
coordinator.delegate = self
|
||||
return coordinator
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UIAdaptivePresentationControllerDelegate
|
||||
|
@ -97,7 +131,36 @@ extension ThreadsCoordinator: ThreadListCoordinatorDelegate {
|
|||
self.delegate?.threadsCoordinatorDidComplete(self)
|
||||
}
|
||||
|
||||
func threadListCoordinatorDidSelectThread(_ coordinator: ThreadListCoordinatorProtocol, thread: MXThread) {
|
||||
let roomCoordinator = createThreadCoordinator(forThread: thread)
|
||||
selectedThreadCoordinator = roomCoordinator
|
||||
roomCoordinator.start()
|
||||
self.add(childCoordinator: roomCoordinator)
|
||||
}
|
||||
|
||||
func threadListCoordinatorDidCancel(_ coordinator: ThreadListCoordinatorProtocol) {
|
||||
self.delegate?.threadsCoordinatorDidComplete(self)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - RoomCoordinatorDelegate
|
||||
|
||||
extension ThreadsCoordinator: RoomCoordinatorDelegate {
|
||||
|
||||
func roomCoordinatorDidLeaveRoom(_ coordinator: RoomCoordinatorProtocol) {
|
||||
|
||||
}
|
||||
|
||||
func roomCoordinatorDidCancelRoomPreview(_ coordinator: RoomCoordinatorProtocol) {
|
||||
|
||||
}
|
||||
|
||||
func roomCoordinator(_ coordinator: RoomCoordinatorProtocol, didSelectRoomWithId roomId: String, eventId: String?) {
|
||||
|
||||
}
|
||||
|
||||
func roomCoordinatorDidDismissInteractively(_ coordinator: RoomCoordinatorProtocol) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue