Skip to content

Commit

Permalink
Settings: Enhance flair handling
Browse files Browse the repository at this point in the history
Display more details on the user's group (avatar, id)

element-hq/riot-meta#118
  • Loading branch information
giomfo committed Feb 6, 2018
1 parent a07431d commit af32b7c
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 87 deletions.
10 changes: 10 additions & 0 deletions Riot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
F075BED71EBB169C00A7B68A /* RoomCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F075BED51EBB169C00A7B68A /* RoomCollectionViewCell.xib */; };
F075BEDB1EBB26F100A7B68A /* TableViewCellWithCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = F075BED91EBB26F100A7B68A /* TableViewCellWithCollectionView.m */; };
F075BEDC1EBB26F100A7B68A /* TableViewCellWithCollectionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F075BEDA1EBB26F100A7B68A /* TableViewCellWithCollectionView.xib */; };
F07CB3992029B20100C29C20 /* GroupTableViewCellWithSwitch.xib in Resources */ = {isa = PBXBuildFile; fileRef = F07CB3972029B20000C29C20 /* GroupTableViewCellWithSwitch.xib */; };
F07CB39A2029B20100C29C20 /* GroupTableViewCellWithSwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = F07CB3982029B20100C29C20 /* GroupTableViewCellWithSwitch.m */; };
F083BD1D1E7009ED00A9B29C /* RageShakeManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BB0B1E7009EC00A9B29C /* RageShakeManager.m */; };
F083BD1E1E7009ED00A9B29C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BB0D1E7009EC00A9B29C /* AppDelegate.m */; };
F083BD221E7009ED00A9B29C /* add_participant.png in Resources */ = {isa = PBXBuildFile; fileRef = F083BB161E7009EC00A9B29C /* add_participant.png */; };
Expand Down Expand Up @@ -814,6 +816,9 @@
F075BED81EBB26F100A7B68A /* TableViewCellWithCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewCellWithCollectionView.h; sourceTree = "<group>"; };
F075BED91EBB26F100A7B68A /* TableViewCellWithCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewCellWithCollectionView.m; sourceTree = "<group>"; };
F075BEDA1EBB26F100A7B68A /* TableViewCellWithCollectionView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TableViewCellWithCollectionView.xib; sourceTree = "<group>"; };
F07CB3962029B20000C29C20 /* GroupTableViewCellWithSwitch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupTableViewCellWithSwitch.h; sourceTree = "<group>"; };
F07CB3972029B20000C29C20 /* GroupTableViewCellWithSwitch.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GroupTableViewCellWithSwitch.xib; sourceTree = "<group>"; };
F07CB3982029B20100C29C20 /* GroupTableViewCellWithSwitch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GroupTableViewCellWithSwitch.m; sourceTree = "<group>"; };
F083BB031E7005FD00A9B29C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F083BB041E7005FD00A9B29C /* RiotTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RiotTests.m; sourceTree = "<group>"; };
F083BB0A1E7009EC00A9B29C /* RageShakeManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RageShakeManager.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2611,6 +2616,9 @@
F0B8D0CB1FDFEC6100F34524 /* Group */ = {
isa = PBXGroup;
children = (
F07CB3962029B20000C29C20 /* GroupTableViewCellWithSwitch.h */,
F07CB3982029B20100C29C20 /* GroupTableViewCellWithSwitch.m */,
F07CB3972029B20000C29C20 /* GroupTableViewCellWithSwitch.xib */,
F0B8D0D01FDFECB200F34524 /* GroupInviteTableViewCell.h */,
F0B8D0CC1FDFECB100F34524 /* GroupInviteTableViewCell.m */,
F0B8D0D11FDFECB200F34524 /* GroupInviteTableViewCell.xib */,
Expand Down Expand Up @@ -3190,6 +3198,7 @@
32935CB41F628BCE006888C8 /* IntegrationManager.js in Resources */,
F083BD851E7009ED00A9B29C /* [email protected] in Resources */,
F083BD541E7009ED00A9B29C /* [email protected] in Resources */,
F07CB3992029B20100C29C20 /* GroupTableViewCellWithSwitch.xib in Resources */,
F083BD6A1E7009ED00A9B29C /* [email protected] in Resources */,
F083BE3B1E7009ED00A9B29C /* RoomIncomingEncryptedAttachmentBubbleCell.xib in Resources */,
F083BD341E7009ED00A9B29C /* [email protected] in Resources */,
Expand Down Expand Up @@ -3566,6 +3575,7 @@
3205ED7D1E976C8A003D65FA /* DirectoryServerPickerViewController.m in Sources */,
F083BE7C1E7009ED00A9B29C /* DirectoryRecentTableViewCell.m in Sources */,
F0E05A031E963103004B83FB /* RoomsViewController.m in Sources */,
F07CB39A2029B20100C29C20 /* GroupTableViewCellWithSwitch.m in Sources */,
83711A7C1F6F8E7D008F0D4D /* KeyboardGrowingTextView.m in Sources */,
F083BE801E7009ED00A9B29C /* PublicRoomTableViewCell.m in Sources */,
322806A01F0F64C4008C53D7 /* RoomMembershipExpandedBubbleCell.m in Sources */,
Expand Down
22 changes: 17 additions & 5 deletions Riot/ViewController/RoomSettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,11 @@ - (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSectio
}
else if (section == ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX)
{
if (relatedGroupsNewGroupIndex == -1)
{
// Hide this section
return nil;
}
return NSLocalizedStringFromTable(@"room_details_flair_section", @"Vector", nil);
}
else if (section == ROOM_SETTINGS_BANNED_USERS_SECTION_INDEX)
Expand All @@ -2036,11 +2041,8 @@ - (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSectio
{
return NSLocalizedStringFromTable(@"room_details_banned_users_section", @"Vector", nil);
}
else
{
// Hide this section
return nil;
}
// Hide this section
return nil;
}
else if (section == ROOM_SETTINGS_ADVANCED_SECTION_INDEX)
{
Expand Down Expand Up @@ -2068,6 +2070,11 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege
// Hide this section
return SECTION_TITLE_PADDING_WHEN_HIDDEN;
}
else if (section == ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX && relatedGroupsNewGroupIndex == -1)
{
// Hide this section
return SECTION_TITLE_PADDING_WHEN_HIDDEN;
}
else
{
return [super tableView:tableView heightForHeaderInSection:section];
Expand All @@ -2081,6 +2088,11 @@ - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSIntege
// Hide this section
return SECTION_TITLE_PADDING_WHEN_HIDDEN;
}
else if (section == ROOM_SETTINGS_RELATED_GROUPS_SECTION_INDEX && relatedGroupsNewGroupIndex == -1)
{
// Hide this section
return SECTION_TITLE_PADDING_WHEN_HIDDEN;
}
else
{
return [super tableView:tableView heightForFooterInSection:section];
Expand Down
2 changes: 1 addition & 1 deletion Riot/ViewController/SettingsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#import "MediaPickerViewController.h"

@interface SettingsViewController : MXKTableViewController<UITextFieldDelegate, MediaPickerViewControllerDelegate, MXKDeviceViewDelegate, UIDocumentInteractionControllerDelegate, MXKCountryPickerViewControllerDelegate, MXKLanguagePickerViewControllerDelegate>
@interface SettingsViewController : MXKTableViewController<UITextFieldDelegate, MediaPickerViewControllerDelegate, MXKDeviceViewDelegate, UIDocumentInteractionControllerDelegate, MXKCountryPickerViewControllerDelegate, MXKLanguagePickerViewControllerDelegate, MXKDataSourceDelegate>

@end

156 changes: 83 additions & 73 deletions Riot/ViewController/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#import "RiotDesignValues.h"
#import "TableViewCellWithPhoneNumberTextField.h"

#import "GroupsDataSource.h"
#import "GroupTableViewCellWithSwitch.h"

#import "GBDeviceInfo_iOS.h"

NSString* const kSettingsViewControllerPhoneBookCountryCellId = @"kSettingsViewControllerPhoneBookCountryCellId";
Expand Down Expand Up @@ -188,8 +191,8 @@ @interface SettingsViewController ()
NSMutableArray<MXDevice *> *devicesArray;
DeviceView *deviceView;

// Flair
NSMutableArray<MXGroup *> *communitiesArray;
// Flair: the groups data source
GroupsDataSource *groupsDataSource;

// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
id kAppDelegateDidTapStatusBarNotificationObserver;
Expand Down Expand Up @@ -246,8 +249,6 @@ - (void)finalizeInit
isSavingInProgress = NO;
isResetPwdInProgress = NO;
is3PIDBindingInProgress = NO;

communitiesArray = [NSMutableArray array];
}

- (void)viewDidLoad
Expand All @@ -261,6 +262,7 @@ - (void)viewDidLoad
[self.tableView registerClass:MXKTableViewCellWithLabelAndSwitch.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier]];
[self.tableView registerClass:MXKTableViewCellWithLabelAndMXKImageView.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndMXKImageView defaultReuseIdentifier]];
[self.tableView registerClass:TableViewCellWithPhoneNumberTextField.class forCellReuseIdentifier:[TableViewCellWithPhoneNumberTextField defaultReuseIdentifier]];
[self.tableView registerClass:GroupTableViewCellWithSwitch.class forCellReuseIdentifier:[GroupTableViewCellWithSwitch defaultReuseIdentifier]];

