2015-12-16 15:29:34 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
2017-03-08 15:14:41 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2015-12-16 15:29:34 +00:00
|
|
|
|
|
|
|
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 "DirectoryViewController.h"
|
|
|
|
|
2015-12-18 16:17:03 +00:00
|
|
|
#import "PublicRoomsDirectoryDataSource.h"
|
|
|
|
|
2021-10-26 15:42:33 +00:00
|
|
|
#import "GeneratedInterface-Swift.h"
|
2015-12-18 17:25:39 +00:00
|
|
|
|
2015-12-16 15:29:34 +00:00
|
|
|
@interface DirectoryViewController ()
|
2015-12-18 17:25:39 +00:00
|
|
|
{
|
|
|
|
PublicRoomsDirectoryDataSource *dataSource;
|
2016-06-20 12:11:27 +00:00
|
|
|
|
|
|
|
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
|
|
|
|
id kAppDelegateDidTapStatusBarNotificationObserver;
|
2017-03-29 07:57:44 +00:00
|
|
|
|
|
|
|
// The animated view displayed at the table view bottom when paginating
|
|
|
|
UIView* footerSpinnerView;
|
2017-07-21 09:28:17 +00:00
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
// Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change.
|
|
|
|
id kThemeServiceDidChangeThemeNotificationObserver;
|
2015-12-18 17:25:39 +00:00
|
|
|
}
|
2015-12-16 15:29:34 +00:00
|
|
|
|
2021-12-02 14:25:45 +00:00
|
|
|
@property (nonatomic) AnalyticsScreenTimer *screenTimer;
|
|
|
|
|
2015-12-16 15:29:34 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DirectoryViewController
|
|
|
|
|
2017-01-03 13:40:23 +00:00
|
|
|
- (void)finalizeInit
|
2015-12-18 16:17:03 +00:00
|
|
|
{
|
2017-01-03 13:40:23 +00:00
|
|
|
[super finalizeInit];
|
2016-02-10 21:12:17 +00:00
|
|
|
|
|
|
|
// Setup `MXKViewControllerHandling` properties
|
|
|
|
self.enableBarTintColorStatusChange = NO;
|
|
|
|
self.rageShakeManager = [RageShakeManager sharedManager];
|
2021-12-02 14:25:45 +00:00
|
|
|
|
|
|
|
self.screenTimer = [[AnalyticsScreenTimer alloc] initWithScreen:AnalyticsScreenRoomDirectory];
|
2017-01-03 13:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
2015-12-18 16:17:03 +00:00
|
|
|
|
2021-09-28 05:40:01 +00:00
|
|
|
self.title = [VectorL10n directoryTitle];
|
2015-12-18 16:17:03 +00:00
|
|
|
|
|
|
|
self.tableView.delegate = self;
|
2016-01-05 17:18:07 +00:00
|
|
|
|
|
|
|
// Hide line separators of empty cells
|
|
|
|
self.tableView.tableFooterView = [[UIView alloc] init];
|
2017-07-21 09:28:17 +00:00
|
|
|
|
|
|
|
// Observe user interface theme change.
|
2019-01-11 09:32:56 +00:00
|
|
|
kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
2017-07-21 09:28:17 +00:00
|
|
|
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
|
|
|
|
}];
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)userInterfaceThemeDidChange
|
|
|
|
{
|
2019-01-11 10:45:27 +00:00
|
|
|
[ThemeService.shared.theme applyStyleOnNavigationBar:self.navigationController.navigationBar];
|
2018-11-29 16:31:41 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
self.activityIndicator.backgroundColor = ThemeService.shared.theme.overlayBackgroundColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
|
|
|
|
// Check the table view style to select its bg color.
|
2019-01-11 10:45:27 +00:00
|
|
|
self.tableView.backgroundColor = ((self.tableView.style == UITableViewStylePlain) ? ThemeService.shared.theme.backgroundColor : ThemeService.shared.theme.headerBackgroundColor);
|
2017-08-11 14:56:09 +00:00
|
|
|
self.view.backgroundColor = self.tableView.backgroundColor;
|
2019-02-18 11:53:13 +00:00
|
|
|
self.tableView.separatorColor = ThemeService.shared.theme.lineBreakColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
|
|
|
|
if (self.tableView.dataSource)
|
|
|
|
{
|
|
|
|
[self.tableView reloadData];
|
|
|
|
}
|
2020-04-08 10:58:12 +00:00
|
|
|
|
|
|
|
[self setNeedsStatusBarAppearanceUpdate];
|
2017-08-11 14:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (UIStatusBarStyle)preferredStatusBarStyle
|
|
|
|
{
|
2019-01-11 10:45:27 +00:00
|
|
|
return ThemeService.shared.theme.statusBarStyle;
|
2017-07-21 09:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)destroy
|
|
|
|
{
|
|
|
|
[super destroy];
|
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
if (kThemeServiceDidChangeThemeNotificationObserver)
|
2017-07-21 09:28:17 +00:00
|
|
|
{
|
2019-01-11 09:32:56 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:kThemeServiceDidChangeThemeNotificationObserver];
|
|
|
|
kThemeServiceDidChangeThemeNotificationObserver = nil;
|
2017-07-21 09:28:17 +00:00
|
|
|
}
|
2015-12-16 15:29:34 +00:00
|
|
|
}
|
|
|
|
|
2015-12-18 16:17:03 +00:00
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
2016-06-20 12:11:27 +00:00
|
|
|
|
|
|
|
// Observe kAppDelegateDidTapStatusBarNotificationObserver.
|
|
|
|
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
|
|
|
|
2021-09-01 09:44:15 +00:00
|
|
|
[self.tableView setContentOffset:CGPointMake(-self.tableView.adjustedContentInset.left, -self.tableView.adjustedContentInset.top) animated:YES];
|
2016-06-20 12:11:27 +00:00
|
|
|
|
|
|
|
}];
|
2015-12-18 16:17:03 +00:00
|
|
|
|
|
|
|
[self.tableView reloadData];
|
|
|
|
}
|
|
|
|
|
2015-12-22 16:23:59 +00:00
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewDidAppear:animated];
|
|
|
|
|
2017-03-28 15:26:50 +00:00
|
|
|
// Release the current selected item (room/contact...) except if the second view controller is still visible (see splitViewController.isCollapsed condition)
|
2017-03-27 12:20:54 +00:00
|
|
|
if (self.splitViewController && self.splitViewController.isCollapsed)
|
|
|
|
{
|
2017-03-28 15:26:50 +00:00
|
|
|
[[AppDelegate theDelegate].masterTabBarController releaseSelectedItem];
|
2017-03-27 12:20:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// In case of split view controller where the primary and secondary view controllers are displayed side-by-side onscreen,
|
|
|
|
// the selected room (if any) is highlighted.
|
|
|
|
[self refreshCurrentSelectedCell:YES];
|
|
|
|
}
|
2021-12-02 14:25:45 +00:00
|
|
|
|
|
|
|
[self.screenTimer start];
|
2015-12-22 16:23:59 +00:00
|
|
|
}
|
|
|
|
|
2016-06-20 12:11:27 +00:00
|
|
|
- (void)viewWillDisappear:(BOOL)animated
|
|
|
|
{
|
|
|
|
if (kAppDelegateDidTapStatusBarNotificationObserver)
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:kAppDelegateDidTapStatusBarNotificationObserver];
|
|
|
|
kAppDelegateDidTapStatusBarNotificationObserver = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
}
|
|
|
|
|
2021-12-02 14:25:45 +00:00
|
|
|
- (void)viewDidDisappear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewDidDisappear:animated];
|
|
|
|
[self.screenTimer stop];
|
|
|
|
}
|
|
|
|
|
2015-12-18 17:25:39 +00:00
|
|
|
- (void)displayWitDataSource:(PublicRoomsDirectoryDataSource *)dataSource2
|
2015-12-18 16:17:03 +00:00
|
|
|
{
|
|
|
|
// Let the data source provide cells
|
2015-12-18 17:25:39 +00:00
|
|
|
dataSource = dataSource2;
|
2015-12-18 16:17:03 +00:00
|
|
|
self.tableView.dataSource = dataSource;
|
2015-12-16 15:29:34 +00:00
|
|
|
}
|
|
|
|
|
2015-12-18 16:17:03 +00:00
|
|
|
#pragma mark - UITableViewDelegate
|
|
|
|
|
2017-08-11 14:56:09 +00:00
|
|
|
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
|
|
|
|
{
|
2019-01-11 10:45:27 +00:00
|
|
|
cell.backgroundColor = ThemeService.shared.theme.backgroundColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
|
|
|
|
// Update the selected background view
|
2019-01-11 10:45:27 +00:00
|
|
|
if (ThemeService.shared.theme.selectedBackgroundColor)
|
2017-08-11 14:56:09 +00:00
|
|
|
{
|
|
|
|
cell.selectedBackgroundView = [[UIView alloc] init];
|
2019-01-11 10:45:27 +00:00
|
|
|
cell.selectedBackgroundView.backgroundColor = ThemeService.shared.theme.selectedBackgroundColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tableView.style == UITableViewStylePlain)
|
|
|
|
{
|
|
|
|
cell.selectedBackgroundView = nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cell.selectedBackgroundView.backgroundColor = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-18 16:17:03 +00:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
return 72;
|
|
|
|
}
|
2015-12-18 17:25:39 +00:00
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2017-03-28 14:36:21 +00:00
|
|
|
MXPublicRoom *publicRoom = [dataSource roomAtIndexPath:indexPath];
|
2015-12-22 14:42:53 +00:00
|
|
|
|
2015-12-22 15:23:43 +00:00
|
|
|
// Check whether the user has already joined the selected public room
|
2021-11-03 10:18:27 +00:00
|
|
|
if ([dataSource.mxSession isJoinedOnRoom:publicRoom.roomId])
|
2015-12-22 15:23:43 +00:00
|
|
|
{
|
2016-06-21 20:06:32 +00:00
|
|
|
// Open the public room.
|
2021-10-20 16:50:00 +00:00
|
|
|
[self showRoomWithId:publicRoom.roomId inMatrixSession:dataSource.mxSession];
|
2015-12-22 15:23:43 +00:00
|
|
|
}
|
2017-03-27 12:20:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Preview the public room
|
|
|
|
if (publicRoom.worldReadable)
|
|
|
|
{
|
2021-09-01 12:29:52 +00:00
|
|
|
RoomPreviewData *roomPreviewData = [[RoomPreviewData alloc] initWithPublicRoom:publicRoom andSession:dataSource.mxSession];
|
2017-03-27 12:20:54 +00:00
|
|
|
|
|
|
|
[self startActivityIndicator];
|
|
|
|
|
|
|
|
// Try to get more information about the room before opening its preview
|
|
|
|
[roomPreviewData peekInRoom:^(BOOL succeeded) {
|
|
|
|
|
|
|
|
[self stopActivityIndicator];
|
|
|
|
|
2021-10-12 17:22:46 +00:00
|
|
|
[self showRoomPreviewWithData:roomPreviewData];
|
2017-03-27 12:20:54 +00:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RoomPreviewData *roomPreviewData = [[RoomPreviewData alloc] initWithPublicRoom:publicRoom andSession:dataSource.mxSession];
|
2021-10-12 17:22:46 +00:00
|
|
|
[self showRoomPreviewWithData:roomPreviewData];
|
2017-03-27 12:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-12-22 15:23:43 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 07:57:44 +00:00
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
|
|
|
{
|
|
|
|
// Trigger inconspicuous pagination when user scrolls down
|
|
|
|
if ((scrollView.contentSize.height - scrollView.contentOffset.y - scrollView.frame.size.height) < 300)
|
|
|
|
{
|
|
|
|
[self triggerPagination];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-22 15:23:43 +00:00
|
|
|
#pragma mark - Private methods
|
|
|
|
|
2021-10-20 16:50:00 +00:00
|
|
|
- (void)showRoomWithId:(NSString*)roomId inMatrixSession:(MXSession*)mxSession
|
2021-10-12 17:22:46 +00:00
|
|
|
{
|
2021-10-21 08:00:37 +00:00
|
|
|
ScreenPresentationParameters *presentationParameters = [[ScreenPresentationParameters alloc] initWithRestoreInitialDisplay:NO stackAboveVisibleViews:NO];
|
2021-10-20 06:31:51 +00:00
|
|
|
|
2021-10-21 09:40:18 +00:00
|
|
|
RoomNavigationParameters *parameters = [[RoomNavigationParameters alloc] initWithRoomId:roomId
|
|
|
|
eventId:nil
|
|
|
|
mxSession:mxSession
|
2022-01-25 20:59:19 +00:00
|
|
|
threadParameters:nil
|
2021-10-21 09:40:18 +00:00
|
|
|
presentationParameters:presentationParameters];
|
2021-10-12 17:22:46 +00:00
|
|
|
[[AppDelegate theDelegate] showRoomWithParameters:parameters];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showRoomPreviewWithData:(RoomPreviewData*)roomPreviewData
|
|
|
|
{
|
2021-10-21 08:00:37 +00:00
|
|
|
ScreenPresentationParameters *presentationParameters = [[ScreenPresentationParameters alloc] initWithRestoreInitialDisplay:NO stackAboveVisibleViews:NO];
|
2021-10-20 06:31:51 +00:00
|
|
|
|
2021-10-21 09:57:13 +00:00
|
|
|
RoomPreviewNavigationParameters *parameters = [[RoomPreviewNavigationParameters alloc] initWithPreviewData:roomPreviewData presentationParameters:presentationParameters];
|
2021-10-12 17:22:46 +00:00
|
|
|
[[AppDelegate theDelegate] showRoomPreviewWithParameters:parameters];
|
2015-12-18 17:25:39 +00:00
|
|
|
}
|
|
|
|
|
2015-12-22 16:23:59 +00:00
|
|
|
- (void)refreshCurrentSelectedCell:(BOOL)forceVisible
|
|
|
|
{
|
2017-03-27 12:20:54 +00:00
|
|
|
MasterTabBarController *masterTabBarController = [AppDelegate theDelegate].masterTabBarController;
|
|
|
|
|
|
|
|
// Update here the index of the current selected cell (if any) - Useful in landscape mode with split view controller.
|
|
|
|
NSIndexPath *currentSelectedCellIndexPath = nil;
|
2021-10-05 14:24:58 +00:00
|
|
|
if (masterTabBarController.selectedRoomId)
|
2017-03-27 12:20:54 +00:00
|
|
|
{
|
|
|
|
// Look for the rank of this selected room in displayed recents
|
|
|
|
currentSelectedCellIndexPath = [dataSource cellIndexPathWithRoomId:masterTabBarController.selectedRoomId andMatrixSession:masterTabBarController.selectedRoomSession];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentSelectedCellIndexPath)
|
|
|
|
{
|
|
|
|
// Select the right row
|
|
|
|
[self.tableView selectRowAtIndexPath:currentSelectedCellIndexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
|
|
|
|
|
|
|
|
if (forceVisible)
|
|
|
|
{
|
|
|
|
// Scroll table view to make the selected row appear at second position
|
|
|
|
NSInteger topCellIndexPathRow = currentSelectedCellIndexPath.row ? currentSelectedCellIndexPath.row - 1: currentSelectedCellIndexPath.row;
|
|
|
|
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:topCellIndexPathRow inSection:currentSelectedCellIndexPath.section];
|
|
|
|
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
|
|
|
|
if (indexPath)
|
|
|
|
{
|
|
|
|
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
|
|
|
|
}
|
|
|
|
}
|
2015-12-22 16:23:59 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 07:57:44 +00:00
|
|
|
- (void)triggerPagination
|
|
|
|
{
|
|
|
|
if (dataSource.hasReachedPaginationEnd || footerSpinnerView)
|
|
|
|
{
|
|
|
|
// We got all public rooms or we are already paginating
|
|
|
|
// Do nothing
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self addSpinnerFooterView];
|
|
|
|
|
2017-06-09 10:09:20 +00:00
|
|
|
__weak __typeof(self) weakSelf = self;
|
|
|
|
|
2017-03-29 07:57:44 +00:00
|
|
|
[dataSource paginate:^(NSUInteger roomsAdded) {
|
|
|
|
|
2017-06-09 10:09:20 +00:00
|
|
|
if (weakSelf)
|
2017-03-29 07:57:44 +00:00
|
|
|
{
|
2017-06-09 10:09:20 +00:00
|
|
|
__strong __typeof(weakSelf) self = weakSelf;
|
2017-03-29 07:57:44 +00:00
|
|
|
|
2017-06-09 10:09:20 +00:00
|
|
|
if (roomsAdded)
|
2017-03-29 07:57:44 +00:00
|
|
|
{
|
2017-06-26 13:33:45 +00:00
|
|
|
[self.tableView reloadData];
|
2017-06-09 10:09:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[self removeSpinnerFooterView];
|
|
|
|
}
|
2017-03-29 07:57:44 +00:00
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
2017-06-09 10:09:20 +00:00
|
|
|
if (weakSelf)
|
|
|
|
{
|
|
|
|
__strong __typeof(weakSelf) self = weakSelf;
|
|
|
|
|
|
|
|
[self removeSpinnerFooterView];
|
|
|
|
}
|
2017-03-29 07:57:44 +00:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addSpinnerFooterView
|
|
|
|
{
|
|
|
|
if (!footerSpinnerView)
|
|
|
|
{
|
|
|
|
UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
|
|
|
spinner.transform = CGAffineTransformMakeScale(0.75f, 0.75f);
|
|
|
|
CGRect frame = spinner.frame;
|
|
|
|
frame.size.height = 80; // 80 * 0.75 = 60
|
|
|
|
spinner.bounds = frame;
|
|
|
|
|
|
|
|
spinner.color = [UIColor darkGrayColor];
|
|
|
|
spinner.hidesWhenStopped = NO;
|
|
|
|
spinner.backgroundColor = [UIColor clearColor];
|
|
|
|
[spinner startAnimating];
|
|
|
|
|
|
|
|
// No need to manage constraints here, iOS defines them
|
|
|
|
self.tableView.tableFooterView = footerSpinnerView = spinner;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)removeSpinnerFooterView
|
|
|
|
{
|
|
|
|
if (footerSpinnerView)
|
|
|
|
{
|
|
|
|
footerSpinnerView = nil;
|
|
|
|
|
|
|
|
// Hide line separators of empty cells
|
|
|
|
self.tableView.tableFooterView = [[UIView alloc] init];;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-16 15:29:34 +00:00
|
|
|
@end
|