diff --git a/Riot/Managers/Settings/RiotSettings.swift b/Riot/Managers/Settings/RiotSettings.swift index 1886975aa..ce3ec7bdd 100644 --- a/Riot/Managers/Settings/RiotSettings.swift +++ b/Riot/Managers/Settings/RiotSettings.swift @@ -73,6 +73,7 @@ final class RiotSettings: NSObject { static let roomScreenAllowFilesAction = "roomScreenAllowFilesAction" static let roomInfoScreenShowIntegrations = "roomInfoScreenShowIntegrations" static let unifiedSearchScreenShowPublicDirectory = "unifiedSearchScreenShowPublicDirectory" + static let hideSpaceBetaAnnounce = "hideSpaceBetaAnnounce" } static let shared = RiotSettings() @@ -634,4 +635,13 @@ final class RiotSettings: NSObject { } } + // MARK: - Beta + + var hideSpaceBetaAnnounce: Bool { + get { + return defaults.bool(forKey: UserDefaultsKeys.hideSpaceBetaAnnounce) + } set { + defaults.set(newValue, forKey: UserDefaultsKeys.hideSpaceBetaAnnounce) + } + } } diff --git a/Riot/Modules/Communities/DataSources/GroupsDataSource.m b/Riot/Modules/Communities/DataSources/GroupsDataSource.m index 28a1cabe8..094eba763 100644 --- a/Riot/Modules/Communities/DataSources/GroupsDataSource.m +++ b/Riot/Modules/Communities/DataSources/GroupsDataSource.m @@ -15,9 +15,77 @@ */ #import "GroupsDataSource.h" +#import "Riot-Swift.h" + +@interface GroupsDataSource() + +@property (nonatomic) NSInteger betaAnnounceSection; +@property (nonatomic) BOOL showBetaAnnounce; + +@end @implementation GroupsDataSource +- (instancetype)initWithMatrixSession:(MXSession *)matrixSession +{ + self = [super initWithMatrixSession:matrixSession]; + if (self) + { + _showBetaAnnounce = !RiotSettings.shared.hideSpaceBetaAnnounce; + } + return self; +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + NSInteger count = 0; + self.betaAnnounceSection = self.groupInvitesSection = self.joinedGroupsSection = -1; + + // Check whether all data sources are ready before rendering groups. + if (self.state == MXKDataSourceStateReady) + { + if (self.showBetaAnnounce) + { + self.betaAnnounceSection = count++; + } + if (groupsInviteCellDataArray.count) + { + self.groupInvitesSection = count++; + } + if (groupsCellDataArray.count) + { + self.joinedGroupsSection = count++; + } + } + + return count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (indexPath.section == self.betaAnnounceSection) + { + BetaAnnounceCell *cell = [tableView dequeueReusableCellWithIdentifier:BetaAnnounceCell.reuseIdentifier forIndexPath:indexPath]; + [cell vc_hideSeparator]; + [cell updateWithTheme:ThemeService.shared.theme]; + cell.delegate = self; + return cell; + + } + + return [super tableView:tableView cellForRowAtIndexPath:indexPath]; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + if (section == self.betaAnnounceSection) + { + return 1; + } + + return [super tableView:tableView numberOfRowsInSection:section]; +} + - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString* sectionTitle = nil; @@ -44,4 +112,13 @@ return (indexPath.section == self.joinedGroupsSection); } +#pragma mark - BetaAnnounceCellDelegate + +- (void)betaAnnounceCellDidTapCloseButton:(BetaAnnounceCell *)cell +{ + self.showBetaAnnounce = NO; + RiotSettings.shared.hideSpaceBetaAnnounce = YES; + [self.delegate dataSource:self didCellChange:nil]; +} + @end diff --git a/Riot/Modules/Communities/GroupsViewController.m b/Riot/Modules/Communities/GroupsViewController.m index dadc807af..afeea1bd4 100644 --- a/Riot/Modules/Communities/GroupsViewController.m +++ b/Riot/Modules/Communities/GroupsViewController.m @@ -79,6 +79,7 @@ //Register here the customized cell view class used to render groups [self.groupsTableView registerNib:GroupTableViewCell.nib forCellReuseIdentifier:GroupTableViewCell.defaultReuseIdentifier]; [self.groupsTableView registerNib:GroupInviteTableViewCell.nib forCellReuseIdentifier:GroupInviteTableViewCell.defaultReuseIdentifier]; + [self.groupsTableView registerNib:BetaAnnounceCell.nib forCellReuseIdentifier:BetaAnnounceCell.reuseIdentifier]; // Hide line separators of empty cells self.groupsTableView.tableFooterView = [[UIView alloc] init];