diff --git a/Vector/Assets/en.lproj/Vector.strings b/Vector/Assets/en.lproj/Vector.strings index 455bb298a..0964e785d 100644 --- a/Vector/Assets/en.lproj/Vector.strings +++ b/Vector/Assets/en.lproj/Vector.strings @@ -158,6 +158,9 @@ "media_picker_choose_from_library" = "Choose from library"; "media_picker_library" = "Library"; +// Directory +"directory_title" = "Directory"; + // Others "you" = "You"; "public_room_section_title" = "Public Rooms (at %@):"; diff --git a/Vector/Base.lproj/Main.storyboard b/Vector/Base.lproj/Main.storyboard index 2a588b9b8..9c5e81c57 100644 --- a/Vector/Base.lproj/Main.storyboard +++ b/Vector/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -201,7 +201,7 @@ - + @@ -216,20 +216,6 @@ - - - - - - - - - - - - - - diff --git a/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.h b/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.h index b3f36bf6a..a5180282a 100644 --- a/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.h +++ b/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.h @@ -30,7 +30,7 @@ There is no way in Matrix to be notified when there is a change in the public room directory. As a workaround, the data source refreshes its data when there are more than 10s old. */ -@interface PublicRoomsDirectoryDataSource : MXKDataSource +@interface PublicRoomsDirectoryDataSource : MXKDataSource /** All public rooms of the directory. diff --git a/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.m b/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.m index bfe86c810..6bfc95c22 100644 --- a/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.m +++ b/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.m @@ -16,6 +16,8 @@ #import "PublicRoomsDirectoryDataSource.h" +#import "MXKPublicRoomTableViewCell.h" + #pragma mark - Constants definitions // Time in seconds from which public rooms data is considered as obsolete @@ -124,4 +126,26 @@ double const kPublicRoomsDirectoryDataExpiration = 10; } } +#pragma mark - UITableViewDataSource + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return _filteredRooms.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + // For now reuse MatrixKit cells + // TODO: use custom cells and manage a mechanism a la MatrixKit with cellData + MXKPublicRoomTableViewCell *publicRoomCell = [tableView dequeueReusableCellWithIdentifier:[MXKPublicRoomTableViewCell defaultReuseIdentifier]]; + if (!publicRoomCell) + { + publicRoomCell = [[MXKPublicRoomTableViewCell alloc] init]; + } + + [publicRoomCell render:_filteredRooms[indexPath.row]]; + + return publicRoomCell; +} + @end diff --git a/Vector/Model/RoomList/RecentsDataSource.h b/Vector/Model/RoomList/RecentsDataSource.h index 6f63aa49d..4ad865902 100644 --- a/Vector/Model/RoomList/RecentsDataSource.h +++ b/Vector/Model/RoomList/RecentsDataSource.h @@ -16,6 +16,8 @@ #import +@class PublicRoomsDirectoryDataSource; + /** 'RecentsDataSource' class inherits from 'MXKInterleavedRecentsDataSource' to define Vector recents source. */ @@ -44,10 +46,15 @@ @property (nonatomic, copy) NSIndexPath* droppingCellIndexPath; /** - The movingCellBackgroundImage; + The movingCellBackgroundImage. */ @property (nonatomic) UIImageView* droppingCellBackGroundView; +/** + The data source used to manage search in public rooms. + */ +@property (nonatomic, readonly) PublicRoomsDirectoryDataSource *publicRoomsDirectoryDataSource; + /** Return the header height from the section. */ diff --git a/Vector/Model/RoomList/RecentsDataSource.m b/Vector/Model/RoomList/RecentsDataSource.m index 27b119efd..71dc63f24 100644 --- a/Vector/Model/RoomList/RecentsDataSource.m +++ b/Vector/Model/RoomList/RecentsDataSource.m @@ -32,8 +32,6 @@ NSMutableArray* conversationCellDataArray; NSMutableArray* lowPriorityCellDataArray; - PublicRoomsDirectoryDataSource *publicRoomsDirectoryDataSource; - NSInteger directorySection; NSInteger invitesSection; NSInteger favoritesSection; @@ -80,10 +78,10 @@ // Initialise the public room directory data source // Note that it is single matrix session only for now - if (!publicRoomsDirectoryDataSource) + if (!_publicRoomsDirectoryDataSource) { - publicRoomsDirectoryDataSource = [[PublicRoomsDirectoryDataSource alloc] initWithMatrixSession:mxSession]; - publicRoomsDirectoryDataSource.delegate = self; + _publicRoomsDirectoryDataSource = [[PublicRoomsDirectoryDataSource alloc] initWithMatrixSession:mxSession]; + _publicRoomsDirectoryDataSource.delegate = self; } } @@ -102,17 +100,17 @@ [roomTagsListenerByUserId removeObjectForKey:matrixSession.myUser.userId]; } - if (publicRoomsDirectoryDataSource.mxSession == matrixSession) + if (_publicRoomsDirectoryDataSource.mxSession == matrixSession) { - [publicRoomsDirectoryDataSource destroy]; - publicRoomsDirectoryDataSource = nil; + [_publicRoomsDirectoryDataSource destroy]; + _publicRoomsDirectoryDataSource = nil; } } } - (void)dataSource:(MXKDataSource*)dataSource didStateChange:(MXKDataSourceState)aState { - if (dataSource == publicRoomsDirectoryDataSource) + if (dataSource == _publicRoomsDirectoryDataSource) { [self refreshRoomsSectionsAndReload]; } @@ -294,7 +292,7 @@ directoryCell = [[DirectoryRecentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[DirectoryRecentTableViewCell defaultReuseIdentifier]]; } - [directoryCell render:publicRoomsDirectoryDataSource]; + [directoryCell render:_publicRoomsDirectoryDataSource]; return directoryCell; } @@ -529,7 +527,7 @@ // Manage the public room search results cell outside the recents. // Show the cell showing the public rooms directory search result // once a search is active - if (publicRoomsDirectoryDataSource.filter) + if (_publicRoomsDirectoryDataSource.filter) { directorySection = sectionIndex; sectionIndex++; @@ -653,11 +651,11 @@ { [super searchWithPatterns:patternsList]; - if (patternsList && publicRoomsDirectoryDataSource) + if (patternsList && _publicRoomsDirectoryDataSource) { // Search only on the first pattern // XXX: Why is it an array? - publicRoomsDirectoryDataSource.filter = patternsList[0]; + _publicRoomsDirectoryDataSource.filter = patternsList[0]; } } diff --git a/Vector/ViewController/DirectoryViewController.h b/Vector/ViewController/DirectoryViewController.h index 7216ca087..ada83aca8 100644 --- a/Vector/ViewController/DirectoryViewController.h +++ b/Vector/ViewController/DirectoryViewController.h @@ -16,6 +16,15 @@ #import -@interface DirectoryViewController : MXKTableViewController +@class PublicRoomsDirectoryDataSource; + +@interface DirectoryViewController : MXKTableViewController + +/** + Display data managed by the passed `PublicRoomsDirectoryDataSource`. + + @param dataSource the data source serving the data. + */ +- (void)displayWitDataSource:(PublicRoomsDirectoryDataSource*)dataSource; @end diff --git a/Vector/ViewController/DirectoryViewController.m b/Vector/ViewController/DirectoryViewController.m index 9bcf72009..cf590ae57 100644 --- a/Vector/ViewController/DirectoryViewController.m +++ b/Vector/ViewController/DirectoryViewController.m @@ -16,20 +16,35 @@ #import "DirectoryViewController.h" +#import "PublicRoomsDirectoryDataSource.h" + @interface DirectoryViewController () @end @implementation DirectoryViewController -- (void)viewDidLoad { +- (void)viewDidLoad +{ [super viewDidLoad]; - // Do any additional setup after loading the view. + + self.title = NSLocalizedStringFromTable(@"directory_title", @"Vector", nil); + + self.tableView.delegate = self; } -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. + +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + + [self.tableView reloadData]; +} + +- (void)displayWitDataSource:(PublicRoomsDirectoryDataSource *)dataSource +{ + // Let the data source provide cells + self.tableView.dataSource = dataSource; } /* @@ -42,4 +57,10 @@ } */ +#pragma mark - UITableViewDelegate + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return 72; +} @end diff --git a/Vector/ViewController/HomeViewController.h b/Vector/ViewController/HomeViewController.h index f3207dc0d..32cea0954 100644 --- a/Vector/ViewController/HomeViewController.h +++ b/Vector/ViewController/HomeViewController.h @@ -53,6 +53,12 @@ */ - (void)closeSelectedRoom; +/** + Open the public rooms directory page. + It uses the `publicRoomsDirectoryDataSource` managed by the recents view controller data source + */ +- (void)showPublicRoomsDirectory; + /** Action registered on `UIControlEventTouchUpInside` event for both buttons. */ diff --git a/Vector/ViewController/HomeViewController.m b/Vector/ViewController/HomeViewController.m index 510c474b4..4f417831b 100644 --- a/Vector/ViewController/HomeViewController.m +++ b/Vector/ViewController/HomeViewController.m @@ -20,6 +20,7 @@ #import "RecentsViewController.h" #import "RoomViewController.h" +#import "DirectoryViewController.h" @interface HomeViewController () { @@ -312,6 +313,11 @@ } } +- (void)showPublicRoomsDirectory +{ + [self performSegueWithIdentifier:@"showDirectory" sender:self]; +} + #pragma mark - Internal methods // Made the currently displayed child update its selected cell @@ -379,6 +385,11 @@ controller.navigationItem.leftItemsSupplementBackButton = YES; } } + else if ([[segue identifier] isEqualToString:@"showDirectory"]) + { + DirectoryViewController *directoryViewController = segue.destinationViewController; + [directoryViewController displayWitDataSource:recentsDataSource.publicRoomsDirectoryDataSource]; + } // Hide back button title self.navigationItem.backBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; diff --git a/Vector/ViewController/RecentsViewController.m b/Vector/ViewController/RecentsViewController.m index 012949138..943258ac2 100644 --- a/Vector/ViewController/RecentsViewController.m +++ b/Vector/ViewController/RecentsViewController.m @@ -28,6 +28,7 @@ #import "VectorDesignValues.h" #import "InviteRecentTableViewCell.h" +#import "DirectoryRecentTableViewCell.h" @interface RecentsViewController () { @@ -458,6 +459,11 @@ static NSMutableDictionary* backgroundByImageNameDict; // hide the selection [tableView deselectRowAtIndexPath:indexPath animated:NO]; } + else if ([cell isKindOfClass:[DirectoryRecentTableViewCell class]]) + { + // Show the directory screen + [homeViewController showPublicRoomsDirectory]; + } else { [super tableView:tableView didSelectRowAtIndexPath:indexPath];