2015-12-09 09:12:08 +00:00
|
|
|
|
/*
|
|
|
|
|
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 "HomeViewController.h"
|
|
|
|
|
|
|
|
|
|
#import "RecentsDataSource.h"
|
|
|
|
|
#import "RecentsViewController.h"
|
|
|
|
|
|
2016-03-04 08:16:57 +00:00
|
|
|
|
#import "RoomDataSource.h"
|
2015-12-09 13:39:37 +00:00
|
|
|
|
#import "RoomViewController.h"
|
2016-06-21 19:47:20 +00:00
|
|
|
|
|
2015-12-18 16:17:03 +00:00
|
|
|
|
#import "DirectoryViewController.h"
|
2016-06-21 19:47:20 +00:00
|
|
|
|
#import "ContactDetailsViewController.h"
|
|
|
|
|
#import "SettingsViewController.h"
|
2015-12-09 13:39:37 +00:00
|
|
|
|
|
2015-12-30 14:15:08 +00:00
|
|
|
|
#import "MXKSearchDataSource.h"
|
2015-12-30 15:23:25 +00:00
|
|
|
|
#import "HomeSearchViewController.h"
|
2015-12-30 14:15:08 +00:00
|
|
|
|
|
2016-03-17 10:32:18 +00:00
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
|
|
2016-06-21 19:47:20 +00:00
|
|
|
|
#import "GBDeviceInfo_iOS.h"
|
|
|
|
|
|
2015-12-09 09:12:08 +00:00
|
|
|
|
@interface HomeViewController ()
|
|
|
|
|
{
|
|
|
|
|
RecentsViewController *recentsViewController;
|
|
|
|
|
RecentsDataSource *recentsDataSource;
|
|
|
|
|
|
2016-03-04 08:16:57 +00:00
|
|
|
|
HomeSearchViewController *searchViewController;
|
2015-12-30 14:15:08 +00:00
|
|
|
|
MXKSearchDataSource *searchDataSource;
|
2016-06-20 12:16:13 +00:00
|
|
|
|
|
|
|
|
|
ContactPickerViewController *contactsViewController;
|
2016-06-21 19:47:20 +00:00
|
|
|
|
MXKContact *selectedContact;
|
2015-12-30 14:15:08 +00:00
|
|
|
|
|
2015-12-09 11:28:25 +00:00
|
|
|
|
// Display a gradient view above the screen
|
|
|
|
|
CAGradientLayer* tableViewMaskLayer;
|
|
|
|
|
|
|
|
|
|
// Display a button to a new room
|
|
|
|
|
UIImageView* createNewRoomImageView;
|
2016-03-17 10:32:18 +00:00
|
|
|
|
|
|
|
|
|
MXHTTPOperation *roomCreationRequest;
|
2016-04-21 14:19:16 +00:00
|
|
|
|
|
2016-04-25 09:29:47 +00:00
|
|
|
|
// Tell whether the authentication screen is preparing.
|
|
|
|
|
BOOL isAuthViewControllerPreparing;
|
|
|
|
|
|
2016-04-21 15:49:52 +00:00
|
|
|
|
// Observer that checks when the Authentification view controller has gone.
|
2016-04-21 14:19:16 +00:00
|
|
|
|
id authViewControllerObserver;
|
2016-04-21 15:49:52 +00:00
|
|
|
|
|
2016-04-21 16:29:14 +00:00
|
|
|
|
// The parameters to pass to the Authentification view controller.
|
2016-04-22 16:42:14 +00:00
|
|
|
|
NSDictionary *authViewControllerRegistrationParameters;
|
2016-04-22 13:17:58 +00:00
|
|
|
|
|
|
|
|
|
// Current alert (if any).
|
|
|
|
|
MXKAlert *currentAlert;
|
2015-12-09 09:12:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-16 16:06:05 +00:00
|
|
|
|
@property(nonatomic,getter=isHidden) BOOL hidden;
|
|
|
|
|
|
2015-12-09 09:12:08 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation HomeViewController
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
|
{
|
|
|
|
|
// Set up the SegmentedVC tabs before calling [super viewDidLoad]
|
|
|
|
|
NSMutableArray* viewControllers = [[NSMutableArray alloc] init];
|
|
|
|
|
NSMutableArray* titles = [[NSMutableArray alloc] init];
|
|
|
|
|
|
2016-01-14 14:23:58 +00:00
|
|
|
|
[titles addObject: NSLocalizedStringFromTable(@"search_rooms", @"Vector", nil)];
|
2015-12-09 09:12:08 +00:00
|
|
|
|
recentsViewController = [RecentsViewController recentListViewController];
|
2015-12-09 13:39:37 +00:00
|
|
|
|
recentsViewController.delegate = self;
|
2015-12-09 09:12:08 +00:00
|
|
|
|
[viewControllers addObject:recentsViewController];
|
|
|
|
|
|
2016-01-14 14:23:58 +00:00
|
|
|
|
[titles addObject: NSLocalizedStringFromTable(@"search_messages", @"Vector", nil)];
|
2015-12-30 15:23:25 +00:00
|
|
|
|
searchViewController = [HomeSearchViewController searchViewController];
|
2015-12-30 14:15:08 +00:00
|
|
|
|
[viewControllers addObject:searchViewController];
|
2015-12-09 09:12:08 +00:00
|
|
|
|
|
2016-06-20 12:16:13 +00:00
|
|
|
|
// Add search People tab
|
|
|
|
|
[titles addObject: NSLocalizedStringFromTable(@"search_people", @"Vector", nil)];
|
|
|
|
|
contactsViewController = [ContactPickerViewController contactPickerViewController];
|
2016-06-21 19:47:20 +00:00
|
|
|
|
contactsViewController.delegate = self;
|
2016-06-20 12:16:13 +00:00
|
|
|
|
[viewControllers addObject:contactsViewController];
|
2015-12-09 09:12:08 +00:00
|
|
|
|
|
|
|
|
|
[self initWithTitles:titles viewControllers:viewControllers defaultSelected:0];
|
|
|
|
|
|
|
|
|
|
[super viewDidLoad];
|
2016-02-10 21:12:17 +00:00
|
|
|
|
|
|
|
|
|
// The navigation bar tint color and the rageShake Manager are handled by super (see SegmentedViewController)
|
2015-12-09 09:12:08 +00:00
|
|
|
|
|
2016-01-14 14:23:58 +00:00
|
|
|
|
self.navigationItem.title = NSLocalizedStringFromTable(@"title_recents", @"Vector", nil);
|
2016-01-05 15:59:22 +00:00
|
|
|
|
|
|
|
|
|
// Add the Vector background image when search bar is empty
|
|
|
|
|
[self addBackgroundImageViewToView:self.view];
|
2016-02-10 23:02:56 +00:00
|
|
|
|
|
2016-06-16 16:06:05 +00:00
|
|
|
|
// Add room creation button programatically
|
|
|
|
|
[self addRoomCreationButton];
|
|
|
|
|
|
2016-06-14 09:10:37 +00:00
|
|
|
|
// Initialize here the data sources if a matrix session has been already set.
|
|
|
|
|
[self initializeDataSources];
|
2015-12-09 09:12:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 13:39:37 +00:00
|
|
|
|
- (void)dealloc
|
|
|
|
|
{
|
|
|
|
|
[self closeSelectedRoom];
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-17 10:32:18 +00:00
|
|
|
|
- (void)destroy
|
|
|
|
|
{
|
|
|
|
|
[super destroy];
|
2016-04-21 14:19:16 +00:00
|
|
|
|
|
2016-04-22 13:17:58 +00:00
|
|
|
|
if (currentAlert)
|
|
|
|
|
{
|
|
|
|
|
[currentAlert dismiss:NO];
|
|
|
|
|
currentAlert = nil;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-21 14:19:16 +00:00
|
|
|
|
if (authViewControllerObserver)
|
|
|
|
|
{
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:authViewControllerObserver];
|
|
|
|
|
authViewControllerObserver = nil;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-17 10:32:18 +00:00
|
|
|
|
if (roomCreationRequest)
|
|
|
|
|
{
|
|
|
|
|
[roomCreationRequest cancel];
|
|
|
|
|
roomCreationRequest = nil;
|
|
|
|
|
}
|
2016-06-16 16:06:05 +00:00
|
|
|
|
|
|
|
|
|
if (createNewRoomImageView)
|
|
|
|
|
{
|
|
|
|
|
[createNewRoomImageView removeFromSuperview];
|
|
|
|
|
createNewRoomImageView = nil;
|
|
|
|
|
tableViewMaskLayer = nil;
|
|
|
|
|
}
|
2016-03-17 10:32:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 09:12:08 +00:00
|
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
|
{
|
|
|
|
|
[super viewWillAppear:animated];
|
2016-06-16 16:06:05 +00:00
|
|
|
|
|
|
|
|
|
// Show the home view controller content only when a user is logged in.
|
|
|
|
|
self.hidden = ([MXKAccountManager sharedManager].accounts.count == 0);
|
2015-12-09 09:12:08 +00:00
|
|
|
|
|
2015-12-09 09:48:40 +00:00
|
|
|
|
// Let's child display the loading not the home view controller
|
2015-12-09 13:39:37 +00:00
|
|
|
|
if (self.activityIndicator)
|
|
|
|
|
{
|
|
|
|
|
[self.activityIndicator stopAnimating];
|
|
|
|
|
self.activityIndicator = nil;
|
|
|
|
|
}
|
2016-06-16 08:50:18 +00:00
|
|
|
|
|
|
|
|
|
// Refresh the search results if a search in in progress
|
|
|
|
|
if (!self.searchBarHidden)
|
|
|
|
|
{
|
|
|
|
|
[self updateSearch];
|
|
|
|
|
}
|
2015-12-09 09:12:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 13:39:37 +00:00
|
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
|
{
|
|
|
|
|
[super viewDidAppear:animated];
|
2016-04-29 08:29:08 +00:00
|
|
|
|
|
|
|
|
|
// Check whether we're not logged in
|
|
|
|
|
if (![MXKAccountManager sharedManager].accounts.count)
|
2015-12-09 13:39:37 +00:00
|
|
|
|
{
|
2016-04-29 08:29:08 +00:00
|
|
|
|
[self showAuthenticationScreen];
|
2015-12-09 13:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-06-03 14:07:34 +00:00
|
|
|
|
// Check whether the user has been already prompted to send crash reports.
|
|
|
|
|
// (Check whether 'enableCrashReport' flag has been set once)
|
|
|
|
|
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"enableCrashReport"])
|
|
|
|
|
{
|
|
|
|
|
[self promptUserBeforeUsingGoogleAnalytics];
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-29 08:29:08 +00:00
|
|
|
|
// Release the current selected room (if any) except if the Room ViewController is still visible (see splitViewController.isCollapsed condition)
|
|
|
|
|
if (!self.splitViewController || self.splitViewController.isCollapsed)
|
|
|
|
|
{
|
|
|
|
|
// Release the current selected room (if any).
|
|
|
|
|
[self closeSelectedRoom];
|
|
|
|
|
}
|
|
|
|
|
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 refreshCurrentSelectedCellInChild:YES];
|
|
|
|
|
}
|
2015-12-09 13:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 13:31:52 +00:00
|
|
|
|
- (void)viewDidLayoutSubviews
|
2015-12-09 09:12:08 +00:00
|
|
|
|
{
|
2015-12-09 11:28:25 +00:00
|
|
|
|
[super viewDidLayoutSubviews];
|
|
|
|
|
|
|
|
|
|
// sanity check
|
|
|
|
|
if (tableViewMaskLayer)
|
|
|
|
|
{
|
|
|
|
|
CGRect currentBounds = tableViewMaskLayer.bounds;
|
|
|
|
|
CGRect newBounds = CGRectIntegral(self.view.frame);
|
|
|
|
|
|
|
|
|
|
// check if there is an update
|
|
|
|
|
if (!CGSizeEqualToSize(currentBounds.size, newBounds.size))
|
|
|
|
|
{
|
|
|
|
|
newBounds.origin = CGPointZero;
|
|
|
|
|
tableViewMaskLayer.bounds = newBounds;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-09 09:12:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 15:48:43 +00:00
|
|
|
|
#pragma mark -
|
|
|
|
|
|
2016-04-05 13:31:52 +00:00
|
|
|
|
- (void)showAuthenticationScreen
|
|
|
|
|
{
|
2016-04-25 09:29:47 +00:00
|
|
|
|
// Check whether an authentication screen is not already shown or preparing
|
|
|
|
|
if (!self.authViewController && !isAuthViewControllerPreparing)
|
|
|
|
|
{
|
|
|
|
|
isAuthViewControllerPreparing = YES;
|
|
|
|
|
|
|
|
|
|
[[AppDelegate theDelegate] restoreInitialDisplay:^{
|
|
|
|
|
|
|
|
|
|
[self performSegueWithIdentifier:@"showAuth" sender:self];
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
}
|
2016-04-21 15:49:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-22 16:42:14 +00:00
|
|
|
|
- (void)showAuthenticationScreenWithRegistrationParameters:(NSDictionary *)parameters
|
2016-04-21 15:49:52 +00:00
|
|
|
|
{
|
2016-04-21 16:29:14 +00:00
|
|
|
|
if (self.authViewController)
|
|
|
|
|
{
|
2016-04-22 16:42:14 +00:00
|
|
|
|
NSLog(@"[HomeViewController] Universal link: Forward registration parameter to the existing AuthViewController");
|
|
|
|
|
self.authViewController.externalRegistrationParameters = parameters;
|
2016-04-21 16:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-04-22 16:42:14 +00:00
|
|
|
|
NSLog(@"[HomeViewController] Universal link: Logout current sessions and open AuthViewController to complete the registration");
|
2016-04-21 15:49:52 +00:00
|
|
|
|
|
2016-04-22 06:35:15 +00:00
|
|
|
|
// Keep a ref on the params
|
2016-04-22 16:42:14 +00:00
|
|
|
|
authViewControllerRegistrationParameters = parameters;
|
2016-04-21 15:49:52 +00:00
|
|
|
|
|
2016-04-22 06:35:15 +00:00
|
|
|
|
// And do a logout out. It will then display AuthViewController
|
|
|
|
|
[[AppDelegate theDelegate] logout];
|
2016-04-21 16:29:14 +00:00
|
|
|
|
}
|
2016-04-05 13:31:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 09:10:37 +00:00
|
|
|
|
- (void)initializeDataSources
|
2015-12-09 17:12:42 +00:00
|
|
|
|
{
|
2016-06-14 09:10:37 +00:00
|
|
|
|
MXSession *mainSession = self.mainSession;
|
2015-12-30 14:15:08 +00:00
|
|
|
|
|
2016-06-14 09:10:37 +00:00
|
|
|
|
if (mainSession)
|
|
|
|
|
{
|
|
|
|
|
// Init the recents data source
|
|
|
|
|
recentsDataSource = [[RecentsDataSource alloc] initWithMatrixSession:mainSession];
|
|
|
|
|
[recentsViewController displayList:recentsDataSource fromHomeViewController:self];
|
|
|
|
|
|
|
|
|
|
// Init the search for messages
|
|
|
|
|
searchDataSource = [[MXKSearchDataSource alloc] initWithMatrixSession:mainSession];
|
|
|
|
|
[searchViewController displaySearch:searchDataSource];
|
|
|
|
|
|
|
|
|
|
// Check whether there are others sessions
|
|
|
|
|
NSArray* mxSessions = self.mxSessions;
|
|
|
|
|
if (mxSessions.count > 1)
|
|
|
|
|
{
|
|
|
|
|
for (MXSession *mxSession in mxSessions)
|
|
|
|
|
{
|
|
|
|
|
if (mxSession != mainSession)
|
|
|
|
|
{
|
|
|
|
|
// Add the session to the recents data source
|
|
|
|
|
[recentsDataSource addMatrixSession:mxSession];
|
|
|
|
|
|
|
|
|
|
// FIXME: Update searchDataSource
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Do not go to search mode when first opening the home
|
|
|
|
|
[self hideSearch:NO];
|
|
|
|
|
}
|
2015-12-09 17:12:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)addMatrixSession:(MXSession *)mxSession
|
2015-12-09 15:48:43 +00:00
|
|
|
|
{
|
2016-06-14 09:10:37 +00:00
|
|
|
|
// Check whether the controller's view is loaded into memory.
|
|
|
|
|
if (recentsViewController)
|
2015-12-09 17:12:42 +00:00
|
|
|
|
{
|
2016-06-14 09:10:37 +00:00
|
|
|
|
// Check whether the data sources have been initialized.
|
|
|
|
|
if (!recentsDataSource)
|
|
|
|
|
{
|
|
|
|
|
// Add first the session. The updated sessions list will be used during data sources initialization.
|
|
|
|
|
[super addMatrixSession:mxSession];
|
|
|
|
|
|
|
|
|
|
// Prepare data sources and return
|
|
|
|
|
[self initializeDataSources];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Add the session to the existing recents data source
|
|
|
|
|
[recentsDataSource addMatrixSession:mxSession];
|
|
|
|
|
|
|
|
|
|
// FIXME: Update searchDataSource
|
|
|
|
|
}
|
2015-12-09 17:12:42 +00:00
|
|
|
|
}
|
2016-04-22 22:32:17 +00:00
|
|
|
|
|
|
|
|
|
[super addMatrixSession:mxSession];
|
2015-12-09 17:12:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)removeMatrixSession:(MXSession *)mxSession
|
|
|
|
|
{
|
|
|
|
|
[recentsDataSource removeMatrixSession:mxSession];
|
|
|
|
|
|
|
|
|
|
// Check whether there are others sessions
|
2016-06-21 19:47:20 +00:00
|
|
|
|
if (!recentsDataSource.mxSessions.count)
|
2015-12-09 17:12:42 +00:00
|
|
|
|
{
|
|
|
|
|
[recentsViewController displayList:nil];
|
2016-06-21 19:47:20 +00:00
|
|
|
|
[recentsDataSource destroy];
|
|
|
|
|
recentsDataSource = nil;
|
2015-12-09 17:12:42 +00:00
|
|
|
|
}
|
2016-04-22 22:32:17 +00:00
|
|
|
|
|
2016-06-21 19:47:20 +00:00
|
|
|
|
// FIXME: Handle correctly searchDataSource
|
|
|
|
|
|
2016-04-22 22:32:17 +00:00
|
|
|
|
[super removeMatrixSession:mxSession];
|
2015-12-09 15:48:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-07 15:36:18 +00:00
|
|
|
|
- (void)selectRoomWithId:(NSString*)roomId andEventId:(NSString*)eventId inMatrixSession:(MXSession*)matrixSession
|
2015-12-09 15:48:43 +00:00
|
|
|
|
{
|
2015-12-22 17:22:05 +00:00
|
|
|
|
// Force hiding the keyboard
|
2015-12-28 08:39:17 +00:00
|
|
|
|
[self.searchBar resignFirstResponder];
|
2015-12-22 17:22:05 +00:00
|
|
|
|
|
2015-12-09 15:48:43 +00:00
|
|
|
|
if (_selectedRoomId && [_selectedRoomId isEqualToString:roomId]
|
2016-04-07 15:36:18 +00:00
|
|
|
|
&& _selectedEventId && [_selectedEventId isEqualToString:eventId]
|
2015-12-09 15:48:43 +00:00
|
|
|
|
&& _selectedRoomSession && _selectedRoomSession == matrixSession)
|
|
|
|
|
{
|
|
|
|
|
// Nothing to do
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_selectedRoomId = roomId;
|
2016-04-07 15:36:18 +00:00
|
|
|
|
_selectedEventId = eventId;
|
2015-12-09 15:48:43 +00:00
|
|
|
|
_selectedRoomSession = matrixSession;
|
|
|
|
|
|
|
|
|
|
if (roomId && matrixSession)
|
|
|
|
|
{
|
|
|
|
|
[self performSegueWithIdentifier:@"showDetails" sender:self];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[self closeSelectedRoom];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-15 07:43:56 +00:00
|
|
|
|
- (void)showRoomPreview:(RoomPreviewData *)roomPreviewData
|
|
|
|
|
{
|
|
|
|
|
// Force hiding the keyboard
|
|
|
|
|
[self.searchBar resignFirstResponder];
|
|
|
|
|
|
|
|
|
|
_selectedRoomPreviewData = roomPreviewData;
|
|
|
|
|
_selectedRoomId = roomPreviewData.roomId;
|
|
|
|
|
_selectedRoomSession = roomPreviewData.mxSession;
|
|
|
|
|
|
|
|
|
|
[self performSegueWithIdentifier:@"showDetails" sender:self];
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 15:48:43 +00:00
|
|
|
|
- (void)closeSelectedRoom
|
|
|
|
|
{
|
|
|
|
|
_selectedRoomId = nil;
|
2016-04-07 15:36:18 +00:00
|
|
|
|
_selectedEventId = nil;
|
2015-12-09 15:48:43 +00:00
|
|
|
|
_selectedRoomSession = nil;
|
|
|
|
|
|
|
|
|
|
if (_currentRoomViewController)
|
|
|
|
|
{
|
2016-06-10 15:15:42 +00:00
|
|
|
|
// If the displayed data is not a preview, let the manager release the room data source
|
|
|
|
|
// (except if the view controller has the room data source ownership).
|
|
|
|
|
if (!_currentRoomViewController.roomPreviewData && _currentRoomViewController.roomDataSource && !_currentRoomViewController.hasRoomDataSourceOwnership)
|
2015-12-09 15:48:43 +00:00
|
|
|
|
{
|
|
|
|
|
MXSession *mxSession = _currentRoomViewController.roomDataSource.mxSession;
|
|
|
|
|
MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:mxSession];
|
2016-06-08 15:01:01 +00:00
|
|
|
|
|
2016-06-08 16:29:35 +00:00
|
|
|
|
// Let the manager release live room data sources where the user is in
|
2016-06-09 09:52:39 +00:00
|
|
|
|
[roomDataSourceManager closeRoomDataSource:_currentRoomViewController.roomDataSource forceClose:NO];
|
2015-12-09 15:48:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[_currentRoomViewController destroy];
|
|
|
|
|
_currentRoomViewController = nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-18 16:17:03 +00:00
|
|
|
|
- (void)showPublicRoomsDirectory
|
|
|
|
|
{
|
2015-12-23 10:21:12 +00:00
|
|
|
|
// Force hiding the keyboard
|
2015-12-28 08:39:17 +00:00
|
|
|
|
[self.searchBar resignFirstResponder];
|
2015-12-23 10:21:12 +00:00
|
|
|
|
|
2015-12-18 16:17:03 +00:00
|
|
|
|
[self performSegueWithIdentifier:@"showDirectory" sender:self];
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-05 15:59:22 +00:00
|
|
|
|
#pragma mark - Override MXKViewController
|
|
|
|
|
|
|
|
|
|
- (void)setKeyboardHeight:(CGFloat)keyboardHeight
|
|
|
|
|
{
|
|
|
|
|
[self setKeyboardHeightForBackgroundImage:keyboardHeight];
|
|
|
|
|
|
|
|
|
|
[super setKeyboardHeight:keyboardHeight];
|
2016-05-30 14:11:24 +00:00
|
|
|
|
|
|
|
|
|
[self checkAndShowBackgroundImage];
|
2016-01-05 15:59:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 13:18:24 +00:00
|
|
|
|
- (void)startActivityIndicator
|
|
|
|
|
{
|
2016-04-19 15:15:24 +00:00
|
|
|
|
// Redirect the operation to the currently displayed VC
|
|
|
|
|
// It is a MXKViewController or a MXKTableViewController. So it supports startActivityIndicator
|
|
|
|
|
[self.selectedViewController performSelector:@selector(startActivityIndicator)];
|
2016-04-19 13:18:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)stopActivityIndicator
|
|
|
|
|
{
|
2016-04-19 15:15:24 +00:00
|
|
|
|
// The selected view controller mwy have changed since the call of [self startActivityIndicator]
|
|
|
|
|
// So, stop the activity indicator for all children
|
|
|
|
|
for (UIViewController *viewController in self.viewControllers)
|
|
|
|
|
{
|
|
|
|
|
[viewController performSelector:@selector(stopActivityIndicator)];
|
|
|
|
|
}
|
2016-04-19 13:18:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-05 16:30:30 +00:00
|
|
|
|
#pragma mark - Override UIViewController+VectorSearch
|
|
|
|
|
|
|
|
|
|
- (void)setKeyboardHeightForBackgroundImage:(CGFloat)keyboardHeight
|
|
|
|
|
{
|
|
|
|
|
[super setKeyboardHeightForBackgroundImage:keyboardHeight];
|
|
|
|
|
|
|
|
|
|
if (keyboardHeight > 0)
|
|
|
|
|
{
|
|
|
|
|
[self checkAndShowBackgroundImage];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-30 14:11:24 +00:00
|
|
|
|
// Check conditions before displaying the background
|
2016-01-05 16:30:30 +00:00
|
|
|
|
- (void)checkAndShowBackgroundImage
|
|
|
|
|
{
|
2016-05-30 14:11:24 +00:00
|
|
|
|
// Note: This background is hidden when keyboard is dismissed.
|
|
|
|
|
// The other conditions depend on the current selected view controller.
|
|
|
|
|
if (self.selectedViewController == recentsViewController)
|
|
|
|
|
{
|
2016-06-03 08:28:46 +00:00
|
|
|
|
self.backgroundImageView.hidden = (!recentsDataSource.hideRecents || !recentsDataSource.hidePublicRoomsDirectory || (self.keyboardHeight == 0));
|
2016-05-30 14:11:24 +00:00
|
|
|
|
}
|
|
|
|
|
else if (self.selectedViewController == searchViewController)
|
2016-01-05 16:30:30 +00:00
|
|
|
|
{
|
2016-06-20 12:16:13 +00:00
|
|
|
|
self.backgroundImageView.hidden = ((searchDataSource.serverCount != 0) || !searchViewController.noResultsLabel.isHidden || (self.keyboardHeight == 0));
|
|
|
|
|
}
|
|
|
|
|
else if (self.selectedViewController == contactsViewController)
|
|
|
|
|
{
|
|
|
|
|
self.backgroundImageView.hidden = (([contactsViewController.contactsTableView numberOfRowsInSection:0] != 0) || !contactsViewController.noResultsLabel.isHidden || (self.keyboardHeight == 0));
|
2016-01-05 16:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-05-30 14:11:24 +00:00
|
|
|
|
self.backgroundImageView.hidden = (self.keyboardHeight == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!self.backgroundImageView.hidden)
|
|
|
|
|
{
|
|
|
|
|
// Check whether there is enough space to display this background
|
|
|
|
|
// For example, in landscape with the iPhone 5 & 6 screen size, the backgroundImageView must be hidden.
|
|
|
|
|
if ((self.selectedViewController.view.frame.size.height - self.backgroundImageViewBottomConstraint.constant) < self.backgroundImageView.frame.size.height)
|
|
|
|
|
{
|
|
|
|
|
self.backgroundImageView.hidden = YES;
|
|
|
|
|
}
|
2016-01-05 16:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-30 14:15:08 +00:00
|
|
|
|
#pragma mark - Override SegmentedViewController
|
|
|
|
|
|
|
|
|
|
- (void)setSelectedIndex:(NSUInteger)selectedIndex
|
|
|
|
|
{
|
|
|
|
|
[super setSelectedIndex:selectedIndex];
|
|
|
|
|
|
2015-12-30 16:28:41 +00:00
|
|
|
|
if (!self.searchBarHidden)
|
|
|
|
|
{
|
|
|
|
|
[self updateSearch];
|
|
|
|
|
}
|
2015-12-30 14:15:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 15:48:43 +00:00
|
|
|
|
#pragma mark - Internal methods
|
|
|
|
|
|
2016-06-16 16:06:05 +00:00
|
|
|
|
- (void)addRoomCreationButton
|
|
|
|
|
{
|
|
|
|
|
// Add blur mask programatically
|
|
|
|
|
tableViewMaskLayer = [CAGradientLayer layer];
|
|
|
|
|
|
|
|
|
|
CGColorRef opaqueWhiteColor = [UIColor colorWithWhite:1.0 alpha:1.0].CGColor;
|
|
|
|
|
CGColorRef transparentWhiteColor = [UIColor colorWithWhite:1.0 alpha:0].CGColor;
|
|
|
|
|
|
|
|
|
|
tableViewMaskLayer.colors = [NSArray arrayWithObjects:(__bridge id)transparentWhiteColor, (__bridge id)transparentWhiteColor, (__bridge id)opaqueWhiteColor, nil];
|
|
|
|
|
|
|
|
|
|
// display a gradient to the rencents bottom (20% of the bottom of the screen)
|
|
|
|
|
tableViewMaskLayer.locations = [NSArray arrayWithObjects:
|
|
|
|
|
[NSNumber numberWithFloat:0],
|
|
|
|
|
[NSNumber numberWithFloat:0.85],
|
|
|
|
|
[NSNumber numberWithFloat:1.0], nil];
|
|
|
|
|
|
|
|
|
|
tableViewMaskLayer.bounds = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
|
|
|
|
|
tableViewMaskLayer.anchorPoint = CGPointZero;
|
|
|
|
|
|
|
|
|
|
// CAConstraint is not supported on IOS.
|
|
|
|
|
// it seems only being supported on Mac OS.
|
|
|
|
|
// so viewDidLayoutSubviews will refresh the layout bounds.
|
|
|
|
|
[self.view.layer addSublayer:tableViewMaskLayer];
|
|
|
|
|
|
|
|
|
|
// Add room create button
|
|
|
|
|
createNewRoomImageView = [[UIImageView alloc] init];
|
|
|
|
|
[createNewRoomImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
|
|
|
|
|
[self.view addSubview:createNewRoomImageView];
|
|
|
|
|
|
|
|
|
|
createNewRoomImageView.backgroundColor = [UIColor clearColor];
|
|
|
|
|
createNewRoomImageView.contentMode = UIViewContentModeCenter;
|
|
|
|
|
createNewRoomImageView.image = [UIImage imageNamed:@"create_room"];
|
|
|
|
|
|
|
|
|
|
CGFloat side = 78.0f;
|
|
|
|
|
NSLayoutConstraint* widthConstraint = [NSLayoutConstraint constraintWithItem:createNewRoomImageView
|
|
|
|
|
attribute:NSLayoutAttributeWidth
|
|
|
|
|
relatedBy:NSLayoutRelationEqual
|
|
|
|
|
toItem:nil
|
|
|
|
|
attribute:NSLayoutAttributeNotAnAttribute
|
|
|
|
|
multiplier:1
|
|
|
|
|
constant:side];
|
|
|
|
|
|
|
|
|
|
NSLayoutConstraint* heightConstraint = [NSLayoutConstraint constraintWithItem:createNewRoomImageView
|
|
|
|
|
attribute:NSLayoutAttributeHeight
|
|
|
|
|
relatedBy:NSLayoutRelationEqual
|
|
|
|
|
toItem:nil
|
|
|
|
|
attribute:NSLayoutAttributeNotAnAttribute
|
|
|
|
|
multiplier:1
|
|
|
|
|
constant:side];
|
|
|
|
|
|
|
|
|
|
NSLayoutConstraint* centerXConstraint = [NSLayoutConstraint constraintWithItem:createNewRoomImageView
|
|
|
|
|
attribute:NSLayoutAttributeCenterX
|
|
|
|
|
relatedBy:NSLayoutRelationEqual
|
|
|
|
|
toItem:self.view
|
|
|
|
|
attribute:NSLayoutAttributeCenterX
|
|
|
|
|
multiplier:1
|
|
|
|
|
constant:0];
|
|
|
|
|
|
|
|
|
|
NSLayoutConstraint* bottomConstraint = [NSLayoutConstraint constraintWithItem:self.view
|
|
|
|
|
attribute:NSLayoutAttributeBottom
|
|
|
|
|
relatedBy:NSLayoutRelationEqual
|
|
|
|
|
toItem:createNewRoomImageView
|
|
|
|
|
attribute:NSLayoutAttributeBottom
|
|
|
|
|
multiplier:1
|
|
|
|
|
constant:9];
|
|
|
|
|
|
|
|
|
|
// Available on iOS 8 and later
|
|
|
|
|
[NSLayoutConstraint activateConstraints:@[widthConstraint, heightConstraint, centerXConstraint, bottomConstraint]];
|
|
|
|
|
|
|
|
|
|
createNewRoomImageView.userInteractionEnabled = YES;
|
|
|
|
|
|
|
|
|
|
// Handle tap gesture
|
|
|
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onNewRoomPressed)];
|
|
|
|
|
[tap setNumberOfTouchesRequired:1];
|
|
|
|
|
[tap setNumberOfTapsRequired:1];
|
|
|
|
|
[tap setDelegate:self];
|
|
|
|
|
[createNewRoomImageView addGestureRecognizer:tap];
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-03 14:07:34 +00:00
|
|
|
|
- (void)promptUserBeforeUsingGoogleAnalytics
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"[HomeViewController]: Invite the user to send crash reports");
|
|
|
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
|
|
|
|
|
[currentAlert dismiss:NO];
|
|
|
|
|
|
|
|
|
|
currentAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"google_analytics_use_prompt", @"Vector", nil)
|
|
|
|
|
message:nil
|
|
|
|
|
style:MXKAlertStyleAlert];
|
|
|
|
|
|
|
|
|
|
currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"no"]
|
|
|
|
|
style:MXKAlertActionStyleDefault
|
|
|
|
|
handler:^(MXKAlert *alert) {
|
|
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"enableCrashReport"];
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
|
{
|
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
strongSelf->currentAlert = nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
[currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"yes"]
|
|
|
|
|
style:MXKAlertActionStyleDefault
|
|
|
|
|
handler:^(MXKAlert *alert) {
|
|
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"enableCrashReport"];
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
|
{
|
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
strongSelf->currentAlert = nil;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 15:37:23 +00:00
|
|
|
|
[[AppDelegate theDelegate] startGoogleAnalytics];
|
2016-06-03 14:07:34 +00:00
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
[currentAlert showInViewController:self];
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 15:48:43 +00:00
|
|
|
|
// Made the currently displayed child update its selected cell
|
|
|
|
|
- (void)refreshCurrentSelectedCellInChild:(BOOL)forceVisible
|
|
|
|
|
{
|
|
|
|
|
// TODO: Manage other children than recents
|
2016-02-26 17:18:04 +00:00
|
|
|
|
[recentsViewController refreshCurrentSelectedCell:forceVisible];
|
2015-12-09 15:48:43 +00:00
|
|
|
|
}
|
2015-12-09 13:39:37 +00:00
|
|
|
|
|
2016-06-16 16:06:05 +00:00
|
|
|
|
- (void)setHidden:(BOOL)hidden
|
|
|
|
|
{
|
|
|
|
|
_hidden = hidden;
|
|
|
|
|
|
|
|
|
|
self.selectionContainer.hidden = hidden;
|
|
|
|
|
self.viewControllerContainer.hidden = hidden;
|
|
|
|
|
self.navigationController.navigationBar.hidden = hidden;
|
|
|
|
|
|
|
|
|
|
createNewRoomImageView.hidden = hidden;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 15:48:43 +00:00
|
|
|
|
#pragma mark - Navigation
|
2015-12-09 11:02:43 +00:00
|
|
|
|
|
2015-12-09 13:39:37 +00:00
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
|
|
|
|
|
{
|
|
|
|
|
if ([[segue identifier] isEqualToString:@"showDetails"])
|
|
|
|
|
{
|
|
|
|
|
UIViewController *controller;
|
|
|
|
|
if ([[segue destinationViewController] isKindOfClass:[UINavigationController class]])
|
|
|
|
|
{
|
|
|
|
|
controller = [[segue destinationViewController] topViewController];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
controller = [segue destinationViewController];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([controller isKindOfClass:[RoomViewController class]])
|
|
|
|
|
{
|
|
|
|
|
// Release existing Room view controller (if any)
|
2015-12-09 15:48:43 +00:00
|
|
|
|
if (_currentRoomViewController)
|
2015-12-09 13:39:37 +00:00
|
|
|
|
{
|
2016-06-10 15:15:42 +00:00
|
|
|
|
// If the displayed data is not a preview, let the manager release the room data source
|
|
|
|
|
// (except if the view controller has the room data source ownership).
|
|
|
|
|
if (!_currentRoomViewController.roomPreviewData && _currentRoomViewController.roomDataSource && !_currentRoomViewController.hasRoomDataSourceOwnership)
|
2015-12-09 13:39:37 +00:00
|
|
|
|
{
|
2015-12-09 15:48:43 +00:00
|
|
|
|
MXSession *mxSession = _currentRoomViewController.roomDataSource.mxSession;
|
2015-12-09 13:39:37 +00:00
|
|
|
|
MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:mxSession];
|
2016-06-10 15:15:42 +00:00
|
|
|
|
|
2015-12-09 15:48:43 +00:00
|
|
|
|
[roomDataSourceManager closeRoomDataSource:_currentRoomViewController.roomDataSource forceClose:NO];
|
2015-12-09 13:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 15:48:43 +00:00
|
|
|
|
[_currentRoomViewController destroy];
|
|
|
|
|
_currentRoomViewController = nil;
|
2015-12-09 13:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 15:48:43 +00:00
|
|
|
|
_currentRoomViewController = (RoomViewController *)controller;
|
2015-12-09 13:39:37 +00:00
|
|
|
|
|
2016-04-15 07:43:56 +00:00
|
|
|
|
if (!_selectedRoomPreviewData)
|
2016-03-04 15:46:43 +00:00
|
|
|
|
{
|
2016-04-15 07:43:56 +00:00
|
|
|
|
// Live timeline or timeline from a search result?
|
|
|
|
|
MXKRoomDataSource *roomDataSource;
|
|
|
|
|
if (!searchViewController.selectedEvent)
|
2016-04-07 15:36:18 +00:00
|
|
|
|
{
|
2016-04-15 07:43:56 +00:00
|
|
|
|
if (!_selectedEventId)
|
|
|
|
|
{
|
|
|
|
|
// LIVE: Show the room live timeline managed by MXKRoomDataSourceManager
|
|
|
|
|
MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:_selectedRoomSession];
|
|
|
|
|
roomDataSource = [roomDataSourceManager roomDataSourceForRoom:_selectedRoomId create:YES];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Open the room on the requested event
|
|
|
|
|
roomDataSource = [[RoomDataSource alloc] initWithRoomId:_selectedRoomId initialEventId:_selectedEventId andMatrixSession:_selectedRoomSession];
|
|
|
|
|
[roomDataSource finalizeInitialization];
|
2016-06-10 15:15:42 +00:00
|
|
|
|
|
|
|
|
|
// Give the data source ownership to the room view controller.
|
2016-06-09 12:41:55 +00:00
|
|
|
|
_currentRoomViewController.hasRoomDataSourceOwnership = YES;
|
2016-04-15 07:43:56 +00:00
|
|
|
|
}
|
2016-04-07 15:36:18 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-04-15 07:43:56 +00:00
|
|
|
|
// Search result: Create a temp timeline from the selected event
|
|
|
|
|
roomDataSource = [[RoomDataSource alloc] initWithRoomId:searchViewController.selectedEvent.roomId initialEventId:searchViewController.selectedEvent.eventId andMatrixSession:searchDataSource.mxSession];
|
2016-04-07 15:36:18 +00:00
|
|
|
|
[roomDataSource finalizeInitialization];
|
2016-06-10 15:15:42 +00:00
|
|
|
|
|
|
|
|
|
// Give the data source ownership to the room view controller.
|
2016-06-09 12:41:55 +00:00
|
|
|
|
_currentRoomViewController.hasRoomDataSourceOwnership = YES;
|
2016-04-07 15:36:18 +00:00
|
|
|
|
}
|
2016-04-15 07:43:56 +00:00
|
|
|
|
|
|
|
|
|
[_currentRoomViewController displayRoom:roomDataSource];
|
2016-03-04 15:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-06-08 16:02:22 +00:00
|
|
|
|
[_currentRoomViewController displayRoomPreview:_selectedRoomPreviewData];
|
2016-04-15 07:43:56 +00:00
|
|
|
|
_selectedRoomPreviewData = nil;
|
2016-03-04 15:46:43 +00:00
|
|
|
|
}
|
2015-12-09 13:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (self.splitViewController)
|
|
|
|
|
{
|
|
|
|
|
// Refresh selected cell without scrolling the selected cell (We suppose it's visible here)
|
2015-12-09 15:48:43 +00:00
|
|
|
|
[self refreshCurrentSelectedCellInChild:NO];
|
2015-12-09 13:39:37 +00:00
|
|
|
|
|
|
|
|
|
// IOS >= 8
|
|
|
|
|
if ([self.splitViewController respondsToSelector:@selector(displayModeButtonItem)])
|
|
|
|
|
{
|
|
|
|
|
controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
controller.navigationItem.leftItemsSupplementBackButton = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-21 10:49:55 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Keep ref on destinationViewController
|
|
|
|
|
[super prepareForSegue:segue sender:sender];
|
2016-06-21 19:47:20 +00:00
|
|
|
|
|
2016-03-04 14:47:27 +00:00
|
|
|
|
if ([[segue identifier] isEqualToString:@"showDirectory"])
|
|
|
|
|
{
|
2016-06-22 10:03:05 +00:00
|
|
|
|
DirectoryViewController *directoryViewController = segue.destinationViewController;
|
2016-03-04 14:47:27 +00:00
|
|
|
|
[directoryViewController displayWitDataSource:recentsDataSource.publicRoomsDirectoryDataSource];
|
|
|
|
|
}
|
2016-06-21 19:47:20 +00:00
|
|
|
|
else if ([[segue identifier] isEqualToString:@"showContactDetails"])
|
|
|
|
|
{
|
2016-06-22 10:03:05 +00:00
|
|
|
|
ContactDetailsViewController *contactDetailsViewController = segue.destinationViewController;
|
2016-06-21 19:47:20 +00:00
|
|
|
|
contactDetailsViewController.contact = selectedContact;
|
|
|
|
|
}
|
2016-04-21 14:19:16 +00:00
|
|
|
|
else if ([[segue identifier] isEqualToString:@"showAuth"])
|
|
|
|
|
{
|
|
|
|
|
// Keep ref on the authentification view controller while it is displayed
|
|
|
|
|
// ie until we get the notification about a new account
|
|
|
|
|
_authViewController = segue.destinationViewController;
|
2016-04-25 09:29:47 +00:00
|
|
|
|
isAuthViewControllerPreparing = NO;
|
2016-04-21 14:19:16 +00:00
|
|
|
|
|
|
|
|
|
authViewControllerObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXKAccountManagerDidAddAccountNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
|
|
|
|
|
|
|
|
|
_authViewController = nil;
|
|
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:authViewControllerObserver];
|
|
|
|
|
authViewControllerObserver = nil;
|
|
|
|
|
}];
|
2016-04-21 15:49:52 +00:00
|
|
|
|
|
|
|
|
|
// Forward parameters if any
|
2016-04-22 16:42:14 +00:00
|
|
|
|
if (authViewControllerRegistrationParameters)
|
2016-04-21 15:49:52 +00:00
|
|
|
|
{
|
2016-04-22 16:42:14 +00:00
|
|
|
|
_authViewController.externalRegistrationParameters = authViewControllerRegistrationParameters;
|
|
|
|
|
authViewControllerRegistrationParameters = nil;
|
2016-04-21 15:49:52 +00:00
|
|
|
|
}
|
2016-04-21 14:19:16 +00:00
|
|
|
|
}
|
2015-12-18 16:17:03 +00:00
|
|
|
|
}
|
2015-12-09 13:39:37 +00:00
|
|
|
|
|
|
|
|
|
// Hide back button title
|
|
|
|
|
self.navigationItem.backBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 11:02:43 +00:00
|
|
|
|
#pragma mark - Search
|
2015-12-09 09:12:08 +00:00
|
|
|
|
|
|
|
|
|
- (void)showSearch:(BOOL)animated
|
|
|
|
|
{
|
2015-12-28 08:39:17 +00:00
|
|
|
|
[super showSearch:animated];
|
|
|
|
|
|
2015-12-21 10:45:47 +00:00
|
|
|
|
// Reset searches
|
|
|
|
|
[recentsDataSource searchWithPatterns:nil];
|
|
|
|
|
|
2015-12-30 16:44:41 +00:00
|
|
|
|
createNewRoomImageView.hidden = YES;
|
|
|
|
|
tableViewMaskLayer.hidden = YES;
|
|
|
|
|
|
2015-12-28 08:39:17 +00:00
|
|
|
|
[self updateSearch];
|
2016-06-14 09:10:37 +00:00
|
|
|
|
|
|
|
|
|
// Screen tracking (via Google Analytics)
|
|
|
|
|
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
|
|
|
|
|
if (tracker)
|
|
|
|
|
{
|
|
|
|
|
[tracker set:kGAIScreenName value:@"RoomsGlobalSearch"];
|
|
|
|
|
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
|
|
|
|
|
}
|
2015-12-09 09:12:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)hideSearch:(BOOL)animated
|
|
|
|
|
{
|
2015-12-28 08:39:17 +00:00
|
|
|
|
[super hideSearch:animated];
|
2015-12-09 09:12:08 +00:00
|
|
|
|
|
2015-12-30 16:44:41 +00:00
|
|
|
|
createNewRoomImageView.hidden = NO;
|
|
|
|
|
tableViewMaskLayer.hidden = NO;
|
2016-01-05 15:59:22 +00:00
|
|
|
|
self.backgroundImageView.hidden = YES;
|
2015-12-30 16:44:41 +00:00
|
|
|
|
|
2015-12-15 16:13:59 +00:00
|
|
|
|
[recentsDataSource searchWithPatterns:nil];
|
|
|
|
|
|
2016-06-14 09:10:37 +00:00
|
|
|
|
recentsDataSource.hideRecents = NO;
|
|
|
|
|
recentsDataSource.hidePublicRoomsDirectory = YES;
|
|
|
|
|
|
|
|
|
|
// Screen tracking (via Google Analytics)
|
|
|
|
|
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
|
|
|
|
|
if (tracker)
|
|
|
|
|
{
|
|
|
|
|
NSString *currentScreenName = [tracker get:kGAIScreenName];
|
|
|
|
|
if (!currentScreenName || ![currentScreenName isEqualToString:@"RoomsList"])
|
|
|
|
|
{
|
|
|
|
|
[tracker set:kGAIScreenName value:@"RoomsList"];
|
|
|
|
|
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-09 11:02:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update search results under the currently selected tab
|
|
|
|
|
- (void)updateSearch
|
|
|
|
|
{
|
2015-12-28 08:39:17 +00:00
|
|
|
|
if (self.searchBar.text.length)
|
2015-12-09 11:02:43 +00:00
|
|
|
|
{
|
2016-05-30 11:42:45 +00:00
|
|
|
|
recentsDataSource.hideRecents = NO;
|
2016-06-03 08:28:46 +00:00
|
|
|
|
recentsDataSource.hidePublicRoomsDirectory = NO;
|
2016-01-05 15:59:22 +00:00
|
|
|
|
self.backgroundImageView.hidden = YES;
|
2015-12-09 11:02:43 +00:00
|
|
|
|
|
|
|
|
|
// Forward the search request to the data source
|
2015-12-15 16:31:16 +00:00
|
|
|
|
if (self.selectedViewController == recentsViewController)
|
2015-12-09 11:02:43 +00:00
|
|
|
|
{
|
2015-12-30 14:15:08 +00:00
|
|
|
|
// Do a AND search on words separated by a space
|
|
|
|
|
NSArray *patterns = [self.searchBar.text componentsSeparatedByString:@" "];
|
|
|
|
|
|
2015-12-21 15:41:41 +00:00
|
|
|
|
[recentsDataSource searchWithPatterns:patterns];
|
2015-12-21 10:13:46 +00:00
|
|
|
|
recentsViewController.shouldScrollToTopOnRefresh = YES;
|
2015-12-09 11:02:43 +00:00
|
|
|
|
}
|
2015-12-30 14:15:08 +00:00
|
|
|
|
else if (self.selectedViewController == searchViewController)
|
|
|
|
|
{
|
|
|
|
|
// Launch the search only if the keyboard is no more visible
|
|
|
|
|
if (!self.searchBar.isFirstResponder)
|
|
|
|
|
{
|
|
|
|
|
// Do it asynchronously to give time to searchViewController to be set up
|
|
|
|
|
// so that it can display its loading wheel
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
[searchDataSource searchMessageText:self.searchBar.text];
|
|
|
|
|
searchViewController.shouldScrollToBottomOnRefresh = YES;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-20 12:16:13 +00:00
|
|
|
|
else if (self.selectedViewController == contactsViewController)
|
|
|
|
|
{
|
|
|
|
|
[contactsViewController searchWithPattern:self.searchBar.text];
|
|
|
|
|
}
|
2015-12-09 11:02:43 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-05-30 11:42:45 +00:00
|
|
|
|
// Nothing to search, show only the public dictionary
|
|
|
|
|
recentsDataSource.hideRecents = YES;
|
2016-06-03 08:28:46 +00:00
|
|
|
|
recentsDataSource.hidePublicRoomsDirectory = NO;
|
2016-05-30 11:42:45 +00:00
|
|
|
|
|
2016-05-30 14:11:24 +00:00
|
|
|
|
// Reset search result (if any)
|
|
|
|
|
[recentsDataSource searchWithPatterns:nil];
|
2016-05-30 11:42:45 +00:00
|
|
|
|
if (searchDataSource.searchText.length)
|
|
|
|
|
{
|
|
|
|
|
[searchDataSource searchMessageText:nil];
|
|
|
|
|
}
|
2016-06-20 12:16:13 +00:00
|
|
|
|
[contactsViewController searchWithPattern:nil];
|
2015-12-09 09:12:08 +00:00
|
|
|
|
}
|
2016-05-30 14:11:24 +00:00
|
|
|
|
|
|
|
|
|
[self checkAndShowBackgroundImage];
|
2015-12-09 09:12:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 11:02:43 +00:00
|
|
|
|
#pragma mark - UISearchBarDelegate
|
2015-12-09 09:12:08 +00:00
|
|
|
|
|
2015-12-09 11:02:43 +00:00
|
|
|
|
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
|
|
|
|
|
{
|
2015-12-15 16:31:16 +00:00
|
|
|
|
if (self.selectedViewController == recentsViewController)
|
2015-12-09 11:02:43 +00:00
|
|
|
|
{
|
2015-12-30 14:15:08 +00:00
|
|
|
|
// As the public room search is local, it can be updated on each text change
|
|
|
|
|
[self updateSearch];
|
|
|
|
|
}
|
2016-06-20 12:16:13 +00:00
|
|
|
|
else if (self.selectedViewController == contactsViewController)
|
|
|
|
|
{
|
|
|
|
|
// As the contact search is local, it can be updated on each text change
|
|
|
|
|
[self updateSearch];
|
|
|
|
|
}
|
2016-05-30 11:42:45 +00:00
|
|
|
|
else if (!self.searchBar.text.length)
|
|
|
|
|
{
|
|
|
|
|
// Reset message search if any
|
|
|
|
|
[self updateSearch];
|
|
|
|
|
}
|
2015-12-30 14:15:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
|
|
|
|
|
{
|
|
|
|
|
[searchBar resignFirstResponder];
|
|
|
|
|
|
|
|
|
|
if (self.selectedViewController == searchViewController)
|
|
|
|
|
{
|
|
|
|
|
// As the messages search is done homeserver-side, launch it only on the "Search" button
|
2015-12-09 11:02:43 +00:00
|
|
|
|
[self updateSearch];
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-09 09:12:08 +00:00
|
|
|
|
|
2015-12-09 13:39:37 +00:00
|
|
|
|
#pragma mark - MXKRecentListViewControllerDelegate
|
|
|
|
|
|
|
|
|
|
- (void)recentListViewController:(MXKRecentListViewController *)recentListViewController didSelectRoom:(NSString *)roomId inMatrixSession:(MXSession *)matrixSession
|
|
|
|
|
{
|
|
|
|
|
// Open the room
|
2016-04-07 15:36:18 +00:00
|
|
|
|
[self selectRoomWithId:roomId andEventId:nil inMatrixSession:matrixSession];
|
2015-12-09 13:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 19:47:20 +00:00
|
|
|
|
#pragma mark - ContactPickerViewControllerDelegate
|
|
|
|
|
|
|
|
|
|
- (void)contactPickerViewController:(ContactPickerViewController *)contactPickerViewController didSelectContact:(MXKContact*)contact
|
|
|
|
|
{
|
|
|
|
|
selectedContact = contact;
|
|
|
|
|
|
|
|
|
|
// Force hiding the keyboard
|
|
|
|
|
[self.searchBar resignFirstResponder];
|
|
|
|
|
|
|
|
|
|
[self performSegueWithIdentifier:@"showContactDetails" sender:self];
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 11:28:25 +00:00
|
|
|
|
#pragma mark - Actions
|
2015-12-09 09:12:08 +00:00
|
|
|
|
|
|
|
|
|
- (IBAction)onButtonPressed:(id)sender
|
|
|
|
|
{
|
|
|
|
|
if (sender == _searchBarButtonIem)
|
|
|
|
|
{
|
|
|
|
|
[self showSearch:YES];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 11:28:25 +00:00
|
|
|
|
- (void)onNewRoomPressed
|
|
|
|
|
{
|
2016-03-22 09:08:01 +00:00
|
|
|
|
// Sanity check
|
|
|
|
|
if (self.mainSession)
|
|
|
|
|
{
|
2016-04-22 13:17:58 +00:00
|
|
|
|
// Create one room at time
|
|
|
|
|
if (!roomCreationRequest)
|
|
|
|
|
{
|
|
|
|
|
[recentsViewController startActivityIndicator];
|
|
|
|
|
|
|
|
|
|
// Create an empty room.
|
|
|
|
|
roomCreationRequest = [self.mainSession createRoom:nil
|
2016-06-10 16:25:17 +00:00
|
|
|
|
visibility:kMXRoomDirectoryVisibilityPrivate
|
2016-04-22 13:17:58 +00:00
|
|
|
|
roomAlias:nil
|
|
|
|
|
topic:nil
|
|
|
|
|
success:^(MXRoom *room) {
|
|
|
|
|
|
|
|
|
|
roomCreationRequest = nil;
|
|
|
|
|
[recentsViewController stopActivityIndicator];
|
|
|
|
|
if (currentAlert)
|
|
|
|
|
{
|
|
|
|
|
[currentAlert dismiss:NO];
|
|
|
|
|
currentAlert = nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self selectRoomWithId:room.state.roomId andEventId:nil inMatrixSession:self.mainSession];
|
|
|
|
|
|
|
|
|
|
// Force the expanded header
|
|
|
|
|
self.currentRoomViewController.showExpandedHeader = YES;
|
|
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
|
|
roomCreationRequest = nil;
|
|
|
|
|
[recentsViewController stopActivityIndicator];
|
|
|
|
|
if (currentAlert)
|
|
|
|
|
{
|
|
|
|
|
[currentAlert dismiss:NO];
|
|
|
|
|
currentAlert = nil;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-03 14:07:34 +00:00
|
|
|
|
NSLog(@"[HomeViewController] Create new room failed");
|
2016-04-22 13:17:58 +00:00
|
|
|
|
|
|
|
|
|
// Alert user
|
|
|
|
|
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Ask the user to wait
|
|
|
|
|
__weak __typeof(self) weakSelf = self;
|
|
|
|
|
currentAlert = [[MXKAlert alloc] initWithTitle:nil
|
|
|
|
|
message:NSLocalizedStringFromTable(@"room_creation_wait_for_creation", @"Vector", nil)
|
|
|
|
|
style:MXKAlertStyleAlert];
|
|
|
|
|
|
|
|
|
|
currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"]
|
|
|
|
|
style:MXKAlertActionStyleCancel
|
|
|
|
|
handler:^(MXKAlert *alert) {
|
|
|
|
|
|
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
strongSelf->currentAlert = nil;
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
[currentAlert showInViewController:self];
|
|
|
|
|
|
|
|
|
|
}
|
2016-03-22 09:08:01 +00:00
|
|
|
|
}
|
2015-12-09 11:28:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 09:12:08 +00:00
|
|
|
|
@end
|