diff --git a/Vector.xcodeproj/project.pbxproj b/Vector.xcodeproj/project.pbxproj index 6dc2ea332..8c3a60112 100644 --- a/Vector.xcodeproj/project.pbxproj +++ b/Vector.xcodeproj/project.pbxproj @@ -51,7 +51,6 @@ F094AA2A1B78E42600B1FBBF /* RageShakeManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA091B78E42600B1FBBF /* RageShakeManager.m */; }; F094AA2B1B78E42600B1FBBF /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = F094AA0B1B78E42600B1FBBF /* Localizable.strings */; }; F094AA2C1B78E42600B1FBBF /* Vector.strings in Resources */ = {isa = PBXBuildFile; fileRef = F094AA0D1B78E42600B1FBBF /* Vector.strings */; }; - F094AA2D1B78E42600B1FBBF /* RecentListDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA121B78E42600B1FBBF /* RecentListDataSource.m */; }; F094AA2E1B78E42600B1FBBF /* countryCodes.plist in Resources */ = {isa = PBXBuildFile; fileRef = F094AA141B78E42600B1FBBF /* countryCodes.plist */; }; F094AA2F1B78E42600B1FBBF /* AccountDetailsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA171B78E42600B1FBBF /* AccountDetailsViewController.m */; }; F094AA301B78E42600B1FBBF /* AuthenticationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA191B78E42600B1FBBF /* AuthenticationViewController.m */; }; @@ -154,8 +153,6 @@ F094AA091B78E42600B1FBBF /* RageShakeManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RageShakeManager.m; sourceTree = ""; }; F094AA0C1B78E42600B1FBBF /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; F094AA0E1B78E42600B1FBBF /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Vector.strings; sourceTree = ""; }; - F094AA111B78E42600B1FBBF /* RecentListDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RecentListDataSource.h; sourceTree = ""; }; - F094AA121B78E42600B1FBBF /* RecentListDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RecentListDataSource.m; sourceTree = ""; }; F094AA141B78E42600B1FBBF /* countryCodes.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = countryCodes.plist; sourceTree = ""; }; F094AA161B78E42600B1FBBF /* AccountDetailsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccountDetailsViewController.h; sourceTree = ""; }; F094AA171B78E42600B1FBBF /* AccountDetailsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AccountDetailsViewController.m; sourceTree = ""; }; @@ -386,8 +383,6 @@ isa = PBXGroup; children = ( F08BE09F1B87064000C480FB /* Room */, - F094AA111B78E42600B1FBBF /* RecentListDataSource.h */, - F094AA121B78E42600B1FBBF /* RecentListDataSource.m */, ); path = Model; sourceTree = ""; @@ -682,7 +677,6 @@ F094AA321B78E42600B1FBBF /* GlobalNotificationSettingsViewController.m in Sources */, F094A9A81B78D8F000B1FBBF /* main.m in Sources */, F0DD7D881B7B507100C4BE02 /* RoomCreationStep2ViewController.m in Sources */, - F094AA2D1B78E42600B1FBBF /* RecentListDataSource.m in Sources */, F094AA2A1B78E42600B1FBBF /* RageShakeManager.m in Sources */, F094AA351B78E42600B1FBBF /* RecentsViewController.m in Sources */, F08BE09E1B87025B00C480FB /* EventFormatter.m in Sources */, diff --git a/Vector/Assets/en.lproj/Vector.strings b/Vector/Assets/en.lproj/Vector.strings index 12dcd0928..6d375e521 100644 --- a/Vector/Assets/en.lproj/Vector.strings +++ b/Vector/Assets/en.lproj/Vector.strings @@ -15,7 +15,7 @@ */ // Titles -"recents" = "Recents"; +"recents" = "Messages"; "accounts" = "Accounts"; // Actions diff --git a/Vector/Model/RecentListDataSource.h b/Vector/Model/RecentListDataSource.h deleted file mode 100644 index 076ca6c41..000000000 --- a/Vector/Model/RecentListDataSource.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - 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 - -/** - The data source for `RecentsViewController` in Vector - List the recents (interleaved in only one section in case of multi-sessions) and the available public rooms. - A section of public rooms is added for each added REST client. - - Two different types of cell data are handled by this data source: id for the recents - and MXPublicRoom* for the public rooms added after the recents list. - See publicRoomsFirstSection property to know which type is expected for cell data at a specific indexPath. - */ -@interface RecentListDataSource : MXKInterleavedRecentsDataSource - -/** - The first Public rooms sections (-1 if none). - */ -@property NSInteger publicRoomsFirstSection; - -/** - Add a matrix REST Client. It is used to retrieve public rooms. - - @param restClient a restClient. - @param onComplete the callback called once public rooms are updated for this client. - */ -- (void)addRestClient:(MXRestClient*)restClient onComplete:(void (^)())onComplete; - -/** - Remove a matrix REST Client. - */ -- (void)removeRestClient:(MXRestClient*)restClient; - -/** - Refresh public rooms - - @param restClient a restClient, or nil to refresh public rooms for all added client. - @param onComplete the callback called once public rooms are updated. - */ -- (void)refreshPublicRooms:(MXRestClient*)restClient onComplete:(void (^)())onComplete; - -/** - Get the public room displayed in the cell at the given index path. - - @param indexPath the index of the cell - @return a public room or nil if the provided indexPath does not correspond to a public room section. - */ -- (MXPublicRoom*)publicRoomAtIndexPath:(NSIndexPath*)indexPath; - -@end diff --git a/Vector/Model/RecentListDataSource.m b/Vector/Model/RecentListDataSource.m deleted file mode 100644 index 88c06d6cf..000000000 --- a/Vector/Model/RecentListDataSource.m +++ /dev/null @@ -1,629 +0,0 @@ -/* - 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 "RecentListDataSource.h" - -#import "AppDelegate.h" - -#import "EventFormatter.h" - -#import "NSBundle+MatrixKit.h" - -@interface RecentListDataSource () -{ - // - UIButton *recentsShrinkButton; - BOOL areRecentsShrinked; - - // Homeserver list - NSMutableArray *homeServers; - // All registered REST clients - NSMutableArray *restClients; - // REST clients by homeserver - NSMutableDictionary *restClientDict; - // Public rooms by homeserver - NSMutableDictionary *publicRoomsDict; - // Array of shrinked homeservers. - NSMutableArray *shrinkedHomeServers; - // Count current refresh requests - NSInteger refreshCount; - - // List of public room names to highlight in displayed list - NSArray* highlightedPublicRooms; - - // Search in public rooms - NSMutableDictionary *filteredPublicRoomsDict; -} -@end - -@implementation RecentListDataSource - -- (instancetype)init -{ - self = [super init]; - if (self) - { - self.eventFormatter = [[EventFormatter alloc] initWithMatrixSession:self.mxSession]; - self.eventFormatter.isForSubtitle = YES; - - highlightedPublicRooms = @[@"#matrix:matrix.org", @"#matrix-dev:matrix.org", @"#matrix-fr:matrix.org"]; // Add here a room name to highlight its display in public room list - } - return self; -} - -- (void)destroy -{ - homeServers = nil; - restClients = nil; - restClientDict = nil; - publicRoomsDict = nil; - filteredPublicRoomsDict = nil; - shrinkedHomeServers = nil; - - highlightedPublicRooms = nil; - - [super destroy]; -} - -#pragma mark - - -- (void)addRestClient:(MXRestClient*)restClient onComplete:(void (^)())onComplete -{ - if (!restClient.homeserver) - { - return; - } - - if (!homeServers) - { - homeServers = [NSMutableArray array]; - } - if (!restClients) - { - restClients = [NSMutableArray array]; - } - if (!restClientDict) - { - restClientDict = [NSMutableDictionary dictionary]; - } - - if ([restClients indexOfObject:restClient] == NSNotFound) - { - [restClients addObject:restClient]; - - if ([homeServers indexOfObject:restClient.homeserver] == NSNotFound){ - [homeServers addObject:restClient.homeserver]; - [restClientDict setObject:restClient forKey:restClient.homeserver]; - [self refreshPublicRooms:restClient onComplete:onComplete]; - } - } -} - -- (void)removeRestClient:(MXRestClient *)restClient -{ - NSUInteger index = [restClients indexOfObject:restClient]; - if (index != NSNotFound) - { - [restClients removeObjectAtIndex:index]; - - // Check whether this client was reported in rest client dictionary - for (NSString *homeserver in homeServers) - { - if ([restClientDict objectForKey:homeserver] == restClient) - { - [restClientDict removeObjectForKey:homeserver]; - BOOL removeHomeServer = YES; - - // Look for an other rest client for this homeserver (if any) - for (MXRestClient *client in restClients) - { - if ([client.homeserver isEqualToString:homeserver]) - { - [restClientDict setObject:client forKey:homeserver]; - removeHomeServer = NO; - break; - } - } - - if (removeHomeServer) - { - [homeServers removeObject:homeserver]; - [publicRoomsDict removeObjectForKey:homeserver]; - } - - [self refreshPublicRooms:nil onComplete:nil]; - break; - } - } - } -} - -- (void)removeClosedRestClients -{ - // We check here all registered clients (Some of them may have been closed). - for (NSInteger index = 0; index < restClients.count; index ++) - { - MXRestClient *restClient = [restClients objectAtIndex:index]; - if (!restClient.homeserver.length) - { - [self removeRestClient:restClient]; - } - } -} - -- (void)refreshPublicRooms:(MXRestClient*)restClient onComplete:(void (^)())onComplete -{ - NSArray *selectedClients; - if (restClient) - { - selectedClients = @[restClient]; - } - else - { - // refresh registered clients by removing closed ones. - [self removeClosedRestClients]; - - // Consider only one client by homeserver. - selectedClients = restClientDict.allValues; - } - - if (!selectedClients.count) - { - return; - } - - refreshCount += selectedClients.count; - - if (!publicRoomsDict) - { - publicRoomsDict = [NSMutableDictionary dictionaryWithCapacity:restClientDict.count]; - } - if (!shrinkedHomeServers) - { - shrinkedHomeServers = [NSMutableArray array]; - } - - for (NSInteger index = 0; index < selectedClients.count; index ++) - { - MXRestClient *restClient = [selectedClients objectAtIndex:index]; - - // Retrieve public rooms - [restClient publicRooms:^(NSArray *rooms) { - - NSArray *publicRooms = [rooms sortedArrayUsingComparator:^NSComparisonResult(id a, id b) { - - MXPublicRoom *firstRoom = (MXPublicRoom*)a; - MXPublicRoom *secondRoom = (MXPublicRoom*)b; - - // Compare member count - if (firstRoom.numJoinedMembers < secondRoom.numJoinedMembers) - { - return NSOrderedDescending; - } - else if (firstRoom.numJoinedMembers > secondRoom.numJoinedMembers) - { - return NSOrderedAscending; - } - else - { - // Alphabetic order - return [firstRoom.displayname compare:secondRoom.displayname options:NSCaseInsensitiveSearch]; - } - }]; - - if (publicRooms.count && restClient.homeserver) - { - [publicRoomsDict setObject:publicRooms forKey:restClient.homeserver]; - } - - refreshCount--; - if (refreshCount == 0) - { - [self.delegate dataSource:self didCellChange:nil]; - - if (onComplete) - { - onComplete(); - } - } - } failure:^(NSError *error) { - - NSLog(@"[RecentListDataSource] Failed to get public rooms for %@: %@", restClient.homeserver, error); - //Alert user - [[AppDelegate theDelegate] showErrorAsAlert:error]; - - refreshCount--; - if (refreshCount == 0) - { - [self.delegate dataSource:self didCellChange:nil]; - - if (onComplete) - { - onComplete(); - } - } - - }]; - } -} - -- (MXPublicRoom*)publicRoomAtIndexPath:(NSIndexPath*)indexPath -{ - MXPublicRoom *publicRoom = nil; - - if (_publicRoomsFirstSection != -1 && indexPath.section >= _publicRoomsFirstSection) - { - NSInteger index = indexPath.section - _publicRoomsFirstSection; - if (index < homeServers.count) - { - NSString *homeserver = [homeServers objectAtIndex:index]; - NSArray *publicRooms = nil; - if (filteredPublicRoomsDict) - { - publicRooms = [filteredPublicRoomsDict objectForKey:homeserver]; - } - else - { - publicRooms = [publicRoomsDict objectForKey:homeserver]; - } - - if (indexPath.row < publicRooms.count) - { - publicRoom = [publicRooms objectAtIndex:indexPath.row]; - } - } - } - - return publicRoom; -} - -#pragma mark - Override MXKRecentsDataSource - -- (void)addMatrixSession:(MXSession *)matrixSession -{ - [super addMatrixSession:matrixSession]; - - [self addRestClient:matrixSession.matrixRestClient onComplete:nil]; -} - -- (void)removeMatrixSession:(MXSession*)matrixSession -{ - [super removeMatrixSession:matrixSession]; - - // Remove the related REST Client - if (matrixSession.matrixRestClient) - { - [self removeRestClient:matrixSession.matrixRestClient]; - } - else - { - // Here the matrix session is closed, the rest client reference has been removed. - // Force a full refresh - [self refreshPublicRooms:nil onComplete:nil]; - } -} - -- (void)searchWithPatterns:(NSArray*)patternsList -{ - [super searchWithPatterns:patternsList]; - - // Update filtered list - if (patternsList.count) - { - if (filteredPublicRoomsDict) - { - [filteredPublicRoomsDict removeAllObjects]; - } - else - { - filteredPublicRoomsDict = [NSMutableDictionary dictionaryWithCapacity:homeServers.count]; - } - - for (NSString* pattern in patternsList) - { - for (NSString *homeserver in homeServers) - { - NSArray *publicRooms = [publicRoomsDict objectForKey:homeserver]; - - NSMutableArray *filteredRooms = [filteredPublicRoomsDict objectForKey:homeserver]; - if (!filteredRooms) - { - filteredRooms = [NSMutableArray array]; - } - - for (MXPublicRoom *publicRoom in publicRooms) - { - if ([[publicRoom displayname] rangeOfString:pattern options:NSCaseInsensitiveSearch].location != NSNotFound) - { - if ([filteredRooms indexOfObject:publicRoom] == NSNotFound) - { - [filteredRooms addObject:publicRoom]; - } - } - } - - if (filteredRooms.count) - { - [filteredPublicRoomsDict setObject:filteredRooms forKey:homeserver]; - } - } - } - } - else - { - filteredPublicRoomsDict = nil; - } - - [self.delegate dataSource:self didCellChange:nil]; -} - -- (CGFloat)cellHeightAtIndexPath:(NSIndexPath*)indexPath -{ - if (_publicRoomsFirstSection != -1 && indexPath.section >= _publicRoomsFirstSection) - { - return 60; - } - return [super cellHeightAtIndexPath:indexPath]; -} - -- (UIView *)viewForHeaderInSection:(NSInteger)section withFrame:(CGRect)frame -{ - UIView *sectionHeader = nil; - NSString* sectionTitle; - BOOL isShrinked = NO; - NSInteger buttonTag = 0; - - if (section < _publicRoomsFirstSection) - { - sectionHeader = [super viewForHeaderInSection:section withFrame:frame]; - - // Here sectionHeader is nil if there is only one session - if (!sectionHeader) - { - // Let's create a header to shrink recents - sectionTitle = self.mxSession.myUser.userId; - if (self.unreadCount) - { - sectionTitle = [NSString stringWithFormat:@"%@ (%tu)", sectionTitle, self.unreadCount]; - } - - isShrinked = areRecentsShrinked; - buttonTag = 0; - } - } - else - { - NSArray *publicRooms = nil; - NSString *homeserver; - NSInteger index = section - _publicRoomsFirstSection; - if (index < homeServers.count) - { - homeserver = [homeServers objectAtIndex:index]; - - if (filteredPublicRoomsDict) - { - publicRooms = [filteredPublicRoomsDict objectForKey:homeserver]; - } - else - { - publicRooms = [publicRoomsDict objectForKey:homeserver]; - } - } - - if (publicRooms) - { - sectionTitle = [NSString stringWithFormat:NSLocalizedStringFromTable(@"public_room_section_title", @"Vector", nil), homeserver]; - isShrinked = ([shrinkedHomeServers indexOfObject:homeserver] != NSNotFound); - buttonTag = self.displayedRecentsDataSourcesCount + index; - } - } - - if (!sectionHeader && sectionTitle.length) - { - sectionHeader = [[UIView alloc] initWithFrame:frame]; - sectionHeader.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]; - - // Add shrink button - UIButton *shrinkButton = [UIButton buttonWithType:UIButtonTypeCustom]; - CGRect frame = sectionHeader.frame; - frame.origin.x = frame.origin.y = 0; - shrinkButton.frame = frame; - shrinkButton.backgroundColor = [UIColor clearColor]; - [shrinkButton addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; - shrinkButton.tag = buttonTag; - [sectionHeader addSubview:shrinkButton]; - sectionHeader.userInteractionEnabled = YES; - - // Add shrink icon - UIImage *chevron; - if (isShrinked) - { - chevron = [NSBundle mxk_imageFromMXKAssetsBundleWithName:@"disclosure"]; - } - else - { - chevron = [NSBundle mxk_imageFromMXKAssetsBundleWithName:@"shrink"]; - } - UIImageView *chevronView = [[UIImageView alloc] initWithImage:chevron]; - chevronView.contentMode = UIViewContentModeCenter; - frame = chevronView.frame; - frame.origin.x = sectionHeader.frame.size.width - frame.size.width - 8; - frame.origin.y = (sectionHeader.frame.size.height - frame.size.height) / 2; - chevronView.frame = frame; - [sectionHeader addSubview:chevronView]; - chevronView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin); - - // Add label - frame = sectionHeader.frame; - frame.origin.x = 5; - frame.origin.y = 5; - frame.size.width = chevronView.frame.origin.x - 10; - frame.size.height -= 10; - UILabel *headerLabel = [[UILabel alloc] initWithFrame:frame]; - headerLabel.font = [UIFont boldSystemFontOfSize:16]; - headerLabel.backgroundColor = [UIColor clearColor]; - headerLabel.text = sectionTitle; - [sectionHeader addSubview:headerLabel]; - } - - return sectionHeader; -} - -- (IBAction)onButtonPressed:(id)sender -{ - if ([sender isKindOfClass:[UIButton class]]) - { - UIButton *shrinkButton = (UIButton*)sender; - - if (shrinkButton.tag < self.displayedRecentsDataSourcesCount) - { - if (self.displayedRecentsDataSourcesCount > 1) - { - [super onButtonPressed:sender]; - } - else - { - areRecentsShrinked = !areRecentsShrinked; - [self.delegate dataSource:self didCellChange:nil]; - } - } - else - { - NSInteger tag = shrinkButton.tag - self.displayedRecentsDataSourcesCount; - if (tag < homeServers.count) - { - NSString *homeserver = [homeServers objectAtIndex:tag]; - - NSUInteger index = [shrinkedHomeServers indexOfObject:homeserver]; - if (index != NSNotFound) - { - // Disclose the public rooms list - [shrinkedHomeServers removeObjectAtIndex:index]; - } - else - { - // Shrink the public rooms list from this homeserver. - [shrinkedHomeServers addObject:homeserver]; - } - // trigger table refresh - [self.delegate dataSource:self didCellChange:nil]; - } - } - } -} - -#pragma mark - UITableViewDataSource - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView -{ - NSInteger sectionNb = [super numberOfSectionsInTableView:tableView]; - - _publicRoomsFirstSection = -1; - - if (homeServers.count) - { - // Add a section for each list of public rooms - _publicRoomsFirstSection = sectionNb; - sectionNb += homeServers.count; - } - - return sectionNb; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ - NSInteger count = 0; - - if (_publicRoomsFirstSection == -1 || section < _publicRoomsFirstSection) - { - count = [super tableView:tableView numberOfRowsInSection:section]; - - if (areRecentsShrinked) - { - count = 0; - } - - } - else - { - NSArray *publicRooms = nil; - NSInteger index = section - _publicRoomsFirstSection; - if (index < homeServers.count) - { - NSString *homeserver = [homeServers objectAtIndex:index]; - - // Check whether the list is shrinked - if ([shrinkedHomeServers indexOfObject:homeserver] == NSNotFound) - { - if (filteredPublicRoomsDict) - { - publicRooms = [filteredPublicRoomsDict objectForKey:homeserver]; - } - else - { - publicRooms = [publicRoomsDict objectForKey:homeserver]; - } - } - } - - count = publicRooms.count; - } - - return count; -} - -- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath -{ - // Public rooms are not editable - if (_publicRoomsFirstSection == -1 || indexPath.section < _publicRoomsFirstSection) - { - return YES; - } - - return NO; -} - -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - UITableViewCell *cell; - - if (_publicRoomsFirstSection == -1 || indexPath.section < _publicRoomsFirstSection) - { - cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]; - } - else - { - MXKPublicRoomTableViewCell *publicRoomCell = [tableView dequeueReusableCellWithIdentifier:[MXKPublicRoomTableViewCell defaultReuseIdentifier]]; - if (!publicRoomCell) - { - publicRoomCell = [[MXKPublicRoomTableViewCell alloc] init]; - } - - MXPublicRoom *publicRoom = [self publicRoomAtIndexPath:indexPath]; - if (publicRoom) - { - [publicRoomCell render:publicRoom]; - // Highlight? - publicRoomCell.highlightedPublicRoom = (publicRoomCell.roomDisplayName.text && [highlightedPublicRooms indexOfObject:publicRoomCell.roomDisplayName.text] != NSNotFound); - } - - cell = publicRoomCell; - } - - return cell; -} - -@end diff --git a/Vector/ViewController/RecentsViewController.m b/Vector/ViewController/RecentsViewController.m index d56a05949..bf6fe5c77 100644 --- a/Vector/ViewController/RecentsViewController.m +++ b/Vector/ViewController/RecentsViewController.m @@ -17,14 +17,10 @@ #import "RecentsViewController.h" #import "RoomViewController.h" -#import "AppDelegate.h" - #import "RageShakeManager.h" #import "NSBundle+MatrixKit.h" -#import "RecentListDataSource.h" - @interface RecentsViewController () { // Recents refresh handling @@ -39,10 +35,6 @@ // Keep the selected cell index to handle correctly split view controller display in landscape mode NSIndexPath *currentSelectedCellIndexPath; - - // "Mark all as read" option - UITapGestureRecognizer *navigationBarTapGesture; - MXKAlert *markAllAsReadAlert; } @end @@ -52,10 +44,13 @@ - (void)awakeFromNib { [super awakeFromNib]; + if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { self.preferredContentSize = CGSizeMake(320.0, 600.0); } + + self.navigationItem.title = NSLocalizedStringFromTable(@"recents", @"Vector", nil); } - (void)viewDidLoad @@ -63,12 +58,6 @@ [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. - // Prepare tap gesture on title bar - navigationBarTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onNavigationBarTap:)]; - [navigationBarTapGesture setNumberOfTouchesRequired:1]; - [navigationBarTapGesture setNumberOfTapsRequired:1]; - [navigationBarTapGesture setDelegate:self]; - // Initialisation currentSelectedCellIndexPath = nil; @@ -86,19 +75,6 @@ - (void)destroy { - if (markAllAsReadAlert) - - { - [markAllAsReadAlert dismiss:NO]; - markAllAsReadAlert = nil; - } - - if (navigationBarTapGesture) - { - [self.navigationController.navigationBar removeGestureRecognizer:navigationBarTapGesture]; - navigationBarTapGesture = nil; - } - [super destroy]; } @@ -119,25 +95,12 @@ { [super viewWillAppear:animated]; - [self updateNavigationBarTitle]; - // Deselect the current selected row, it will be restored on viewDidAppear (if any) NSIndexPath *indexPath = [self.recentsTableView indexPathForSelectedRow]; if (indexPath) { [self.recentsTableView deselectRowAtIndexPath:indexPath animated:NO]; } - - RecentListDataSource *recentListDataSource = (RecentListDataSource*)self.dataSource; - if (recentListDataSource) - { - [self startActivityIndicator]; - [recentListDataSource refreshPublicRooms:nil onComplete:^{ - [self stopActivityIndicator]; - }]; - } - - [self.navigationController.navigationBar addGestureRecognizer:navigationBarTapGesture]; } - (void)viewWillDisappear:(BOOL)animated @@ -149,14 +112,6 @@ selectedRoomId = nil; selectedRoomSession = nil; - - if (markAllAsReadAlert) - { - [markAllAsReadAlert dismiss:NO]; - markAllAsReadAlert = nil; - } - - [self.navigationController.navigationBar removeGestureRecognizer:navigationBarTapGesture]; } - (void)viewDidAppear:(BOOL)animated @@ -183,67 +138,6 @@ [super viewDidDisappear:animated]; } -- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section -{ - return 35; -} - -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath -{ - // Check whether the selected row is a public room or not - RecentListDataSource *recentListDataSource = (RecentListDataSource*)self.dataSource; - if (recentListDataSource && recentListDataSource.publicRoomsFirstSection != -1 && indexPath.section >= recentListDataSource.publicRoomsFirstSection) - { - MXPublicRoom *publicRoom = [recentListDataSource publicRoomAtIndexPath:indexPath]; - if (publicRoom) - { - // Handle multi-sessions here - [[AppDelegate theDelegate] selectMatrixAccount:^(MXKAccount *selectedAccount) { - // Check whether the user has already joined the selected public room - if ([selectedAccount.mxSession roomWithRoomId:publicRoom.roomId]) - { - // Open selected room - [[AppDelegate theDelegate] showRoom:publicRoom.roomId withMatrixSession:selectedAccount.mxSession]; - } - else - { - // Join the selected room - UIActivityIndicatorView *loadingWheel = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; - UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; - if (selectedCell) - { - CGPoint center = CGPointMake(selectedCell.frame.size.width / 2, selectedCell.frame.size.height / 2); - loadingWheel.center = center; - [selectedCell addSubview:loadingWheel]; - } - [loadingWheel startAnimating]; - [selectedAccount.mxSession joinRoom:publicRoom.roomId success:^(MXRoom *room) - { - // Show joined room - [loadingWheel stopAnimating]; - [loadingWheel removeFromSuperview]; - [[AppDelegate theDelegate] showRoom:publicRoom.roomId withMatrixSession:selectedAccount.mxSession]; - } failure:^(NSError *error) - { - NSLog(@"[HomeVC] Failed to join public room (%@): %@", publicRoom.displayname, error); - //Alert user - [loadingWheel stopAnimating]; - [loadingWheel removeFromSuperview]; - [[AppDelegate theDelegate] showErrorAsAlert:error]; - }]; - } - - }]; - } - [tableView deselectRowAtIndexPath:indexPath animated:YES]; - } - else - { - // Let super handle the selected row - [super tableView:tableView didSelectRowAtIndexPath:indexPath]; - } -} - #pragma mark - - (void)selectRoomWithId:(NSString*)roomId inMatrixSession:(MXSession*)matrixSession @@ -290,23 +184,13 @@ #pragma mark - Internal methods -- (void)updateNavigationBarTitle -{ - NSString *title = NSLocalizedStringFromTable(@"recents", @"Vector", nil); - - if (self.dataSource.unreadCount) - { - title = [NSString stringWithFormat:@"%@ (%tu)", title, self.dataSource.unreadCount]; - } - self.navigationItem.title = title; -} - - (void)scrollToTop { - // stop any scrolling effect + // Stop any scrolling effect before scrolling to the tableview top [UIView setAnimationsEnabled:NO]; - // before scrolling to the tableview top + self.recentsTableView.contentOffset = CGPointMake(-self.recentsTableView.contentInset.left, -self.recentsTableView.contentInset.top); + [UIView setAnimationsEnabled:YES]; } @@ -350,37 +234,6 @@ } } -#pragma mark - - -- (void)onNavigationBarTap:(id)sender -{ - if (self.dataSource.unreadCount) - - { - __weak typeof(self) weakSelf = self; - - markAllAsReadAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"mark_all_as_read_prompt", @"Vector", nil) message:nil style:MXKAlertStyleAlert]; - - markAllAsReadAlert.cancelButtonIndex = [markAllAsReadAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"no"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) - { - typeof(self) strongSelf = weakSelf; - strongSelf->markAllAsReadAlert = nil; - }]; - - [markAllAsReadAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"yes"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) - { - typeof(self) strongSelf = weakSelf; - - strongSelf->markAllAsReadAlert = nil; - - [strongSelf.dataSource markAllAsRead]; - [strongSelf updateNavigationBarTitle]; - }]; - - [markAllAsReadAlert showInViewController:self]; - } -} - #pragma mark - Segues - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender @@ -424,8 +277,6 @@ [currentRoomViewController displayRoom:roomDataSource]; } - [self updateNavigationBarTitle]; - if (self.splitViewController) { // Refresh selected cell without scrolling the selected cell (We suppose it's visible here) @@ -447,11 +298,9 @@ } #pragma mark - MXKDataSourceDelegate + - (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes { - // Update the unreadCount in the title - [self updateNavigationBarTitle]; - [self.recentsTableView reloadData]; if (shouldScrollToTopOnRefresh) @@ -470,6 +319,7 @@ } #pragma mark - MXKRecentListViewControllerDelegate + - (void)recentListViewController:(MXKRecentListViewController *)recentListViewController didSelectRoom:(NSString *)roomId inMatrixSession:(MXSession *)matrixSession { // Open the room