// Enable self sizing cells
self.tableView.rowHeight = UITableViewAutomaticDimension;
Expand Down Expand Up @@ -302,6 +304,10 @@ - (void)viewDidLoad
[self addMatrixSession:mxSession];
}

groupsDataSource = [[GroupsDataSource alloc] initWithMatrixSession:self.mainSession];
[groupsDataSource finalizeInitialization];
groupsDataSource.delegate = self;

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(onSave:)];
self.navigationItem.rightBarButtonItem.accessibilityIdentifier=@"SettingsVCNavBarSaveButton";

Expand Down Expand Up @@ -343,6 +349,13 @@ - (void)didReceiveMemoryWarning

- (void)destroy
{
if (groupsDataSource)
{
groupsDataSource.delegate = nil;
[groupsDataSource destroy];
groupsDataSource = nil;
}

// Release the potential pushed view controller
[self releasePushedViewController];

Expand Down Expand Up @@ -419,12 +432,6 @@ - (void)viewWillAppear:(BOOL)animated
// Refresh devices in parallel
[self loadDevices];

// Listen to MXSession groups changes, and load the current list.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didUpdateGroup:) name:kMXSessionDidJoinGroupNotification object:self.mainSession];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didUpdateGroup:) name:kMXSessionDidLeaveGroupNotification object:self.mainSession];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didUpdateGroup:) name:kMXSessionDidUpdateGroupSummaryNotification object:self.mainSession];
[self refreshCommunitiesList:YES];

// Observe kAppDelegateDidTapStatusBarNotificationObserver.
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {

Expand Down Expand Up @@ -964,55 +971,6 @@ - (NSAttributedString*)cryptographyInformation
return cryptoInformationString;
}

- (void)refreshCommunitiesList:(BOOL)forceUpdate
{
// Reset the table
[communitiesArray removeAllObjects];

NSArray *groups = self.mainSession.groups;
for (MXGroup *group in groups)
{
// Keep only the joined group
if (group.membership == MXMembershipJoin)
{
[communitiesArray addObject:group];

if (forceUpdate)
{
// Force the matrix session to refresh the group summary.
[self.mainSession updateGroupSummary:group success:nil failure:nil];
}
}
}

NSLog(@"[SettingsViewController] Loaded %tu groups", communitiesArray.count);

// Order alphabetically the groups
[communitiesArray sortUsingComparator:^NSComparisonResult(MXGroup *group1, MXGroup *group2)
{
if (group1.profile.name.length && group2.profile.name.length)
{
return [group1.profile.name compare:group2.profile.name options:NSCaseInsensitiveSearch];
}
else if (group1.profile.name.length)
{
return NSOrderedAscending;
}
else if (group2.profile.name.length)
{
return NSOrderedDescending;
}
return [group1.groupId compare:group2.groupId options:NSCaseInsensitiveSearch];;
}];

[self refreshSettings];
}

- (void)didUpdateGroup:(NSNotification *)notif
{
[self refreshCommunitiesList:NO];
}

- (void)loadDevices
{
// Refresh the account devices list
Expand Down Expand Up @@ -1288,7 +1246,14 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
}
else if (section == SETTINGS_SECTION_FLAIR_INDEX)
{
count = communitiesArray.count;
// Check whether some joined groups are available
if ([groupsDataSource numberOfSectionsInTableView:tableView])
{
if (groupsDataSource.joinedGroupsSection != -1)
{
count = [groupsDataSource tableView:tableView numberOfRowsInSection:groupsDataSource.joinedGroupsSection];
}
}
}
else if (section == SETTINGS_SECTION_DEVICES_INDEX)
{
Expand Down Expand Up @@ -2103,20 +2068,29 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}
else if (section == SETTINGS_SECTION_FLAIR_INDEX)
{
MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:groupsDataSource.joinedGroupsSection];
cell = [groupsDataSource tableView:tableView cellForRowAtIndexPath:indexPath];

if (row < communitiesArray.count)
if ([cell isKindOfClass:GroupTableViewCellWithSwitch.class])
{
MXGroup *group = communitiesArray[row];
labelAndSwitchCell.mxkLabel.text = (group.profile.name.length ? group.profile.name : group.groupId);
labelAndSwitchCell.mxkSwitch.on = group.summary.user.isPublicised;
labelAndSwitchCell.mxkSwitch.enabled = YES;
labelAndSwitchCell.mxkSwitch.tag = row;
GroupTableViewCellWithSwitch* groupWithSwitchCell = (GroupTableViewCellWithSwitch*)cell;
id<MXKGroupCellDataStoring> groupCellData = [groupsDataSource cellDataAtIndex:indexPath];

// Display the groupId in the description label, except if the group has no name
if (![groupWithSwitchCell.groupName.text isEqualToString:groupCellData.group.groupId])
{
groupWithSwitchCell.groupDescription.hidden = NO;
groupWithSwitchCell.groupDescription.text = groupCellData.group.groupId;
}

[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleCommunityFlair:) forControlEvents:UIControlEventTouchUpInside];
// Update the toogle button
groupWithSwitchCell.toggleButton.on = groupCellData.group.summary.user.isPublicised;
groupWithSwitchCell.toggleButton.enabled = YES;
groupWithSwitchCell.toggleButton.tag = row;

[groupWithSwitchCell.toggleButton removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
[groupWithSwitchCell.toggleButton addTarget:self action:@selector(toggleCommunityFlair:) forControlEvents:UIControlEventTouchUpInside];
}

cell = labelAndSwitchCell;
}
else if (section == SETTINGS_SECTION_DEVICES_INDEX)
{
Expand Down Expand Up @@ -2243,7 +2217,7 @@ - (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSectio
else if (section == SETTINGS_SECTION_FLAIR_INDEX)
{
// Check whether this section is visible
if (communitiesArray.count > 0)
if (groupsDataSource.joinedGroupsSection != -1)
{
return NSLocalizedStringFromTable(@"settings_flair", @"Vector", nil);
}
Expand Down Expand Up @@ -2347,6 +2321,13 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege
return SECTION_TITLE_PADDING_WHEN_HIDDEN;
}
}
else if (section == SETTINGS_SECTION_FLAIR_INDEX)
{
if (groupsDataSource.joinedGroupsSection == -1)
{
return SECTION_TITLE_PADDING_WHEN_HIDDEN;
}
}

return 24;
}
Expand All @@ -2372,6 +2353,13 @@ - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSIntege
return SECTION_TITLE_PADDING_WHEN_HIDDEN;
}
}
else if (section == SETTINGS_SECTION_FLAIR_INDEX)
{
if (groupsDataSource.joinedGroupsSection == -1)
{
return SECTION_TITLE_PADDING_WHEN_HIDDEN;
}
}

