Move leave alert to view controller

This commit is contained in:
ismailgulek
2020-09-23 12:06:36 +03:00
parent 84b5d79eed
commit 86e56aaacb
6 changed files with 25 additions and 35 deletions
@@ -67,10 +67,6 @@ extension RoomInfoListCoordinator: RoomInfoListViewModelCoordinatorDelegate {
self.delegate?.roomInfoListCoordinator(self, wantsToNavigate: viewController)
}
func roomInfoListViewModel(_ viewModel: RoomInfoListViewModelType, wantsToPresent viewController: UIViewController) {
self.delegate?.roomInfoListCoordinator(self, wantsToPresent: viewController)
}
func roomInfoListViewModelDidCancel(_ viewModel: RoomInfoListViewModelType) {
self.delegate?.roomInfoListCoordinatorDidCancel(self)
}
@@ -20,7 +20,6 @@ import Foundation
protocol RoomInfoListCoordinatorDelegate: class {
func roomInfoListCoordinator(_ coordinator: RoomInfoListCoordinatorType, wantsToNavigate viewController: UIViewController)
func roomInfoListCoordinator(_ coordinator: RoomInfoListCoordinatorType, wantsToPresent viewController: UIViewController)
func roomInfoListCoordinatorDidCancel(_ coordinator: RoomInfoListCoordinatorType)
}
@@ -47,6 +47,19 @@ final class RoomInfoListViewController: UIViewController {
return button
}()
private lazy var leaveAlertController: UIAlertController = {
let controller = UIAlertController(title: VectorL10n.roomParticipantsLeavePromptTitle, message: VectorL10n.roomParticipantsLeavePromptMsg, preferredStyle: .alert)
controller.addAction(UIAlertAction(title: VectorL10n.cancel, style: .cancel, handler: nil))
controller.addAction(UIAlertAction(title: VectorL10n.leave, style: .default, handler: { [weak self] (action) in
guard let self = self else { return }
self.viewModel.process(viewAction: .leave)
}))
controller.mxk_setAccessibilityIdentifier("RoomSettingsVCLeaveAlert")
return controller
}()
private enum RowType {
case `default`
case destructive
@@ -151,7 +164,7 @@ final class RoomInfoListViewController: UIViewController {
footer: nil)
let rowLeave = Row(type: .destructive, icon: Asset.Images.roomActionLeave.image, text: VectorL10n.roomParticipantsLeavePromptTitle, accessoryType: .none) {
self.viewModel.process(viewAction: .leave)
self.present(self.leaveAlertController, animated: true, completion: nil)
}
let sectionLeave = Section(header: nil,
rows: [rowLeave],
@@ -67,29 +67,6 @@ final class RoomInfoListViewModel: NSObject, RoomInfoListViewModelType {
return controller
}()
private lazy var leaveAlertController: UIAlertController = {
let controller = UIAlertController(title: VectorL10n.roomParticipantsLeavePromptTitle, message: VectorL10n.roomParticipantsLeavePromptMsg, preferredStyle: .alert)
controller.addAction(UIAlertAction(title: VectorL10n.cancel, style: .cancel, handler: nil))
controller.addAction(UIAlertAction(title: VectorL10n.leave, style: .default, handler: { [weak self] (action) in
guard let self = self else { return }
self.stopObservingSummaryChanges()
self.update(viewState: .loading)
self.room.leave { (response) in
switch response {
case .success:
self.coordinatorDelegate?.roomInfoListViewModelDidCancel(self)
case .failure(let error):
self.startObservingSummaryChanges()
self.update(viewState: .error(error))
}
}
}))
controller.mxk_setAccessibilityIdentifier("RoomSettingsVCLeaveAlert")
return controller
}()
// MARK: Public
weak var viewDelegate: RoomInfoListViewModelViewDelegate?
@@ -173,7 +150,17 @@ final class RoomInfoListViewModel: NSObject, RoomInfoListViewModelType {
}
private func leave() {
self.coordinatorDelegate?.roomInfoListViewModel(self, wantsToPresent: leaveAlertController)
self.stopObservingSummaryChanges()
self.update(viewState: .loading)
self.room.leave { (response) in
switch response {
case .success:
self.coordinatorDelegate?.roomInfoListViewModelDidCancel(self)
case .failure(let error):
self.startObservingSummaryChanges()
self.update(viewState: .error(error))
}
}
}
private func update(viewState: RoomInfoListViewState) {
@@ -25,7 +25,6 @@ protocol RoomInfoListViewModelViewDelegate: class {
protocol RoomInfoListViewModelCoordinatorDelegate: class {
func roomInfoListViewModelDidCancel(_ viewModel: RoomInfoListViewModelType)
func roomInfoListViewModel(_ viewModel: RoomInfoListViewModelType, wantsToNavigate viewController: UIViewController)
func roomInfoListViewModel(_ viewModel: RoomInfoListViewModelType, wantsToPresent viewController: UIViewController)
}
/// Protocol describing the view model used by `RoomInfoListViewController`