2014-10-08 12:14:12 +00:00
|
|
|
/*
|
|
|
|
Copyright 2014 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.
|
|
|
|
*/
|
|
|
|
|
2014-10-08 16:55:26 +00:00
|
|
|
#import "MasterTabBarController.h"
|
2014-10-08 12:14:12 +00:00
|
|
|
|
2015-05-05 16:08:22 +00:00
|
|
|
#import "AppDelegate.h"
|
|
|
|
|
2014-10-15 14:13:35 +00:00
|
|
|
#import "RecentsViewController.h"
|
2015-04-11 23:44:25 +00:00
|
|
|
#import "RecentListDataSource.h"
|
2014-10-15 14:13:35 +00:00
|
|
|
|
2015-04-13 16:00:39 +00:00
|
|
|
#import "SettingsViewController.h"
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
@interface MasterTabBarController ()
|
|
|
|
{
|
2015-05-21 16:15:45 +00:00
|
|
|
//Array of `MXSession` instances.
|
|
|
|
NSMutableArray *mxSessionArray;
|
|
|
|
|
|
|
|
// Tab bar view controllers
|
2015-04-17 12:24:08 +00:00
|
|
|
|
2014-10-15 14:13:35 +00:00
|
|
|
UINavigationController *recentsNavigationController;
|
|
|
|
RecentsViewController *recentsViewController;
|
2014-11-04 16:26:33 +00:00
|
|
|
|
2015-04-13 16:00:39 +00:00
|
|
|
SettingsViewController *settingsViewController;
|
2014-10-15 14:13:35 +00:00
|
|
|
}
|
2014-10-08 12:14:12 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2014-10-08 16:55:26 +00:00
|
|
|
@implementation MasterTabBarController
|
2014-10-08 12:14:12 +00:00
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
2014-10-08 12:14:12 +00:00
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view, typically from a nib.
|
2014-10-15 14:13:35 +00:00
|
|
|
|
2015-05-21 16:15:45 +00:00
|
|
|
mxSessionArray = [NSMutableArray array];
|
|
|
|
|
2014-10-15 14:13:35 +00:00
|
|
|
// To simplify navigation into the app, we retrieve here the navigation controller and the view controller related
|
|
|
|
// to the recents list in Recents Tab.
|
|
|
|
// Note: UISplitViewController is not supported on iPhone for iOS < 8.0
|
|
|
|
UIViewController* recents = [self.viewControllers objectAtIndex:TABBAR_RECENTS_INDEX];
|
|
|
|
recentsNavigationController = nil;
|
2015-06-11 15:03:31 +00:00
|
|
|
if ([recents isKindOfClass:[UISplitViewController class]])
|
|
|
|
{
|
2014-10-15 14:13:35 +00:00
|
|
|
UISplitViewController *splitViewController = (UISplitViewController *)recents;
|
|
|
|
recentsNavigationController = [splitViewController.viewControllers objectAtIndex:0];
|
2015-06-11 15:03:31 +00:00
|
|
|
}
|
|
|
|
else if ([recents isKindOfClass:[UINavigationController class]])
|
|
|
|
{
|
2014-10-15 14:13:35 +00:00
|
|
|
recentsNavigationController = (UINavigationController*)recents;
|
|
|
|
}
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
if (recentsNavigationController)
|
|
|
|
{
|
|
|
|
for (UIViewController *viewController in recentsNavigationController.viewControllers)
|
|
|
|
{
|
|
|
|
if ([viewController isKindOfClass:[RecentsViewController class]])
|
|
|
|
{
|
2014-10-15 14:13:35 +00:00
|
|
|
recentsViewController = (RecentsViewController*)viewController;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-11 23:44:25 +00:00
|
|
|
|
2015-04-13 16:00:39 +00:00
|
|
|
// Retrieve the settings view controller
|
|
|
|
UIViewController* settings = [self.viewControllers objectAtIndex:TABBAR_SETTINGS_INDEX];
|
2015-06-11 15:03:31 +00:00
|
|
|
if ([settings isKindOfClass:[UINavigationController class]])
|
|
|
|
{
|
2015-04-13 16:00:39 +00:00
|
|
|
UINavigationController *settingsNavigationController = (UINavigationController*)settings;
|
2015-06-11 15:03:31 +00:00
|
|
|
for (UIViewController *viewController in settingsNavigationController.viewControllers)
|
|
|
|
{
|
|
|
|
if ([viewController isKindOfClass:[SettingsViewController class]])
|
|
|
|
{
|
2015-04-13 16:00:39 +00:00
|
|
|
settingsViewController = (SettingsViewController*)viewController;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sanity check
|
2015-08-12 07:32:45 +00:00
|
|
|
NSAssert(recentsViewController && settingsViewController, @"Something wrong in Main.storyboard");
|
2014-10-08 12:14:12 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
{
|
2014-10-08 12:14:12 +00:00
|
|
|
[super viewDidAppear:animated];
|
|
|
|
|
2015-04-17 12:24:08 +00:00
|
|
|
// Check whether we're not logged in
|
2015-06-11 15:03:31 +00:00
|
|
|
if (![MXKAccountManager sharedManager].accounts.count)
|
|
|
|
{
|
2015-02-05 10:43:06 +00:00
|
|
|
[self showAuthenticationScreen];
|
2014-10-08 12:14:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
- (void)didReceiveMemoryWarning
|
|
|
|
{
|
2014-10-08 12:14:12 +00:00
|
|
|
[super didReceiveMemoryWarning];
|
2015-05-05 16:08:22 +00:00
|
|
|
|
2014-10-08 12:14:12 +00:00
|
|
|
// Dispose of any resources that can be recreated.
|
2015-05-05 16:08:22 +00:00
|
|
|
[[AppDelegate theDelegate] reloadMatrixSessions:NO];
|
2014-10-08 12:14:12 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
2015-05-21 16:15:45 +00:00
|
|
|
mxSessionArray = nil;
|
|
|
|
|
2014-10-15 14:13:35 +00:00
|
|
|
recentsNavigationController = nil;
|
|
|
|
recentsViewController = nil;
|
2015-04-13 16:00:39 +00:00
|
|
|
settingsViewController = nil;
|
2014-10-15 14:13:35 +00:00
|
|
|
}
|
|
|
|
|
2014-10-13 12:45:29 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
- (void)restoreInitialDisplay
|
|
|
|
{
|
2014-11-04 16:26:33 +00:00
|
|
|
// Dismiss potential media picker
|
2015-08-17 17:15:58 +00:00
|
|
|
if (self.presentedViewController)
|
2015-06-11 15:03:31 +00:00
|
|
|
{
|
2015-08-17 17:15:58 +00:00
|
|
|
[self dismissViewControllerAnimated:NO completion:nil];
|
2014-11-04 16:26:33 +00:00
|
|
|
}
|
|
|
|
|
2014-12-10 09:11:45 +00:00
|
|
|
[self popRoomViewControllerAnimated:NO];
|
2014-11-04 16:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
- (NSArray*)mxSessions
|
|
|
|
{
|
2015-05-21 16:15:45 +00:00
|
|
|
return [NSArray arrayWithArray:mxSessionArray];
|
|
|
|
}
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
- (void)addMatrixSession:(MXSession *)mxSession
|
|
|
|
{
|
|
|
|
if (mxSession)
|
|
|
|
{
|
2015-05-28 15:54:50 +00:00
|
|
|
// Update recents data source (The recents view controller will be updated by its data source)
|
2015-06-11 15:03:31 +00:00
|
|
|
if (!mxSessionArray.count)
|
|
|
|
{
|
2015-05-28 15:54:50 +00:00
|
|
|
// This is the first added session, list all the recents for the logged user
|
2015-06-11 14:59:57 +00:00
|
|
|
RecentListDataSource *recentlistDataSource = [[RecentListDataSource alloc] initWithMatrixSession:mxSession];
|
2015-05-21 16:15:45 +00:00
|
|
|
[recentsViewController displayList:recentlistDataSource];
|
2015-06-11 15:03:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-21 16:15:45 +00:00
|
|
|
[recentsViewController.dataSource addMatrixSession:mxSession];
|
|
|
|
}
|
|
|
|
|
2015-05-28 15:54:50 +00:00
|
|
|
// Update settings tab
|
|
|
|
[settingsViewController addMatrixSession:mxSession];
|
|
|
|
|
2015-05-21 16:15:45 +00:00
|
|
|
[mxSessionArray addObject:mxSession];
|
2015-04-17 13:45:32 +00:00
|
|
|
}
|
2015-05-21 16:15:45 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
- (void)removeMatrixSession:(MXSession*)mxSession
|
|
|
|
{
|
2015-05-28 15:54:50 +00:00
|
|
|
// Update recents data source
|
2015-05-21 16:15:45 +00:00
|
|
|
[recentsViewController.dataSource removeMatrixSession:mxSession];
|
|
|
|
|
2015-05-28 15:54:50 +00:00
|
|
|
// Update settings tab
|
|
|
|
[settingsViewController removeMatrixSession:mxSession];
|
2015-04-17 12:24:08 +00:00
|
|
|
|
2015-05-28 15:54:50 +00:00
|
|
|
[mxSessionArray removeObject:mxSession];
|
2015-04-14 08:55:18 +00:00
|
|
|
|
2015-05-21 16:15:45 +00:00
|
|
|
// Check whether there are others sessions
|
2015-06-11 15:03:31 +00:00
|
|
|
if (!mxSessionArray.count)
|
|
|
|
{
|
2015-05-21 16:15:45 +00:00
|
|
|
// Keep reference on existing dataSource to release it properly
|
2015-06-11 14:59:57 +00:00
|
|
|
MXKRecentsDataSource *previousRecentlistDataSource = recentsViewController.dataSource;
|
2015-05-21 16:15:45 +00:00
|
|
|
[recentsViewController displayList:nil];
|
|
|
|
[previousRecentlistDataSource destroy];
|
|
|
|
}
|
2015-04-17 13:45:32 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
- (void)showAuthenticationScreen
|
|
|
|
{
|
2015-04-17 13:45:32 +00:00
|
|
|
[self restoreInitialDisplay];
|
2015-02-05 10:43:06 +00:00
|
|
|
[self performSegueWithIdentifier:@"showAuth" sender:self];
|
2014-10-08 12:14:12 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
- (void)showRoom:(NSString*)roomId withMatrixSession:(MXSession*)mxSession
|
|
|
|
{
|
2014-11-04 16:26:33 +00:00
|
|
|
[self restoreInitialDisplay];
|
2014-10-15 14:13:35 +00:00
|
|
|
|
|
|
|
// Switch on Recents Tab
|
2014-10-10 12:30:09 +00:00
|
|
|
[self setSelectedIndex:TABBAR_RECENTS_INDEX];
|
2014-10-15 14:13:35 +00:00
|
|
|
|
2014-10-30 17:23:02 +00:00
|
|
|
// Select room to display its details (dispatch this action in order to let TabBarController end its refresh)
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2015-05-28 17:20:18 +00:00
|
|
|
[recentsViewController selectRoomWithId:roomId inMatrixSession:mxSession];
|
2014-10-30 17:23:02 +00:00
|
|
|
});
|
2014-10-10 12:30:09 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
- (void)popRoomViewControllerAnimated:(BOOL)animated
|
|
|
|
{
|
2014-12-10 09:11:45 +00:00
|
|
|
// Force back to recents list if room details is displayed in Recents Tab
|
2015-06-11 15:03:31 +00:00
|
|
|
if (recentsViewController)
|
|
|
|
{
|
2014-12-10 09:11:45 +00:00
|
|
|
[recentsNavigationController popToViewController:recentsViewController animated:animated];
|
2015-01-22 16:26:51 +00:00
|
|
|
// Release the current selected room
|
2015-05-21 17:06:34 +00:00
|
|
|
[recentsViewController closeSelectedRoom];
|
2014-12-10 09:11:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 15:03:31 +00:00
|
|
|
- (void)setVisibleRoomId:(NSString *)roomId
|
|
|
|
{
|
|
|
|
if (roomId)
|
|
|
|
{
|
2015-05-28 16:48:37 +00:00
|
|
|
// Enable inApp notification for this room in all existing accounts.
|
|
|
|
NSArray *mxAccounts = [MXKAccountManager sharedManager].accounts;
|
2015-06-11 15:03:31 +00:00
|
|
|
for (MXKAccount *account in mxAccounts)
|
|
|
|
{
|
2015-05-28 16:48:37 +00:00
|
|
|
[account updateNotificationListenerForRoomId:roomId ignore:NO];
|
|
|
|
}
|
2015-04-30 14:19:12 +00:00
|
|
|
}
|
|
|
|
|
2015-05-28 16:48:37 +00:00
|
|
|
_visibleRoomId = roomId;
|
2015-01-29 10:32:15 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 12:14:12 +00:00
|
|
|
@end
|