Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spaces] M10.4.1 Home space data filtering #4570 #4965

Merged
merged 8 commits into from
Oct 18, 2021
2 changes: 1 addition & 1 deletion Riot/Modules/Spaces/SpaceMenu/SpaceMenuCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
import Foundation

protocol SpaceMenuCell: Themable {
func fill(with viewData: SpaceMenuListItemViewData)
func update(with viewData: SpaceMenuListItemViewData)
}
14 changes: 11 additions & 3 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuListItemViewData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

import Foundation

/// Possible action ID related to a `SpaceMenuListViewCell` view data
enum SpaceMenuListItemActionId {
pixlwave marked this conversation as resolved.
Show resolved Hide resolved
case showAllRoomsInHomeSpace
case exploreSpaceMembers
case exploreSpaceRooms
case leaveSpace
}

/// Style of the `SpaceMenuListViewCell`
enum SpaceMenuListItemStyle {
case normal
Expand All @@ -30,19 +38,19 @@ protocol SpaceMenuListItemViewDataDelegate: AnyObject {

/// `SpaceMenuListViewCell` view data
class SpaceMenuListItemViewData {
let actionId: String
let actionId: SpaceMenuListItemActionId
let style: SpaceMenuListItemStyle
let title: String?
let icon: UIImage?

/// Any value related to the type of data (e.g. `Bool` for `boolean` style, `nil` for `normal` and `destructive` style)
pixlwave marked this conversation as resolved.
Show resolved Hide resolved
var value: Any? {
pixlwave marked this conversation as resolved.
Show resolved Hide resolved
didSet {
delegate?.spaceMenuItemValueDidChange(self)
}
}
weak var delegate: SpaceMenuListItemViewDataDelegate?

init(actionId: String, style: SpaceMenuListItemStyle, title: String?, icon: UIImage?, value: Any?) {
init(actionId: SpaceMenuListItemActionId, style: SpaceMenuListItemStyle, title: String?, icon: UIImage?, value: Any?) {
self.actionId = actionId
self.style = style
self.title = title
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Spaces/SpaceMenu/SpaceMenuListViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SpaceMenuListViewCell: UITableViewCell, SpaceMenuCell, NibReusable {

// MARK: - Public

func fill(with viewData: SpaceMenuListItemViewData) {
func update(with viewData: SpaceMenuListItemViewData) {
self.iconView.image = viewData.icon
self.titleLabel.text = viewData.title

Expand Down
11 changes: 5 additions & 6 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,12 @@ extension SpaceMenuPresenter: SpaceMenuModelViewModelCoordinatorDelegate {
self.dismiss(animated: true, completion: nil)
}

func spaceMenuViewModel(_ viewModel: SpaceMenuViewModelType, didSelectItemWithId itemId: String) {
let actionId = SpaceMenuViewModel.ActionId(rawValue: itemId)
switch actionId {
case .leave: break
case .members:
func spaceMenuViewModel(_ viewModel: SpaceMenuViewModelType, didSelectItemWithId itemId: SpaceMenuListItemActionId) {
switch itemId {
case .leaveSpace: break
case .exploreSpaceMembers:
self.delegate?.spaceMenuPresenter(self, didCompleteWith: .exploreMembers, forSpaceWithId: self.spaceId, with: self.session)
case .rooms:
case .exploreSpaceRooms:
self.delegate?.spaceMenuPresenter(self, didCompleteWith: .exploreRooms, forSpaceWithId: self.spaceId, with: self.session)
default:
MXLog.error("[SpaceMenuPresenter] spaceListViewModel didSelectItemWithId: invalid itemId \(itemId)")
Expand Down
12 changes: 1 addition & 11 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuSwitchViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,10 @@ class SpaceMenuSwitchViewCell: UITableViewCell, SpaceMenuCell, NibReusable {

// MARK: - Public

func fill(with viewData: SpaceMenuListItemViewData) {
func update(with viewData: SpaceMenuListItemViewData) {
self.titleLabel.text = viewData.title
self.switchView.isOn = (viewData.value as? Bool) ?? false

guard let theme = self.theme else {
return
}

if viewData.style == .destructive {
self.titleLabel.textColor = theme.colors.alert
} else {
self.titleLabel.textColor = theme.colors.primaryContent
}

viewData.delegate = self
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ extension SpaceMenuViewController: UITableViewDataSource {

if let cell = cell as? SpaceMenuCell {
cell.update(theme: self.theme)
cell.fill(with: viewData)
cell.update(with: viewData)
}

return cell
Expand Down
30 changes: 10 additions & 20 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,15 @@ import Foundation
/// View model used by `SpaceMenuViewController`
class SpaceMenuViewModel: SpaceMenuViewModelType {

// MARK: - Enum

enum ActionId: String {
case showAllRoomsInHome = "showAllRoomsInHome"
case members = "members"
case rooms = "rooms"
case leave = "leave"
}

// MARK: - Properties

weak var coordinatorDelegate: SpaceMenuModelViewModelCoordinatorDelegate?
weak var viewDelegate: SpaceMenuViewModelViewDelegate?

private let spaceMenuItems: [SpaceMenuListItemViewData] = [
SpaceMenuListItemViewData(actionId: ActionId.members.rawValue, style: .normal, title: VectorL10n.roomDetailsPeople, icon: Asset.Images.spaceMenuMembers.image, value: nil),
SpaceMenuListItemViewData(actionId: ActionId.rooms.rawValue, style: .normal, title: VectorL10n.spacesExploreRooms, icon: Asset.Images.spaceMenuRooms.image, value: nil),
SpaceMenuListItemViewData(actionId: ActionId.leave.rawValue, style: .destructive, title: VectorL10n.leave, icon: Asset.Images.spaceMenuLeave.image, value: nil)
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)
]

var menuItems: [SpaceMenuListItemViewData] = []
Expand All @@ -54,7 +45,7 @@ class SpaceMenuViewModel: SpaceMenuViewModelType {
self.menuItems = spaceMenuItems
} else {
self.menuItems = [
SpaceMenuListItemViewData(actionId: ActionId.showAllRoomsInHome.rawValue, style: .boolean, title: VectorL10n.spaceHomeShowAllRooms, icon: nil, value: MXKAppSettings.standard().isShowAllRoomsInHomeEnabled)
SpaceMenuListItemViewData(actionId: .showAllRoomsInHomeSpace, style: .boolean, title: VectorL10n.spaceHomeShowAllRooms, icon: nil, value: MXKAppSettings.standard().showAllRoomsInHomeSpace)
]
}
}
Expand All @@ -76,17 +67,16 @@ class SpaceMenuViewModel: SpaceMenuViewModelType {

// MARK: - Private

private func processAction(with actionStringId: String, at indexPath: IndexPath) {
let actionId = ActionId(rawValue: actionStringId)
private func processAction(with actionId: SpaceMenuListItemActionId, at indexPath: IndexPath) {
switch actionId {
case .showAllRoomsInHome:
MXKAppSettings.standard().isShowAllRoomsInHomeEnabled = !MXKAppSettings.standard().isShowAllRoomsInHomeEnabled
self.menuItems[indexPath.row].value = MXKAppSettings.standard().isShowAllRoomsInHomeEnabled
case .showAllRoomsInHomeSpace:
MXKAppSettings.standard().showAllRoomsInHomeSpace = !MXKAppSettings.standard().showAllRoomsInHomeSpace
self.menuItems[indexPath.row].value = MXKAppSettings.standard().showAllRoomsInHomeSpace
self.viewDelegate?.spaceMenuViewModel(self, didUpdateViewState: .deselect)
case .leave:
case .leaveSpace:
self.leaveSpace()
default:
self.coordinatorDelegate?.spaceMenuViewModel(self, didSelectItemWithId: actionStringId)
self.coordinatorDelegate?.spaceMenuViewModel(self, didSelectItemWithId: actionId)
}
}

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: String)
func spaceMenuViewModel(_ viewModel: SpaceMenuViewModelType, didSelectItemWithId itemId: SpaceMenuListItemActionId)
}

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