return 24;
}
Expand Down Expand Up @@ -3052,9 +3040,12 @@ - (void)toggleCommunityFlair:(id)sender
{
UISwitch *switchButton = (UISwitch*)sender;

if (switchButton.tag < communitiesArray.count)
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:switchButton.tag inSection:groupsDataSource.joinedGroupsSection];
id<MXKGroupCellDataStoring> groupCellData = [groupsDataSource cellDataAtIndex:indexPath];
MXGroup *group = groupCellData.group;

if (group)
{
MXGroup *group = communitiesArray[switchButton.tag];
[self startActivityIndicator];

__weak typeof(self) weakSelf = self;
Expand Down Expand Up @@ -4083,4 +4074,23 @@ - (void)languagePickerViewController:(MXKLanguagePickerViewController *)language
}
}

#pragma mark - MXKDataSourceDelegate

- (Class<MXKCellRendering>)cellViewClassForCellData:(MXKCellData*)cellData
{
// Return the class used to display a group with a toogle button
return GroupTableViewCellWithSwitch.class;
}

- (NSString *)cellReuseIdentifierForCellData:(MXKCellData*)cellData
{
return GroupTableViewCellWithSwitch.defaultReuseIdentifier;
}

- (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes
{
// Group data has been updated. Do a simple full reload
[self refreshSettings];
}

@end
3 changes: 3 additions & 0 deletions Riot/Views/Group/GroupTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

@property (weak, nonatomic) IBOutlet MXKImageView *groupAvatar;

/**
The optional unread badge
*/
@property (weak, nonatomic) IBOutlet UILabel *missedNotifAndUnreadBadgeLabel;
@property (weak, nonatomic) IBOutlet UIView *missedNotifAndUnreadBadgeBgView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *missedNotifAndUnreadBadgeBgViewWidthConstraint;
Expand Down
Loading

0 comments on commit af32b7c

Please sign in to comment.