Skip to content

Commit

Permalink
[Spaces] M10.4.1 Home space data filtering #4570
Browse files Browse the repository at this point in the history
- update after review
  • Loading branch information
gileluard committed Oct 18, 2021
1 parent 94f3439 commit 66e2c07
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuListItemViewData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import Foundation

/// Possible action ID related to a `SpaceMenuListViewCell` view data
enum SpaceMenuListItemActionId {
/// Possible action related to a `SpaceMenuListViewCell` view data
enum SpaceMenuListItemAction {
case showAllRoomsInHomeSpace
case exploreSpaceMembers
case exploreSpaceRooms
Expand All @@ -27,7 +27,7 @@ enum SpaceMenuListItemActionId {
/// Style of the `SpaceMenuListViewCell`
enum SpaceMenuListItemStyle {
case normal
case boolean
case toggle
case destructive
}

Expand All @@ -38,7 +38,7 @@ protocol SpaceMenuListItemViewDataDelegate: AnyObject {

/// `SpaceMenuListViewCell` view data
class SpaceMenuListItemViewData {
let actionId: SpaceMenuListItemActionId
let action: SpaceMenuListItemAction
let style: SpaceMenuListItemStyle
let title: String?
let icon: UIImage?
Expand All @@ -50,8 +50,8 @@ class SpaceMenuListItemViewData {
}
weak var delegate: SpaceMenuListItemViewDataDelegate?

init(actionId: SpaceMenuListItemActionId, style: SpaceMenuListItemStyle, title: String?, icon: UIImage?, value: Any?) {
self.actionId = actionId
init(action: SpaceMenuListItemAction, style: SpaceMenuListItemStyle, title: String?, icon: UIImage?, value: Any?) {
self.action = action
self.style = style
self.title = title
self.icon = icon
Expand Down
6 changes: 3 additions & 3 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ extension SpaceMenuPresenter: SpaceMenuModelViewModelCoordinatorDelegate {
self.dismiss(animated: true, completion: nil)
}

func spaceMenuViewModel(_ viewModel: SpaceMenuViewModelType, didSelectItemWithId itemId: SpaceMenuListItemActionId) {
switch itemId {
func spaceMenuViewModel(_ viewModel: SpaceMenuViewModelType, didSelectItemWith action: SpaceMenuListItemAction) {
switch action {
case .leaveSpace: break
case .exploreSpaceMembers:
self.delegate?.spaceMenuPresenter(self, didCompleteWith: .exploreMembers, forSpaceWithId: self.spaceId, with: self.session)
case .exploreSpaceRooms:
self.delegate?.spaceMenuPresenter(self, didCompleteWith: .exploreRooms, forSpaceWithId: self.spaceId, with: self.session)
default:
MXLog.error("[SpaceMenuPresenter] spaceListViewModel didSelectItemWithId: invalid itemId \(itemId)")
MXLog.error("[SpaceMenuPresenter] spaceListViewModel didSelectItem: invalid action \(action)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ extension SpaceMenuViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let viewData = viewModel.menuItems[indexPath.row]

let cell = viewData.style == .boolean ? tableView.dequeueReusableCell(for: indexPath, cellType: SpaceMenuSwitchViewCell.self) :
let cell = viewData.style == .toggle ? tableView.dequeueReusableCell(for: indexPath, cellType: SpaceMenuSwitchViewCell.self) :
tableView.dequeueReusableCell(for: indexPath, cellType: SpaceMenuListViewCell.self)

if let cell = cell as? SpaceMenuCell {
Expand Down
16 changes: 8 additions & 8 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class SpaceMenuViewModel: SpaceMenuViewModelType {
weak var viewDelegate: SpaceMenuViewModelViewDelegate?

private let spaceMenuItems: [SpaceMenuListItemViewData] = [
SpaceMenuListItemViewData(actionId: .exploreSpaceMembers, style: .normal, title: VectorL10n.roomDetailsPeople, icon: Asset.Images.spaceMenuMembers.image, value: nil),
SpaceMenuListItemViewData(actionId: .exploreSpaceRooms, style: .normal, title: VectorL10n.spacesExploreRooms, icon: Asset.Images.spaceMenuRooms.image, value: nil),
SpaceMenuListItemViewData(actionId: .leaveSpace, style: .destructive, title: VectorL10n.leave, icon: Asset.Images.spaceMenuLeave.image, value: nil)
SpaceMenuListItemViewData(action: .exploreSpaceMembers, style: .normal, title: VectorL10n.roomDetailsPeople, icon: Asset.Images.spaceMenuMembers.image, value: nil),
SpaceMenuListItemViewData(action: .exploreSpaceRooms, style: .normal, title: VectorL10n.spacesExploreRooms, icon: Asset.Images.spaceMenuRooms.image, value: nil),
SpaceMenuListItemViewData(action: .leaveSpace, style: .destructive, title: VectorL10n.leave, icon: Asset.Images.spaceMenuLeave.image, value: nil)
]

var menuItems: [SpaceMenuListItemViewData] = []
Expand All @@ -45,7 +45,7 @@ class SpaceMenuViewModel: SpaceMenuViewModelType {
self.menuItems = spaceMenuItems
} else {
self.menuItems = [
SpaceMenuListItemViewData(actionId: .showAllRoomsInHomeSpace, style: .boolean, title: VectorL10n.spaceHomeShowAllRooms, icon: nil, value: MXKAppSettings.standard().showAllRoomsInHomeSpace)
SpaceMenuListItemViewData(action: .showAllRoomsInHomeSpace, style: .toggle, title: VectorL10n.spaceHomeShowAllRooms, icon: nil, value: MXKAppSettings.standard().showAllRoomsInHomeSpace)
]
}
}
Expand All @@ -57,7 +57,7 @@ class SpaceMenuViewModel: SpaceMenuViewModelType {
case .dismiss:
self.coordinatorDelegate?.spaceMenuViewModelDidDismiss(self)
case .selectRow(at: let indexPath):
self.processAction(with: menuItems[indexPath.row].actionId, at: indexPath)
self.processAction(with: menuItems[indexPath.row].action, at: indexPath)
case .leaveSpaceAndKeepRooms:
self.leaveSpaceAndKeepRooms()
case .leaveSpaceAndLeaveRooms:
Expand All @@ -67,16 +67,16 @@ class SpaceMenuViewModel: SpaceMenuViewModelType {

// MARK: - Private

private func processAction(with actionId: SpaceMenuListItemActionId, at indexPath: IndexPath) {
switch actionId {
private func processAction(with action: SpaceMenuListItemAction, at indexPath: IndexPath) {
switch action {
case .showAllRoomsInHomeSpace:
MXKAppSettings.standard().showAllRoomsInHomeSpace = !MXKAppSettings.standard().showAllRoomsInHomeSpace
self.menuItems[indexPath.row].value = MXKAppSettings.standard().showAllRoomsInHomeSpace
self.viewDelegate?.spaceMenuViewModel(self, didUpdateViewState: .deselect)
case .leaveSpace:
self.leaveSpace()
default:
self.coordinatorDelegate?.spaceMenuViewModel(self, didSelectItemWithId: actionId)
self.coordinatorDelegate?.spaceMenuViewModel(self, didSelectItemWith: action)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModelType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protocol SpaceMenuViewModelViewDelegate: AnyObject {

protocol SpaceMenuModelViewModelCoordinatorDelegate: AnyObject {
func spaceMenuViewModelDidDismiss(_ viewModel: SpaceMenuViewModelType)
func spaceMenuViewModel(_ viewModel: SpaceMenuViewModelType, didSelectItemWithId itemId: SpaceMenuListItemActionId)
func spaceMenuViewModel(_ viewModel: SpaceMenuViewModelType, didSelectItemWith action: SpaceMenuListItemAction)
}

/// Protocol describing the view model used by `SpaceMenuViewController`
Expand Down

0 comments on commit 66e2c07

Please sign in to comment.