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

New App Layout: added suppport for room invites in the all chats screen #6604

Merged
merged 1 commit into from
Aug 22, 2022
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
29 changes: 28 additions & 1 deletion Riot/Assets/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,36 @@
</objects>
<point key="canvasLocation" x="-153" y="-419"/>
</scene>
<!--Room Invites View Controller-->
<scene sceneID="ied-3I-huo">
<objects>
<viewController storyboardIdentifier="RoomInvitesViewController" extendedLayoutIncludesOpaqueBars="YES" id="BYq-qZ-orN" customClass="RoomInvitesViewController" customModule="Element" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="NpE-qA-EJG"/>
<viewControllerLayoutGuide type="bottom" id="N2q-zt-KdC"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ln5-wB-A9e">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<tabBarItem key="tabBarItem" title="" image="tab_home" id="vSs-0M-T3r">
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="accessibilityIdentifier" value="TabBarItemHome"/>
</userDefinedRuntimeAttributes>
</tabBarItem>
<navigationItem key="navigationItem" id="FIq-cg-lge"/>
<connections>
<segue destination="WDS-Ip-RQ9" kind="presentation" identifier="presentStartChat" id="rok-Xg-Mhx"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="r4V-Xa-ZoW" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2734" y="-2050"/>
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="y6u-0X-urR"/>
<segue reference="rok-Xg-Mhx"/>
</inferredMetricsTieBreakers>
<resources>
<image name="launch_screen_logo" width="240" height="240"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef NS_ENUM(NSInteger, RecentsDataSourceMode)
RecentsDataSourceModeFavourites,
RecentsDataSourceModePeople,
RecentsDataSourceModeRooms,
RecentsDataSourceModeRoomInvites,
RecentsDataSourceModeAllChats
};

Expand Down
37 changes: 29 additions & 8 deletions Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ - (DiscussionsCount *)groupMissedDiscussionsCount
- (RecentsDataSourceSections *)makeDataSourceSections
{
NSMutableArray *types = [NSMutableArray array];
if (self.recentsDataSourceMode == RecentsDataSourceModeRoomInvites)
{
[types addObject:@(RecentsDataSourceSectionTypeInvites)];
return [[RecentsDataSourceSections alloc] initWithSectionTypes:types.copy];
}

if (self.crossSigningBannerDisplay != CrossSigningBannerDisplayNone)
{
[types addObject:@(RecentsDataSourceSectionTypeCrossSigningBanner)];
Expand All @@ -183,7 +189,7 @@ - (RecentsDataSourceSections *)makeDataSourceSections
[types addObject:@(RecentsDataSourceSectionTypeSecureBackupBanner)];
}

if (!BuildSettings.newAppLayoutEnabled && self.invitesCellDataArray.count > 0)
if (self.invitesCellDataArray.count > 0)
{
[types addObject:@(RecentsDataSourceSectionTypeInvites)];
}
Expand Down Expand Up @@ -229,11 +235,6 @@ - (RecentsDataSourceSections *)makeDataSourceSections
[types addObject:@(RecentsDataSourceSectionTypeAllChats)];
}

if (self.currentSpace == nil && BuildSettings.newAppLayoutEnabled && self.invitesCellDataArray.count > 0)
{
[types addObject:@(RecentsDataSourceSectionTypeInvites)];
}

