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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"images" : [
{
"filename" : "space_private_icon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "space_private_icon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "space_private_icon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,7 @@ Tap the + to start adding people.";
"spaces_coming_soon_detail" = "This feature hasn’t been implemented here, but it’s on the way. For now, you can do that with Element on your computer.";
"space_participants_action_remove" = "Remove from this space";
"space_participants_action_ban" = "Ban from this space";
"space_home_show_all_rooms" = "Show all rooms";

"space_private_join_rule" = "Private space";
"space_public_join_rule" = "Public space";
Expand Down
1 change: 1 addition & 0 deletions Riot/Generated/Images.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ internal enum Asset {
internal static let spaceMenuLeave = ImageAsset(name: "space_menu_leave")
internal static let spaceMenuMembers = ImageAsset(name: "space_menu_members")
internal static let spaceMenuRooms = ImageAsset(name: "space_menu_rooms")
internal static let spacePrivateIcon = ImageAsset(name: "space_private_icon")
internal static let spaceRoomIcon = ImageAsset(name: "space_room_icon")
internal static let spaceTypeIcon = ImageAsset(name: "space_type_icon")
internal static let spaceUserIcon = ImageAsset(name: "space_user_icon")
Expand Down
4 changes: 4 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4903,6 +4903,10 @@ public class VectorL10n: NSObject {
public static var spaceFeatureUnavailableTitle: String {
return VectorL10n.tr("Vector", "space_feature_unavailable_title")
}
/// Show all rooms
public static var spaceHomeShowAllRooms: String {
return VectorL10n.tr("Vector", "space_home_show_all_rooms")
}
/// Ban from this space
public static var spaceParticipantsActionBan: String {
return VectorL10n.tr("Vector", "space_participants_action_ban")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ + (RecentsDataSourceState *)computeStateWithCells:(NSArray<id<MXKRecentCellDataS
}

MXLogDebug(@"[RecentsDataSource] refreshRoomsSections: Done in %.0fms", [[NSDate date] timeIntervalSinceDate:startDate] * 1000);
MXLogDebug(@"[Spaces] refreshRoomsSections with %ld suggested room", suggestedRoomCellDataArray.count);
MXLogDebug(@"[RecentsDataSource] refreshRoomsSections with %ld suggested room", suggestedRoomCellDataArray.count);

return [[RecentsDataSourceState alloc]
initWithInvitesCellDataArray:invitesCellDataArray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ class SpaceDetailViewController: UIViewController {
let membersString = membersCount == 1 ? VectorL10n.roomTitleOneMember : VectorL10n.roomTitleMembers("\(membersCount)")
self.spaceTypeLabel.text = "\(joinRuleString) · \(membersString)"

let joinRuleIcon = parameters.joinRule == .public ? Asset.Images.spaceTypeIcon : Asset.Images.spacePrivateIcon
self.spaceTypeIconView.image = joinRuleIcon.image

self.inviterIdLabel.text = parameters.inviterId
if let inviterId = parameters.inviterId {
self.inviterTitleLabel.text = "\(parameters.inviter?.displayname ?? inviterId) invited you"
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Spaces/SpaceList/SpaceListViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class SpaceListViewCell: UITableViewCell, Themable, NibReusable {
func fill(with viewData: SpaceListItemViewData) {
self.avatarView.fill(with: viewData.avatarViewData)
self.titleLabel.text = viewData.title
self.moreButton.isHidden = viewData.spaceId == SpaceListViewModel.Constants.homeSpaceId || viewData.isInvite
self.moreButton.isHidden = viewData.isInvite
if viewData.isInvite {
self.isBadgeAlert = true
self.badgeLabel.isHidden = false
Expand Down
3 changes: 2 additions & 1 deletion Riot/Modules/Spaces/SpaceList/SpaceListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ final class SpaceListViewModel: SpaceListViewModelType {
case .moreAction(at: let indexPath, from: let sourceView):
let section = self.sections[indexPath.section]
switch section {
case .home: break
case .home:
self.coordinatorDelegate?.spaceListViewModel(self, didPressMoreForSpaceWithId: Constants.homeSpaceId, from: sourceView)
case .spaces(let viewDataList):
let spaceViewData = viewDataList[indexPath.row]
self.coordinatorDelegate?.spaceListViewModel(self, didPressMoreForSpaceWithId: spaceViewData.spaceId, from: sourceView)
Expand Down
21 changes: 21 additions & 0 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

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

import Foundation

/// Possible action related to a `SpaceMenuListViewCell` view data
enum SpaceMenuListItemAction {
case showAllRoomsInHomeSpace
case exploreSpaceMembers
case exploreSpaceRooms
case leaveSpace
}

/// Style of the `SpaceMenuListViewCell`
enum SpaceMenuListItemStyle {
case normal
case toggle
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 {
let actionId: String
class SpaceMenuListItemViewData {
let action: SpaceMenuListItemAction
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(action: SpaceMenuListItemAction, style: SpaceMenuListItemStyle, title: String?, icon: UIImage?, value: Any?) {
self.action = action
self.style = style
self.title = title
self.icon = icon
self.value = value
}
}
4 changes: 2 additions & 2 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuListViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation
import Reusable

class SpaceMenuListViewCell: UITableViewCell, Themable, NibReusable {
class SpaceMenuListViewCell: UITableViewCell, SpaceMenuCell, NibReusable {

// MARK: - Properties

Expand Down Expand Up @@ -49,7 +49,7 @@ class SpaceMenuListViewCell: UITableViewCell, Themable, 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
13 changes: 6 additions & 7 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,15 @@ 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, didSelectItemWith action: SpaceMenuListItemAction) {
switch action {
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)")
MXLog.error("[SpaceMenuPresenter] spaceListViewModel didSelectItem: invalid action \(action)")
}
}
}
Expand Down
73 changes: 73 additions & 0 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuSwitchViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation
import Reusable

class SpaceMenuSwitchViewCell: UITableViewCell, SpaceMenuCell, NibReusable {

// MARK: - Properties

@IBOutlet private weak var titleLabel: UILabel!
@IBOutlet private weak var selectionView: UIView!
@IBOutlet private weak var switchView: UISwitch!

// MARK: - Private

private var theme: Theme?

// MARK: - Life cycle

override func awakeFromNib() {
super.awakeFromNib()

self.selectionStyle = .none
self.selectionView.layer.cornerRadius = 8.0
self.selectionView.layer.masksToBounds = true
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

UIView.animate(withDuration: animated ? 0.3 : 0.0) {
self.selectionView.alpha = selected ? 1.0 : 0.0
}
}

// MARK: - Public

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

viewData.delegate = self
}

func update(theme: Theme) {
self.theme = theme
self.backgroundColor = theme.colors.background
self.titleLabel.textColor = theme.colors.primaryContent
pixlwave marked this conversation as resolved.
Show resolved Hide resolved
self.titleLabel.font = theme.fonts.body
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)
}
}
64 changes: 64 additions & 0 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuSwitchViewCell.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="64" id="tOd-GW-k0x" customClass="SpaceMenuSwitchViewCell" customModule="Riot" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="64"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="tOd-GW-k0x" id="kRV-oW-j2b">
<rect key="frame" x="0.0" y="0.0" width="320" height="64"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YQF-X2-MAf">
<rect key="frame" x="8" y="8" width="304" height="48"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="48" id="f1L-gQ-B6g"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="SSn-E2-PZK">
<rect key="frame" x="16" y="21.5" width="231" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zhh-dM-9TG">
<rect key="frame" x="255" y="16.5" width="51" height="31"/>
</switch>
</subviews>
<constraints>
<constraint firstItem="YQF-X2-MAf" firstAttribute="top" secondItem="kRV-oW-j2b" secondAttribute="top" constant="8" id="0nO-xV-wrC"/>
<constraint firstItem="zhh-dM-9TG" firstAttribute="leading" secondItem="SSn-E2-PZK" secondAttribute="trailing" constant="8" id="3fk-BS-QhF"/>
<constraint firstAttribute="trailing" secondItem="YQF-X2-MAf" secondAttribute="trailing" constant="8" id="4pu-1l-NUB"/>
<constraint firstItem="YQF-X2-MAf" firstAttribute="leading" secondItem="kRV-oW-j2b" secondAttribute="leading" constant="8" id="Dlx-2U-0pd"/>
<constraint firstItem="zhh-dM-9TG" firstAttribute="centerY" secondItem="kRV-oW-j2b" secondAttribute="centerY" id="JlX-MX-R9W"/>
<constraint firstAttribute="bottom" secondItem="YQF-X2-MAf" secondAttribute="bottom" constant="8" id="fTw-ef-WYp"/>
<constraint firstItem="SSn-E2-PZK" firstAttribute="leading" secondItem="kRV-oW-j2b" secondAttribute="leading" constant="16" id="fep-GJ-roy"/>
<constraint firstItem="SSn-E2-PZK" firstAttribute="centerY" secondItem="kRV-oW-j2b" secondAttribute="centerY" id="jwX-PQ-zct"/>
<constraint firstAttribute="trailing" secondItem="zhh-dM-9TG" secondAttribute="trailing" constant="16" id="rKz-yr-ejP"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="0Tk-ek-Uxc"/>
<connections>
<outlet property="selectionView" destination="YQF-X2-MAf" id="Y3z-Ug-Lrc"/>
<outlet property="switchView" destination="zhh-dM-9TG" id="ogf-cv-75K"/>
<outlet property="titleLabel" destination="SSn-E2-PZK" id="bS7-F2-Tfb"/>
</connections>
<point key="canvasLocation" x="137.68115942028987" y="104.46428571428571"/>
</tableViewCell>
</objects>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
24 changes: 19 additions & 5 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ class SpaceMenuViewController: UIViewController {
}

private func setupViews() {
setupTableView()

if self.spaceId == SpaceListViewModel.Constants.homeSpaceId {
let avatarViewData = AvatarViewData(matrixItemId: self.spaceId, displayName: nil, avatarUrl: nil, mediaManager: session.mediaManager, fallbackImage: .image(Asset.Images.spaceHomeIcon.image, .center))
self.avatarView.fill(with: avatarViewData)
self.titleLabel.text = VectorL10n.titleHome
self.subtitleLabel.text = VectorL10n.settingsTitle

return
}

guard let space = self.session.spaceService.getSpace(withId: self.spaceId), let summary = space.summary else {
MXLog.error("[SpaceMenuViewController] setupViews: no space found")
return
Expand All @@ -130,7 +141,6 @@ class SpaceMenuViewController: UIViewController {

self.closeButton.layer.masksToBounds = true
self.closeButton.layer.cornerRadius = self.closeButton.bounds.height / 2
setupTableView()
}

private func setupTableView() {
Expand All @@ -139,6 +149,7 @@ class SpaceMenuViewController: UIViewController {
self.tableView.estimatedRowHeight = Constants.estimatedRowHeight
self.tableView.allowsSelection = true
self.tableView.register(cellType: SpaceMenuListViewCell.self)
self.tableView.register(cellType: SpaceMenuSwitchViewCell.self)
self.tableView.tableFooterView = UIView()
}

Expand Down Expand Up @@ -235,12 +246,15 @@ extension SpaceMenuViewController: UITableViewDataSource {
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(for: indexPath, cellType: SpaceMenuListViewCell.self)

let viewData = viewModel.menuItems[indexPath.row]

cell.update(theme: self.theme)
cell.fill(with: viewData)
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 {
cell.update(theme: self.theme)
cell.update(with: viewData)
}

return cell
}
Expand Down
Loading