From 2ff73cded1e13ee6dd3cdf7b71a667561c31298c Mon Sep 17 00:00:00 2001 From: yannick Date: Wed, 9 Dec 2015 16:09:46 +0100 Subject: [PATCH 1/9] add_invite_rooms_section -> reduce the recent cell height --- Vector/Assets/en.lproj/Vector.strings | 1 + Vector/Model/RoomList/RecentsDataSource.m | 39 +++++++++++++++++-- Vector/Utils/EventFormatter.m | 4 ++ Vector/Utils/VectorDesignValues.h | 2 + Vector/Views/RoomList/RecentTableViewCell.m | 10 +++-- Vector/Views/RoomList/RecentTableViewCell.xib | 36 ++++++++--------- 6 files changed, 68 insertions(+), 24 deletions(-) diff --git a/Vector/Assets/en.lproj/Vector.strings b/Vector/Assets/en.lproj/Vector.strings index 38e386798..75948f55f 100644 --- a/Vector/Assets/en.lproj/Vector.strings +++ b/Vector/Assets/en.lproj/Vector.strings @@ -62,6 +62,7 @@ "room_recents_favourites" = "FAVORITES"; "room_recents_conversations" = "CONVERSATIONS"; "room_recents_low_priority" = "LOW PRIORITY"; +"room_recents_invites" = "INVITES"; // Chat participants "room_participants_title" = "Participants"; diff --git a/Vector/Model/RoomList/RecentsDataSource.m b/Vector/Model/RoomList/RecentsDataSource.m index 0f255d76f..6812c4b37 100644 --- a/Vector/Model/RoomList/RecentsDataSource.m +++ b/Vector/Model/RoomList/RecentsDataSource.m @@ -22,10 +22,12 @@ @interface RecentsDataSource() { + NSMutableArray* invitesCellDataArray; NSMutableArray* favoriteCellDataArray; NSMutableArray* conversationCellDataArray; NSMutableArray* lowPriorityCellDataArray; + NSInteger invitesSection; NSInteger favoritesSection; NSInteger conversationSection; NSInteger lowPrioritySection; @@ -49,6 +51,7 @@ conversationCellDataArray = [[NSMutableArray alloc] init]; lowPriorityCellDataArray = [[NSMutableArray alloc] init]; + invitesSection = -1; favoritesSection = -1; conversationSection = -1; lowPrioritySection = -1; @@ -111,7 +114,7 @@ */ - (CGFloat)heightForHeaderInSection:(NSInteger)section { - if ((section == favoritesSection) || (section == conversationSection) || (section == lowPrioritySection)) + if ((section == invitesSection) || (section == favoritesSection) || (section == conversationSection) || (section == lowPrioritySection)) { return 30.0f; } @@ -146,6 +149,11 @@ { count = lowPriorityCellDataArray.count; } + else if (section == invitesSection) + { + count = invitesCellDataArray.count; + } + return count; } @@ -154,7 +162,7 @@ { // add multi accounts section management - if ((section == favoritesSection) || (section == conversationSection) || (section == lowPrioritySection)) + if ((section == favoritesSection) || (section == conversationSection) || (section == lowPrioritySection) || (section == invitesSection)) { UILabel* label = [[UILabel alloc] initWithFrame:frame]; @@ -172,6 +180,10 @@ { text = NSLocalizedStringFromTable(@"room_recents_low_priority", @"Vector", nil); } + else if (section == invitesSection) + { + text = NSLocalizedStringFromTable(@"room_recents_invites", @"Vector", nil); + } label.text = [NSString stringWithFormat:@" %@", text]; label.font = [UIFont boldSystemFontOfSize:15.0]; @@ -199,6 +211,10 @@ { cellData = [lowPriorityCellDataArray objectAtIndex:indexPath.row]; } + else if (indexPath.section == invitesSection) + { + cellData = [invitesCellDataArray objectAtIndex:indexPath.row]; + } return cellData; } @@ -211,6 +227,7 @@ if (cellData && self.delegate) { Class class = [self.delegate cellViewClassForCellData:cellData]; + return [class heightForCellData:cellData withMaximumWidth:0]; } @@ -240,7 +257,7 @@ conversationCellDataArray = [[NSMutableArray alloc] init]; lowPriorityCellDataArray = [[NSMutableArray alloc] init]; - favoritesSection = conversationSection = lowPrioritySection = -1; + favoritesSection = conversationSection = lowPrioritySection = invitesSection = -1; sectionsCount = 0; if (displayedRecentsDataSourceArray.count > 0) @@ -248,9 +265,11 @@ MXKSessionRecentsDataSource *recentsDataSource = [displayedRecentsDataSourceArray objectAtIndex:0]; MXSession* session = recentsDataSource.mxSession; + NSArray* sortedInvitesRooms = [session invitedRooms]; NSArray* sortedFavRooms = [session roomsWithTag:kMXRoomTagFavourite]; NSArray* sortedLowPriorRooms = [session roomsWithTag:kMXRoomTagLowPriority]; + invitesCellDataArray = [self createEmptyArray:sortedInvitesRooms.count]; favoriteCellDataArray = [self createEmptyArray:sortedFavRooms.count]; lowPriorityCellDataArray = [self createEmptyArray:sortedLowPriorRooms.count]; @@ -276,6 +295,13 @@ [lowPriorityCellDataArray replaceObjectAtIndex:pos withObject:recentCellDataStoring]; } } + else if ((pos = [sortedInvitesRooms indexOfObject:room]) != NSNotFound) + { + if (pos < invitesCellDataArray.count) + { + [invitesCellDataArray replaceObjectAtIndex:pos withObject:recentCellDataStoring]; + } + } else { [conversationCellDataArray addObject:recentCellDataStoring]; @@ -284,6 +310,13 @@ int sectionIndex = 0; + [invitesCellDataArray removeObject:[NSNull null]]; + if (invitesCellDataArray.count > 0) + { + invitesSection = sectionIndex; + sectionIndex++; + } + [favoriteCellDataArray removeObject:[NSNull null]]; if (favoriteCellDataArray.count > 0) { diff --git a/Vector/Utils/EventFormatter.m b/Vector/Utils/EventFormatter.m index 0a8e3e87a..4007e2687 100644 --- a/Vector/Utils/EventFormatter.m +++ b/Vector/Utils/EventFormatter.m @@ -45,7 +45,11 @@ localTimeZone = [NSTimeZone localTimeZone]; + self.defaultTextColor = VECTOR_TEXT_GRAY_COLOR; self.bingTextColor = VECTOR_GREEN_COLOR; + self.sendingTextColor = VECTOR_LIGHT_GRAY_COLOR; + self.errorTextColor = [UIColor redColor]; + } return self; } diff --git a/Vector/Utils/VectorDesignValues.h b/Vector/Utils/VectorDesignValues.h index 05633fa34..06f66fce7 100644 --- a/Vector/Utils/VectorDesignValues.h +++ b/Vector/Utils/VectorDesignValues.h @@ -17,6 +17,8 @@ // the green text color #define VECTOR_GREEN_COLOR [UIColor colorWithRed:(98.0/256.0) green:(206.0/256.0) blue:(156.0/256.0) alpha:1.0] +#define VECTOR_TEXT_GRAY_COLOR [UIColor colorWithRed:(164.0 / 256.0) green:(164.0 / 256.0) blue:(164.0 / 256.0) alpha:1.0] + #define VECTOR_LIGHT_GRAY_COLOR [UIColor colorWithRed:(242.0 / 256.0) green:(242.0 / 256.0) blue:(242.0 / 256.0) alpha:1.0] // to update the navigation bar buttons color diff --git a/Vector/Views/RoomList/RecentTableViewCell.m b/Vector/Views/RoomList/RecentTableViewCell.m index c0395d837..a4fc7c0aa 100644 --- a/Vector/Views/RoomList/RecentTableViewCell.m +++ b/Vector/Views/RoomList/RecentTableViewCell.m @@ -20,6 +20,8 @@ #import "MXEvent.h" +#import "VectorDesignValues.h" + @implementation RecentTableViewCell #pragma mark - Class methods @@ -52,6 +54,8 @@ self.lastEventDescription.text = roomCellData.lastEventTextMessage; } + self.lastEventDate.textColor = VECTOR_TEXT_GRAY_COLOR; + // Notify unreads and bing self.bingIndicator.hidden = YES; @@ -62,11 +66,11 @@ self.bingIndicator.hidden = NO; self.bingIndicator.backgroundColor = roomCellData.recentsDataSource.eventFormatter.bingTextColor; } - self.roomTitle.font = [UIFont boldSystemFontOfSize:19]; + self.roomTitle.font = [UIFont boldSystemFontOfSize:17]; } else { - self.roomTitle.font = [UIFont systemFontOfSize:19]; + self.roomTitle.font = [UIFont systemFontOfSize:17]; } self.roomAvatar.backgroundColor = [UIColor clearColor]; @@ -118,7 +122,7 @@ + (CGFloat)heightForCellData:(MXKCellData *)cellData withMaximumWidth:(CGFloat)maxWidth { // The height is fixed - return 74; + return 54; } @end diff --git a/Vector/Views/RoomList/RecentTableViewCell.xib b/Vector/Views/RoomList/RecentTableViewCell.xib index 34dd46ca2..c1602ca72 100644 --- a/Vector/Views/RoomList/RecentTableViewCell.xib +++ b/Vector/Views/RoomList/RecentTableViewCell.xib @@ -1,17 +1,17 @@ - + - + - + - + - + - - + + @@ -63,13 +63,13 @@ - + - + - - + + From c96d6fb9cd9592dde402fe4f3b441d19f378c10d Mon Sep 17 00:00:00 2001 From: yannick Date: Wed, 9 Dec 2015 17:01:29 +0100 Subject: [PATCH 2/9] add_invite_rooms_section -> add the customized invite cell. not yet plugged. --- Vector.xcodeproj/project.pbxproj | 10 ++ Vector/Model/RoomList/RecentsDataSource.m | 29 +++++ Vector/ViewController/RecentsViewController.m | 29 ++++- .../RoomList/InviteRecentTableViewCell.h | 26 +++++ .../RoomList/InviteRecentTableViewCell.m | 45 ++++++++ .../RoomList/InviteRecentTableViewCell.xib | 100 ++++++++++++++++++ 6 files changed, 234 insertions(+), 5 deletions(-) create mode 100644 Vector/Views/RoomList/InviteRecentTableViewCell.h create mode 100644 Vector/Views/RoomList/InviteRecentTableViewCell.m create mode 100644 Vector/Views/RoomList/InviteRecentTableViewCell.xib diff --git a/Vector.xcodeproj/project.pbxproj b/Vector.xcodeproj/project.pbxproj index 6a038ecf0..3e1a3cde2 100644 --- a/Vector.xcodeproj/project.pbxproj +++ b/Vector.xcodeproj/project.pbxproj @@ -13,6 +13,8 @@ 71352D651C10A265001D50B0 /* Contact.m in Sources */ = {isa = PBXBuildFile; fileRef = 71352D641C10A265001D50B0 /* Contact.m */; }; 7165A25B1C05CD42003635D7 /* SegmentedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7165A2591C05CD42003635D7 /* SegmentedViewController.m */; }; 7165A25C1C05CD42003635D7 /* SegmentedViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7165A25A1C05CD42003635D7 /* SegmentedViewController.xib */; }; + 716FDC8A1C186A3A001034CB /* InviteRecentTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 716FDC881C186A3A001034CB /* InviteRecentTableViewCell.m */; }; + 716FDC8B1C186A3A001034CB /* InviteRecentTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 716FDC891C186A3A001034CB /* InviteRecentTableViewCell.xib */; }; 717928451C03852C00407D96 /* TableViewCellSeparator.m in Sources */ = {isa = PBXBuildFile; fileRef = 7179283D1C03852C00407D96 /* TableViewCellSeparator.m */; }; 717928461C03852C00407D96 /* TableViewCellSeparator.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7179283E1C03852C00407D96 /* TableViewCellSeparator.xib */; }; 717928471C03852C00407D96 /* TableViewCellWithLabelAndLargeTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 717928401C03852C00407D96 /* TableViewCellWithLabelAndLargeTextView.m */; }; @@ -156,6 +158,9 @@ 7165A2581C05CD42003635D7 /* SegmentedViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SegmentedViewController.h; sourceTree = ""; }; 7165A2591C05CD42003635D7 /* SegmentedViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SegmentedViewController.m; sourceTree = ""; }; 7165A25A1C05CD42003635D7 /* SegmentedViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SegmentedViewController.xib; sourceTree = ""; }; + 716FDC871C186A3A001034CB /* InviteRecentTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InviteRecentTableViewCell.h; sourceTree = ""; }; + 716FDC881C186A3A001034CB /* InviteRecentTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InviteRecentTableViewCell.m; sourceTree = ""; }; + 716FDC891C186A3A001034CB /* InviteRecentTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = InviteRecentTableViewCell.xib; sourceTree = ""; }; 7179283C1C03852C00407D96 /* TableViewCellSeparator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TableViewCellSeparator.h; path = TableViewCell/TableViewCellSeparator.h; sourceTree = ""; }; 7179283D1C03852C00407D96 /* TableViewCellSeparator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TableViewCellSeparator.m; path = TableViewCell/TableViewCellSeparator.m; sourceTree = ""; }; 7179283E1C03852C00407D96 /* TableViewCellSeparator.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = TableViewCellSeparator.xib; path = TableViewCell/TableViewCellSeparator.xib; sourceTree = ""; }; @@ -452,6 +457,9 @@ F00C47821BFF77C800DBABC9 /* RoomList */ = { isa = PBXGroup; children = ( + 716FDC871C186A3A001034CB /* InviteRecentTableViewCell.h */, + 716FDC881C186A3A001034CB /* InviteRecentTableViewCell.m */, + 716FDC891C186A3A001034CB /* InviteRecentTableViewCell.xib */, F00C47831BFF77C800DBABC9 /* RecentTableViewCell.h */, F00C47841BFF77C800DBABC9 /* RecentTableViewCell.m */, F00C47851BFF77C800DBABC9 /* RecentTableViewCell.xib */, @@ -863,6 +871,7 @@ F094A9B61B78D8F000B1FBBF /* Images.xcassets in Resources */, F094AA061B78E3D400B1FBBF /* Vector-Defaults.plist in Resources */, F00C47871BFF77C800DBABC9 /* RecentTableViewCell.xib in Resources */, + 716FDC8B1C186A3A001034CB /* InviteRecentTableViewCell.xib in Resources */, F02528E51C11B6FC00E1FE1B /* favorite_icon@3x.png in Resources */, F02529051C11B6FC00E1FE1B /* typing@3x.png in Resources */, F02528E71C11B6FC00E1FE1B /* logo.png in Resources */, @@ -967,6 +976,7 @@ F001D7621B8207C000A162C3 /* RoomInputToolbarView.m in Sources */, 71EBE66D1C04C4D300E7D953 /* RoomActivitiesView.m in Sources */, F08BE0A21B87064000C480FB /* RoomDataSource.m in Sources */, + 716FDC8A1C186A3A001034CB /* InviteRecentTableViewCell.m in Sources */, F0C34CB31C16269D00C36F09 /* RoomIncomingTextMsgWithPaginationTitleBubbleCell.m in Sources */, 71046D5E1C0C639300DCA984 /* RoomTitleViewWithTopic.m in Sources */, F0C34B631C15C28300C36F09 /* RoomOutgoingAttachmentWithoutSenderInfoBubbleCell.m in Sources */, diff --git a/Vector/Model/RoomList/RecentsDataSource.m b/Vector/Model/RoomList/RecentsDataSource.m index 6812c4b37..c80b90345 100644 --- a/Vector/Model/RoomList/RecentsDataSource.m +++ b/Vector/Model/RoomList/RecentsDataSource.m @@ -20,6 +20,8 @@ #import "VectorDesignValues.h" +#import "InviteRecentTableViewCell.h" + @interface RecentsDataSource() { NSMutableArray* invitesCellDataArray; @@ -195,6 +197,33 @@ return [super viewForHeaderInSection:section withFrame:frame]; } +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + id roomData = [self cellDataAtIndexPath:indexPath]; + if (roomData && self.delegate) + { + NSString *cellIdentifier = [self.delegate cellReuseIdentifierForCellData:roomData]; + + if (cellIdentifier) + { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; + + // Make the bubble display the data + [cell render:roomData]; + + // Clear the user flag, if only one recents list is available + if (displayedRecentsDataSourceArray.count == 1 && [cell isKindOfClass:[MXKInterleavedRecentTableViewCell class]]) + { + ((MXKInterleavedRecentTableViewCell*)cell).userFlag.backgroundColor = [UIColor clearColor]; + } + + return cell; + } + } + return nil; +} + + - (id)cellDataAtIndexPath:(NSIndexPath *)indexPath { id cellData = nil; diff --git a/Vector/ViewController/RecentsViewController.m b/Vector/ViewController/RecentsViewController.m index 95557f5c2..e3934dfe3 100644 --- a/Vector/ViewController/RecentsViewController.m +++ b/Vector/ViewController/RecentsViewController.m @@ -27,6 +27,8 @@ #import "VectorDesignValues.h" +#import "InviteRecentTableViewCell.h" + @interface RecentsViewController () { // Recents refresh handling @@ -81,6 +83,7 @@ // Register here the customized cell view class used to render recents [self.recentsTableView registerNib:RecentTableViewCell.nib forCellReuseIdentifier:RecentTableViewCell.defaultReuseIdentifier]; + [self.recentsTableView registerNib:InviteRecentTableViewCell.nib forCellReuseIdentifier:InviteRecentTableViewCell.defaultReuseIdentifier]; } - (void)dealloc @@ -423,15 +426,31 @@ #pragma mark - MXKDataSourceDelegate - (Class)cellViewClassForCellData:(MXKCellData*)cellData -{ - // Return the customized recent table view cell - return RecentTableViewCell.class; +{ + id cellDataStoring = (id )cellData; + + if (NSNotFound == [cellDataStoring.recentsDataSource.mxSession.invitedRooms indexOfObject:cellDataStoring.roomDataSource.room]) + { + return RecentTableViewCell.class; + } + else + { + return InviteRecentTableViewCell.class; + } } - (NSString *)cellReuseIdentifierForCellData:(MXKCellData*)cellData { - // Return the customized recent table view cell identifier - return RecentTableViewCell.defaultReuseIdentifier; + id cellDataStoring = (id )cellData; + + if (NSNotFound == [cellDataStoring.recentsDataSource.mxSession.invitedRooms indexOfObject:cellDataStoring.roomDataSource.room]) + { + return RecentTableViewCell.defaultReuseIdentifier; + } + else + { + return InviteRecentTableViewCell.defaultReuseIdentifier; + } } - (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes diff --git a/Vector/Views/RoomList/InviteRecentTableViewCell.h b/Vector/Views/RoomList/InviteRecentTableViewCell.h new file mode 100644 index 000000000..c5342d9cd --- /dev/null +++ b/Vector/Views/RoomList/InviteRecentTableViewCell.h @@ -0,0 +1,26 @@ +/* + Copyright 2015 OpenMarket 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 + +#import "RecentTableViewCell.h" + +/** + `InviteRecentTableViewCell` instances display an invite to a room in the context of the recents list. + */ +@interface InviteRecentTableViewCell : RecentTableViewCell + +@end diff --git a/Vector/Views/RoomList/InviteRecentTableViewCell.m b/Vector/Views/RoomList/InviteRecentTableViewCell.m new file mode 100644 index 000000000..daba06d57 --- /dev/null +++ b/Vector/Views/RoomList/InviteRecentTableViewCell.m @@ -0,0 +1,45 @@ +/* + Copyright 2015 OpenMarket 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 "InviteRecentTableViewCell.h" + +#import "AvatarGenerator.h" + +#import "MXEvent.h" + +#import "VectorDesignValues.h" + +@implementation InviteRecentTableViewCell + +#pragma mark - Class methods + +- (void)awakeFromNib +{ + [super awakeFromNib]; +} + +- (void)render:(MXKCellData *)cellData +{ + [super render:cellData]; +} + ++ (CGFloat)heightForCellData:(MXKCellData *)cellData withMaximumWidth:(CGFloat)maxWidth +{ + // The height is fixed + return 79; +} + +@end diff --git a/Vector/Views/RoomList/InviteRecentTableViewCell.xib b/Vector/Views/RoomList/InviteRecentTableViewCell.xib new file mode 100644 index 000000000..c4bd2c257 --- /dev/null +++ b/Vector/Views/RoomList/InviteRecentTableViewCell.xib @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 6169b39ae59d25e302b37aab58e368196883651c Mon Sep 17 00:00:00 2001 From: yannick Date: Wed, 9 Dec 2015 17:38:39 +0100 Subject: [PATCH 3/9] Improve the invite room display. --- Vector/Assets/en.lproj/Vector.strings | 2 + .../RoomList/InviteRecentTableViewCell.h | 3 ++ .../RoomList/InviteRecentTableViewCell.m | 17 ++++++- .../RoomList/InviteRecentTableViewCell.xib | 48 +++++++++++++++---- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/Vector/Assets/en.lproj/Vector.strings b/Vector/Assets/en.lproj/Vector.strings index 75948f55f..a846b59b3 100644 --- a/Vector/Assets/en.lproj/Vector.strings +++ b/Vector/Assets/en.lproj/Vector.strings @@ -32,6 +32,8 @@ "off" = "Off"; "cancel" = "Cancel"; "save" = "Save"; +"join" = "Join"; +"reject" = "Reject"; // Authentication "auth_sign_in" = "Sign in"; diff --git a/Vector/Views/RoomList/InviteRecentTableViewCell.h b/Vector/Views/RoomList/InviteRecentTableViewCell.h index c5342d9cd..6773860f7 100644 --- a/Vector/Views/RoomList/InviteRecentTableViewCell.h +++ b/Vector/Views/RoomList/InviteRecentTableViewCell.h @@ -23,4 +23,7 @@ */ @interface InviteRecentTableViewCell : RecentTableViewCell +@property (weak, nonatomic) IBOutlet UIButton *leftButton; +@property (weak, nonatomic) IBOutlet UIButton *rightButton; + @end diff --git a/Vector/Views/RoomList/InviteRecentTableViewCell.m b/Vector/Views/RoomList/InviteRecentTableViewCell.m index daba06d57..5a57b1103 100644 --- a/Vector/Views/RoomList/InviteRecentTableViewCell.m +++ b/Vector/Views/RoomList/InviteRecentTableViewCell.m @@ -29,6 +29,21 @@ - (void)awakeFromNib { [super awakeFromNib]; + + [self.leftButton.layer setCornerRadius:5]; + self.leftButton.clipsToBounds = YES; + self.leftButton.backgroundColor = VECTOR_GREEN_COLOR; + [self.leftButton setTitle:NSLocalizedStringFromTable(@"join", @"Vector", nil) forState:UIControlStateNormal]; + [self.leftButton setTitle:NSLocalizedStringFromTable(@"join", @"Vector", nil) forState:UIControlStateHighlighted]; + + [self.rightButton.layer setCornerRadius:5]; + self.rightButton.clipsToBounds = YES; + self.rightButton.backgroundColor = VECTOR_GREEN_COLOR; + [self.rightButton setTitle:NSLocalizedStringFromTable(@"reject", @"Vector", nil) forState:UIControlStateNormal]; + [self.rightButton setTitle:NSLocalizedStringFromTable(@"reject", @"Vector", nil) forState:UIControlStateHighlighted]; + + // the date is not displayed in the invitation cells. + self.lastEventDate.hidden = YES; } - (void)render:(MXKCellData *)cellData @@ -39,7 +54,7 @@ + (CGFloat)heightForCellData:(MXKCellData *)cellData withMaximumWidth:(CGFloat)maxWidth { // The height is fixed - return 79; + return 84; } @end diff --git a/Vector/Views/RoomList/InviteRecentTableViewCell.xib b/Vector/Views/RoomList/InviteRecentTableViewCell.xib index c4bd2c257..8c066630b 100644 --- a/Vector/Views/RoomList/InviteRecentTableViewCell.xib +++ b/Vector/Views/RoomList/InviteRecentTableViewCell.xib @@ -3,15 +3,16 @@ + - + - + @@ -72,7 +98,7 @@ - + @@ -92,6 +118,8 @@ + + From 09567f1c29d79f36a7ea710e1c6290b7fd2d54ef Mon Sep 17 00:00:00 2001 From: yannick Date: Thu, 10 Dec 2015 09:00:57 +0100 Subject: [PATCH 4/9] add_invite_rooms_section Plug the join/reject button The join does not refresh properly the recents. --- Vector/Model/RoomList/RecentsDataSource.h | 10 +++++ Vector/Model/RoomList/RecentsDataSource.m | 22 ++++++++- Vector/ViewController/RecentsViewController.m | 45 +++++++++++++++++++ .../RoomList/InviteRecentTableViewCell.h | 10 +++++ .../RoomList/InviteRecentTableViewCell.m | 26 +++++++++-- 5 files changed, 109 insertions(+), 4 deletions(-) diff --git a/Vector/Model/RoomList/RecentsDataSource.h b/Vector/Model/RoomList/RecentsDataSource.h index a46c7e753..b03bb3ccd 100644 --- a/Vector/Model/RoomList/RecentsDataSource.h +++ b/Vector/Model/RoomList/RecentsDataSource.h @@ -21,6 +21,16 @@ */ @interface RecentsDataSource : MXKInterleavedRecentsDataSource +/** + The callback when a room invitation is rejected. + */ +@property (nonatomic, copy) void (^onRoomInvitationReject)(MXRoom*); + +/** + The callback when a room invitation is accepted. + */ +@property (nonatomic, copy) void (^onRoomInvitationAccept)(MXRoom*); + /** Return the header height from the section. */ diff --git a/Vector/Model/RoomList/RecentsDataSource.m b/Vector/Model/RoomList/RecentsDataSource.m index c80b90345..3c65f375d 100644 --- a/Vector/Model/RoomList/RecentsDataSource.m +++ b/Vector/Model/RoomList/RecentsDataSource.m @@ -40,6 +40,7 @@ @end @implementation RecentsDataSource +@synthesize onRoomInvitationReject, onRoomInvitationAccept; - (instancetype)init { @@ -217,13 +218,32 @@ ((MXKInterleavedRecentTableViewCell*)cell).userFlag.backgroundColor = [UIColor clearColor]; } + // on invite cell, add listeners on accept / reject buttons + if ([cell isKindOfClass:[InviteRecentTableViewCell class]]) + { + InviteRecentTableViewCell* inviteRecentTableViewCell = (InviteRecentTableViewCell*)cell; + + inviteRecentTableViewCell.onRejectClick = ^(){ + if (self.onRoomInvitationReject) + { + self.onRoomInvitationReject(roomData.roomDataSource.room); + } + }; + + inviteRecentTableViewCell.onJoinClick = ^(){ + if (self.onRoomInvitationAccept) + { + self.onRoomInvitationAccept(roomData.roomDataSource.room); + } + }; + } + return cell; } } return nil; } - - (id)cellDataAtIndexPath:(NSIndexPath *)indexPath { id cellData = nil; diff --git a/Vector/ViewController/RecentsViewController.m b/Vector/ViewController/RecentsViewController.m index e3934dfe3..38827c49a 100644 --- a/Vector/ViewController/RecentsViewController.m +++ b/Vector/ViewController/RecentsViewController.m @@ -455,6 +455,28 @@ - (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes { + if ([dataSource isKindOfClass:[RecentsDataSource class]]) + { + RecentsDataSource* recentsDataSource = (RecentsDataSource*)dataSource; + + recentsDataSource.onRoomInvitationReject = ^(MXRoom* room) { + + [self.recentsTableView setEditing:NO]; + + [room leave:^{ + [self.recentsTableView reloadData]; + } failure:^(NSError *error) { + NSLog(@"[RecentsViewController] Failed to reject an invited room (%@) failed: %@", room.state.roomId, error); + }]; + + }; + + recentsDataSource.onRoomInvitationAccept = ^(MXRoom* room) { + [self selectRoomWithId:room.state.roomId inMatrixSession:room.mxSession]; + }; + } + + [self.recentsTableView reloadData]; if (shouldScrollToTopOnRefresh) @@ -663,6 +685,29 @@ static NSMutableDictionary* backgroundByImageNameDict; return [(RecentsDataSource*)self.dataSource heightForHeaderInSection:section]; } +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (self.delegate) + { + id cellData = [self.dataSource cellDataAtIndexPath:indexPath]; + + // the invited rooms cannot be selected. + // the invitation is accepted / rejected with dedicated buttons inside the cell. + // cell.userInteractionEnabled = NO would also disable the button so + // the cell selection is trapped. + if (NSNotFound == [cellData.recentsDataSource.mxSession.invitedRooms indexOfObject:cellData.roomDataSource.room]) + { + [self.delegate recentListViewController:self didSelectRoom:cellData.roomDataSource.roomId inMatrixSession:cellData.roomDataSource.mxSession]; + } + } + + // Hide the keyboard when user select a room + // do not hide the searchBar until the view controller disappear + // on tablets / iphone 6+, the user could expect to search again while looking at a room + [self.recentsSearchBar resignFirstResponder]; +} + + #pragma mark - Actions. - (void)onNewRoomPressed diff --git a/Vector/Views/RoomList/InviteRecentTableViewCell.h b/Vector/Views/RoomList/InviteRecentTableViewCell.h index 6773860f7..eda65554a 100644 --- a/Vector/Views/RoomList/InviteRecentTableViewCell.h +++ b/Vector/Views/RoomList/InviteRecentTableViewCell.h @@ -26,4 +26,14 @@ @property (weak, nonatomic) IBOutlet UIButton *leftButton; @property (weak, nonatomic) IBOutlet UIButton *rightButton; +/** + The user tap on the reject button + */ +@property (nonatomic, copy) void (^onRejectClick)(); + +/** + The user tap on the join button + */ +@property (nonatomic, copy) void (^onJoinClick)(); + @end diff --git a/Vector/Views/RoomList/InviteRecentTableViewCell.m b/Vector/Views/RoomList/InviteRecentTableViewCell.m index 5a57b1103..905dc103e 100644 --- a/Vector/Views/RoomList/InviteRecentTableViewCell.m +++ b/Vector/Views/RoomList/InviteRecentTableViewCell.m @@ -23,6 +23,7 @@ #import "VectorDesignValues.h" @implementation InviteRecentTableViewCell +@synthesize onRejectClick, onJoinClick; #pragma mark - Class methods @@ -35,20 +36,39 @@ self.leftButton.backgroundColor = VECTOR_GREEN_COLOR; [self.leftButton setTitle:NSLocalizedStringFromTable(@"join", @"Vector", nil) forState:UIControlStateNormal]; [self.leftButton setTitle:NSLocalizedStringFromTable(@"join", @"Vector", nil) forState:UIControlStateHighlighted]; + [self.leftButton addTarget:self action:@selector(onJoinPressed:) forControlEvents:UIControlEventTouchUpInside]; + [self.rightButton.layer setCornerRadius:5]; self.rightButton.clipsToBounds = YES; self.rightButton.backgroundColor = VECTOR_GREEN_COLOR; [self.rightButton setTitle:NSLocalizedStringFromTable(@"reject", @"Vector", nil) forState:UIControlStateNormal]; [self.rightButton setTitle:NSLocalizedStringFromTable(@"reject", @"Vector", nil) forState:UIControlStateHighlighted]; - - // the date is not displayed in the invitation cells. - self.lastEventDate.hidden = YES; + [self.rightButton addTarget:self action:@selector(onRejectedPressed:) forControlEvents:UIControlEventTouchUpInside]; +} + +- (void)onRejectedPressed:(id)sender +{ + if (self.onRejectClick) + { + self.onRejectClick(); + } +} + +- (void)onJoinPressed:(id)sender +{ + if (self.onJoinClick) + { + self.onJoinClick(); + } } - (void)render:(MXKCellData *)cellData { [super render:cellData]; + + // the date is not displayed in the invitation cells. + self.lastEventDate.hidden = YES; } + (CGFloat)heightForCellData:(MXKCellData *)cellData withMaximumWidth:(CGFloat)maxWidth From 6c9784e40a6a0fdbbd9a38ddac25f387e828aaae Mon Sep 17 00:00:00 2001 From: yannick Date: Thu, 10 Dec 2015 10:16:22 +0100 Subject: [PATCH 5/9] add_invite_rooms_section fix some UI issues. --- Vector/Model/RoomList/RecentsDataSource.m | 9 +++++++++ Vector/ViewController/RecentsViewController.m | 3 +++ Vector/Views/RoomList/InviteRecentTableViewCell.m | 2 ++ 3 files changed, 14 insertions(+) diff --git a/Vector/Model/RoomList/RecentsDataSource.m b/Vector/Model/RoomList/RecentsDataSource.m index 3c65f375d..e3e1f7e8f 100644 --- a/Vector/Model/RoomList/RecentsDataSource.m +++ b/Vector/Model/RoomList/RecentsDataSource.m @@ -110,6 +110,15 @@ } } +- (void)didMXSessionInviteRoomUpdate:(NSNotification *)notif +{ + MXSession *mxSession = notif.object; + if (mxSession == self.mxSession) + { + [self.delegate dataSource:self didCellChange:nil]; + } +} + #pragma mark - UITableViewDataSource /** diff --git a/Vector/ViewController/RecentsViewController.m b/Vector/ViewController/RecentsViewController.m index 38827c49a..0047be7d7 100644 --- a/Vector/ViewController/RecentsViewController.m +++ b/Vector/ViewController/RecentsViewController.m @@ -705,6 +705,9 @@ static NSMutableDictionary* backgroundByImageNameDict; // do not hide the searchBar until the view controller disappear // on tablets / iphone 6+, the user could expect to search again while looking at a room [self.recentsSearchBar resignFirstResponder]; + + // hide the selection + [tableView deselectRowAtIndexPath:indexPath animated:NO]; } diff --git a/Vector/Views/RoomList/InviteRecentTableViewCell.m b/Vector/Views/RoomList/InviteRecentTableViewCell.m index 905dc103e..441b1273c 100644 --- a/Vector/Views/RoomList/InviteRecentTableViewCell.m +++ b/Vector/Views/RoomList/InviteRecentTableViewCell.m @@ -45,6 +45,8 @@ [self.rightButton setTitle:NSLocalizedStringFromTable(@"reject", @"Vector", nil) forState:UIControlStateNormal]; [self.rightButton setTitle:NSLocalizedStringFromTable(@"reject", @"Vector", nil) forState:UIControlStateHighlighted]; [self.rightButton addTarget:self action:@selector(onRejectedPressed:) forControlEvents:UIControlEventTouchUpInside]; + + self.selectionStyle = UITableViewCellSelectionStyleNone; } - (void)onRejectedPressed:(id)sender From 8d2bede5985f7e7c685ced82530fa0b35486114c Mon Sep 17 00:00:00 2001 From: yannick Date: Thu, 10 Dec 2015 13:41:03 +0100 Subject: [PATCH 6/9] add_invite_rooms_section Fix a crash when selected a recent cells. --- Vector/Model/RoomList/RecentsDataSource.m | 72 +++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/Vector/Model/RoomList/RecentsDataSource.m b/Vector/Model/RoomList/RecentsDataSource.m index e3e1f7e8f..d3d6d8bea 100644 --- a/Vector/Model/RoomList/RecentsDataSource.m +++ b/Vector/Model/RoomList/RecentsDataSource.m @@ -292,6 +292,78 @@ return 0; } +- (NSInteger)cellIndexPosWithRoomId:(NSString*)roomId andMatrixSession:(MXSession*)matrixSession within:(NSMutableArray*)cellDataArray +{ + if (roomId && matrixSession && cellDataArray.count) + { + for (int index = 0; index < cellDataArray.count; index++) + { + id cellDataStoring = [cellDataArray objectAtIndex:index]; + + if ([roomId isEqualToString:cellDataStoring.roomDataSource.roomId] && (matrixSession == cellDataStoring.roomDataSource.mxSession)) + { + return index; + } + } + } + + return NSNotFound; +} + +- (NSIndexPath*)cellIndexPathWithRoomId:(NSString*)roomId andMatrixSession:(MXSession*)matrixSession +{ + NSIndexPath *indexPath = nil; + NSInteger index = NSNotFound; + + if (!indexPath && (invitesSection >= 0)) + { + index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:invitesCellDataArray]; + + if (index != NSNotFound) + { + indexPath = [NSIndexPath indexPathForRow:index inSection:invitesSection]; + } + } + + if (!indexPath && (favoritesSection >= 0)) + { + index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:favoriteCellDataArray]; + + if (index != NSNotFound) + { + indexPath = [NSIndexPath indexPathForRow:index inSection:favoritesSection]; + } + } + + if (!indexPath && (conversationSection >= 0)) + { + index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:conversationCellDataArray]; + + if (index != NSNotFound) + { + indexPath = [NSIndexPath indexPathForRow:index inSection:conversationSection]; + } + } + + if (!indexPath && (lowPrioritySection >= 0)) + { + index = [self cellIndexPosWithRoomId:roomId andMatrixSession:matrixSession within:lowPriorityCellDataArray]; + + if (index != NSNotFound) + { + indexPath = [NSIndexPath indexPathForRow:index inSection:lowPrioritySection]; + } + } + + if (!indexPath) + { + indexPath = [super cellIndexPathWithRoomId:roomId andMatrixSession:matrixSession]; + } + + return indexPath; +} + + #pragma mark - MXKDataSourceDelegate // create an array filled with NSNull and with the same size as sourceArray From dd1b9c92e6527cbbb14173255f44116d4403c0ef Mon Sep 17 00:00:00 2001 From: yannick Date: Thu, 10 Dec 2015 14:17:02 +0100 Subject: [PATCH 7/9] Update to the latest UI design --- .../RoomList/InviteRecentTableViewCell.m | 2 +- .../RoomList/InviteRecentTableViewCell.xib | 42 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Vector/Views/RoomList/InviteRecentTableViewCell.m b/Vector/Views/RoomList/InviteRecentTableViewCell.m index 441b1273c..4c0d1a04c 100644 --- a/Vector/Views/RoomList/InviteRecentTableViewCell.m +++ b/Vector/Views/RoomList/InviteRecentTableViewCell.m @@ -76,7 +76,7 @@ + (CGFloat)heightForCellData:(MXKCellData *)cellData withMaximumWidth:(CGFloat)maxWidth { // The height is fixed - return 84; + return 105; } @end diff --git a/Vector/Views/RoomList/InviteRecentTableViewCell.xib b/Vector/Views/RoomList/InviteRecentTableViewCell.xib index 8c066630b..602951b26 100644 --- a/Vector/Views/RoomList/InviteRecentTableViewCell.xib +++ b/Vector/Views/RoomList/InviteRecentTableViewCell.xib @@ -9,10 +9,10 @@ - + - + - + - - + + - - +