if (self.currentSpace != nil && self.suggestedRoomCellDataArray.count > 0)
{
[types addObject:@(RecentsDataSourceSectionTypeSuggestedRooms)];
Expand Down Expand Up @@ -625,7 +626,13 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
}
else if (sectionType == RecentsDataSourceSectionTypeInvites && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_INVITES))
{
count = self.invitesCellDataArray.count;
if (self.recentsDataSourceMode == RecentsDataSourceModeAllChats)
{
count = 1;
}
else {
count = self.invitesCellDataArray.count;
}
}
else if (sectionType == RecentsDataSourceSectionTypeSuggestedRooms && !(shrinkedSectionsBitMask & RECENTSDATASOURCE_SECTION_SUGGESTED))
{
Expand Down Expand Up @@ -660,6 +667,7 @@ - (CGFloat)heightForHeaderInSection:(NSInteger)section
if (sectionType == RecentsDataSourceSectionTypeSecureBackupBanner ||
sectionType == RecentsDataSourceSectionTypeCrossSigningBanner ||
sectionType == RecentsDataSourceSectionTypeBreadcrumbs ||
(sectionType == RecentsDataSourceSectionTypeInvites && self.recentsDataSourceMode == RecentsDataSourceModeAllChats) ||
(sectionType == RecentsDataSourceSectionTypeAllChats && !self.allChatsFilterOptions.optionsCount))
{
return 0.0;
Expand Down Expand Up @@ -859,6 +867,7 @@ - (UIView *)viewForHeaderInSection:(NSInteger)section withFrame:(CGRect)frame in
if (sectionType == RecentsDataSourceSectionTypeSecureBackupBanner ||
sectionType == RecentsDataSourceSectionTypeCrossSigningBanner ||
sectionType == RecentsDataSourceSectionTypeBreadcrumbs ||
(sectionType == RecentsDataSourceSectionTypeInvites && self.recentsDataSourceMode == RecentsDataSourceModeRoomInvites) ||
(sectionType == RecentsDataSourceSectionTypeAllChats && !self.allChatsFilterOptions.optionsCount))
{
return nil;
Expand Down Expand Up @@ -1088,6 +1097,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

return tableViewCell;
}
else if (sectionType == RecentsDataSourceSectionTypeInvites && self.recentsDataSourceMode == RecentsDataSourceModeAllChats)
{
RecentsInvitesTableViewCell *tableViewCell = [tableView dequeueReusableCellWithIdentifier:[RecentsInvitesTableViewCell defaultReuseIdentifier]];

tableViewCell.invitesCount = self.recentsListService.invitedRoomListData.counts.numberOfRooms;

return tableViewCell;
}

return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
Expand Down Expand Up @@ -1199,6 +1216,10 @@ - (CGFloat)cellHeightAtIndexPath:(NSIndexPath *)indexPath
if (sectionType == RecentsDataSourceSectionTypeAllChats && !self.allChatsRoomCellDataArray.count) {
return 300.0;
}
if (sectionType == RecentsDataSourceSectionTypeInvites && self.recentsDataSourceMode == RecentsDataSourceModeAllChats)
{
return 32.0;
}

// Override this method here to use our own cellDataAtIndexPath
id<MXKRecentCellDataStoring> cellData = [self cellDataAtIndexPath:indexPath];
Expand Down Expand Up @@ -1509,7 +1530,7 @@ - (void)searchWithPatterns:(NSArray *)patternsList

- (BOOL)isDraggableCellAt:(NSIndexPath*)path
{
if (_recentsDataSourceMode == RecentsDataSourceModePeople || _recentsDataSourceMode == RecentsDataSourceModeRooms)
if (_recentsDataSourceMode == RecentsDataSourceModePeople || _recentsDataSourceMode == RecentsDataSourceModeRooms || _recentsDataSourceMode == RecentsDataSourceModeRoomInvites)
{
return NO;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class RecentsListService: NSObject, RecentsListServiceProtocol {

private var invitedRoomListDataFetcher: MXRoomListDataFetcher? {
switch mode {
case .home, .allChats:
case .home, .allChats, .roomInvites:
return invitedRoomListDataFetcherForHome
case .people:
return invitedRoomListDataFetcherForPeople
Expand Down Expand Up @@ -87,6 +87,7 @@ public class RecentsListService: NSObject, RecentsListServiceProtocol {
.favourites: [.favorited],
.people: [.invited, .directPeople],
.rooms: [.invited, .conversationRooms, .suggested],
.roomInvites: [.invited],
.allChats: [.breadcrumbs, .favorited, .directHome, .invited, .allChats, .lowPriority, .serverNotice, .suggested]
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// Copyright 2022 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 UIKit
import Reusable

/// `RecentsInvitesTableViewCell` can be used as a placeholder to show invites number
class RecentsInvitesTableViewCell: UITableViewCell, NibReusable, Themable {

// MARK: - Outlet

@IBOutlet weak private var badgeLabel: BadgeLabel!
@IBOutlet weak private var titleLabel: UILabel!

// MARK: - Properties

@objc var invitesCount: Int = 0 {
didSet {
badgeLabel.text = "\(invitesCount)"
}
}

// MARK: - NibReusable

@objc static func defaultReuseIdentifier() -> String {
return reuseIdentifier
}

// MARK: - Life cycle

override func awakeFromNib() {
super.awakeFromNib()

setupView()
update(theme: ThemeService.shared().theme)
}

// MARK: - Themable

func update(theme: Theme) {
self.backgroundColor = theme.colors.background

badgeLabel.badgeColor = theme.colors.alert
badgeLabel.textColor = theme.colors.background
badgeLabel.font = theme.fonts.footnoteSB

titleLabel.textColor = theme.colors.accent
}

// MARK: - Private

private func setupView() {
self.selectionStyle = .none

titleLabel.text = VectorL10n.roomRecentsInvitesSection.capitalized
update(theme: ThemeService.shared().theme)
}
}
58 changes: 58 additions & 0 deletions Riot/Modules/Common/Recents/Views/RecentsInvitesTableViewCell.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<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" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" rowHeight="44" id="L2L-l5-wPx" customClass="RecentsInvitesTableViewCell" customModule="Element" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="403" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="L2L-l5-wPx" id="aXz-IR-jj5">
<rect key="frame" x="0.0" y="0.0" width="403" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="14" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="v7o-A4-W0T" customClass="BadgeLabel" customModule="Element" customModuleProvider="target">
<rect key="frame" x="369" y="12" width="18" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="size" keyPath="padding">
<size key="value" width="13" height="2"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Invites" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eXI-UE-lYe">
<rect key="frame" x="311" y="12" width="50" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="v7o-A4-W0T" firstAttribute="centerY" secondItem="aXz-IR-jj5" secondAttribute="centerY" id="8up-Mj-fMw"/>
<constraint firstItem="v7o-A4-W0T" firstAttribute="leading" secondItem="eXI-UE-lYe" secondAttribute="trailing" constant="8" id="UoH-jb-QUq"/>
<constraint firstAttribute="trailing" secondItem="v7o-A4-W0T" secondAttribute="trailing" constant="16" id="cbs-0p-bQh"/>
<constraint firstItem="eXI-UE-lYe" firstAttribute="centerY" secondItem="aXz-IR-jj5" secondAttribute="centerY" id="pdw-2c-vG6"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<accessibility key="accessibilityConfiguration" identifier="RecentTableViewCell"/>
<connections>
<outlet property="badgeLabel" destination="v7o-A4-W0T" id="O6d-wK-nKA"/>
<outlet property="titleLabel" destination="eXI-UE-lYe" id="w0P-0Z-dd8"/>
</connections>
<point key="canvasLocation" x="-324" y="-71.964017991004496"/>
</tableViewCell>
</objects>
<designables>
<designable name="v7o-A4-W0T">
<size key="intrinsicContentSize" width="18" height="20.5"/>
</designable>
</designables>
</document>
58 changes: 57 additions & 1 deletion Riot/Modules/Home/AllChats/AllChatsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class AllChatsViewController: HomeViewController {
recentsTableView.tag = RecentsDataSourceMode.allChats.rawValue
recentsTableView.clipsToBounds = false
recentsTableView.register(RecentEmptySectionTableViewCell.nib, forCellReuseIdentifier: RecentEmptySectionTableViewCell.reuseIdentifier)

recentsTableView.register(RecentsInvitesTableViewCell.nib, forCellReuseIdentifier: RecentsInvitesTableViewCell.reuseIdentifier)

updateUI()
vc_setLargeTitleDisplayMode(.automatic)

Expand Down Expand Up @@ -127,6 +128,51 @@ class AllChatsViewController: HomeViewController {
self.spaceSelectorBridgePresenter = spaceSelectorBridgePresenter
}

// MARK: - UITableViewDataSource

private func sectionType(forSectionAt index: Int) -> RecentsDataSourceSectionType? {
guard let recentsDataSource = dataSource as? RecentsDataSource else {
return nil
}

return recentsDataSource.sections.sectionType(forSectionIndex: index)
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let sectionType = sectionType(forSectionAt: section), sectionType == .invites else {
return super.tableView(tableView, numberOfRowsInSection: section)
}

return dataSource.tableView(tableView, numberOfRowsInSection: section)
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let sectionType = sectionType(forSectionAt: indexPath.section), sectionType == .invites else {
return super.tableView(tableView, cellForRowAt: indexPath)
}

return dataSource.tableView(tableView, cellForRowAt: indexPath)
}

// MARK: - UITableViewDelegate

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
guard let sectionType = sectionType(forSectionAt: indexPath.section), sectionType == .invites else {
return super.tableView(tableView, heightForRowAt: indexPath)
}

return dataSource.cellHeight(at: indexPath)
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let sectionType = sectionType(forSectionAt: indexPath.section), sectionType == .invites else {
super.tableView(tableView, didSelectRowAt: indexPath)
return
}

showRoomInviteList()
}

// MARK: - Toolbar animation

private var lastScrollPosition: Double = 0
Expand Down Expand Up @@ -385,6 +431,16 @@ class AllChatsViewController: HomeViewController {
}
present(coordinator.toPresentable(), animated: true)
}

private func showRoomInviteList() {
let invitesViewController = RoomInvitesViewController.instantiate()
invitesViewController.userIndicatorStore = self.userIndicatorStore
// invitesViewController.displayList(self.dataSource)
let recentsListService = RecentsListService(withSession: mainSession)
let recentsDataSource = RecentsDataSource(matrixSession: mainSession, recentsListService: recentsListService)
invitesViewController.displayList(recentsDataSource)
self.navigationController?.pushViewController(invitesViewController, animated: true)
}
}

// MARK: - SpaceSelectorBottomSheetCoordinatorBridgePresenterDelegate
Expand Down
Loading