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
- Improved visual feedback when switching home settings
  • Loading branch information
gileluard committed Oct 11, 2021
1 parent 151a48e commit 691bf34
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
23 changes: 21 additions & 2 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuListItemViewData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,30 @@ enum SpaceMenuListItemStyle {
case destructive
}

/// `SpaceMenuListItemViewDataDelegate` allows the table view cell to update its view accordingly with it's related data change
protocol SpaceMenuListItemViewDataDelegate: AnyObject {
func spaceMenuItemValueDidChange(_ item: SpaceMenuListItemViewData)
}

/// `SpaceMenuListViewCell` view data
struct SpaceMenuListItemViewData {
class SpaceMenuListItemViewData {
let actionId: String
let style: SpaceMenuListItemStyle
let title: String?
let icon: UIImage?
var value: Any?

var value: Any? {
didSet {
delegate?.spaceMenuItemValueDidChange(self)
}
}
weak var delegate: SpaceMenuListItemViewDataDelegate?

init(actionId: String, style: SpaceMenuListItemStyle, title: String?, icon: UIImage?, value: Any?) {
self.actionId = actionId
self.style = style
self.title = title
self.icon = icon
self.value = value
}
}
9 changes: 9 additions & 0 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuSwitchViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class SpaceMenuSwitchViewCell: UITableViewCell, SpaceMenuCell, NibReusable {
} else {
self.titleLabel.textColor = theme.colors.primaryContent
}

viewData.delegate = self
}

func update(theme: Theme) {
Expand All @@ -72,3 +74,10 @@ class SpaceMenuSwitchViewCell: UITableViewCell, SpaceMenuCell, NibReusable {
self.selectionView.backgroundColor = theme.colors.separator
}
}

// MARK: - SpaceMenuListItemViewDataDelegate
extension SpaceMenuSwitchViewCell: SpaceMenuListItemViewDataDelegate {
func spaceMenuItemValueDidChange(_ item: SpaceMenuListItemViewData) {
self.switchView.setOn((item.value as? Bool) ?? false, animated: true)
}
}
2 changes: 0 additions & 2 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ class SpaceMenuViewController: UIViewController {
self.renderLoaded()
case .leaveOptions(let displayName, let isAdmin):
self.renderLeaveOptions(displayName: displayName, isAdmin: isAdmin)
case .updateItem(let indexPath):
self.tableView.reloadRows(at: [indexPath], with: .fade)
case .error(let error):
self.render(error: error)
case .deselect:
Expand Down
1 change: 0 additions & 1 deletion Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class SpaceMenuViewModel: SpaceMenuViewModelType {
MXKAppSettings.standard().isShowAllRoomsInHomeEnabled = !MXKAppSettings.standard().isShowAllRoomsInHomeEnabled
self.menuItems[indexPath.row].value = MXKAppSettings.standard().isShowAllRoomsInHomeEnabled
self.viewDelegate?.spaceMenuViewModel(self, didUpdateViewState: .deselect)
self.viewDelegate?.spaceMenuViewModel(self, didUpdateViewState: .updateItem(indexPath))
case .leave:
self.leaveSpace()
default:
Expand Down
1 change: 0 additions & 1 deletion Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ enum SpaceMenuViewState {
case loading
case loaded
case deselect
case updateItem(_ indexPath: IndexPath)
case leaveOptions(_ displayName: String, _ isAdmin: Bool)
case error(Error)
}

0 comments on commit 691bf34

Please sign in to comment.