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-04-17 12:24:08 +00:00
|
|
|
#import "HomeViewController.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-14 08:55:18 +00:00
|
|
|
#import "ContactsViewController.h"
|
|
|
|
|
2015-04-13 16:00:39 +00:00
|
|
|
#import "SettingsViewController.h"
|
|
|
|
|
2014-10-15 14:13:35 +00:00
|
|
|
@interface MasterTabBarController () {
|
2015-04-17 12:24:08 +00:00
|
|
|
HomeViewController *homeViewController;
|
|
|
|
|
2014-10-15 14:13:35 +00:00
|
|
|
UINavigationController *recentsNavigationController;
|
|
|
|
RecentsViewController *recentsViewController;
|
2014-11-04 16:26:33 +00:00
|
|
|
|
2015-04-14 08:55:18 +00:00
|
|
|
ContactsViewController *contactsViewController;
|
|
|
|
|
2015-04-13 16:00:39 +00:00
|
|
|
SettingsViewController *settingsViewController;
|
|
|
|
|
2014-11-04 16:26:33 +00:00
|
|
|
UIImagePickerController *mediaPicker;
|
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
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view, typically from a nib.
|
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;
|
|
|
|
if ([recents isKindOfClass:[UISplitViewController class]]) {
|
|
|
|
UISplitViewController *splitViewController = (UISplitViewController *)recents;
|
|
|
|
recentsNavigationController = [splitViewController.viewControllers objectAtIndex:0];
|
|
|
|
} else if ([recents isKindOfClass:[UINavigationController class]]) {
|
|
|
|
recentsNavigationController = (UINavigationController*)recents;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recentsNavigationController) {
|
|
|
|
for (UIViewController *viewController in recentsNavigationController.viewControllers) {
|
|
|
|
if ([viewController isKindOfClass:[RecentsViewController class]]) {
|
|
|
|
recentsViewController = (RecentsViewController*)viewController;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-11 23:44:25 +00:00
|
|
|
|
2015-04-17 12:24:08 +00:00
|
|
|
// Retrieve the home view controller
|
|
|
|
UIViewController* home = [self.viewControllers objectAtIndex:TABBAR_HOME_INDEX];
|
|
|
|
if ([home isKindOfClass:[UINavigationController class]]) {
|
|
|
|
UINavigationController *homeNavigationController = (UINavigationController*)home;
|
|
|
|
for (UIViewController *viewController in homeNavigationController.viewControllers) {
|
|
|
|
if ([viewController isKindOfClass:[HomeViewController class]]) {
|
|
|
|
homeViewController = (HomeViewController*)viewController;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-14 08:55:18 +00:00
|
|
|
// Retrieve the constacts view controller
|
|
|
|
UIViewController* contacts = [self.viewControllers objectAtIndex:TABBAR_CONTACTS_INDEX];
|
|
|
|
if ([contacts isKindOfClass:[UINavigationController class]]) {
|
|
|
|
UINavigationController *contactsNavigationController = (UINavigationController*)contacts;
|
|
|
|
for (UIViewController *viewController in contactsNavigationController.viewControllers) {
|
|
|
|
if ([viewController isKindOfClass:[ContactsViewController class]]) {
|
|
|
|
contactsViewController = (ContactsViewController*)viewController;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 16:00:39 +00:00
|
|
|
// Retrieve the settings view controller
|
|
|
|
UIViewController* settings = [self.viewControllers objectAtIndex:TABBAR_SETTINGS_INDEX];
|
|
|
|
if ([settings isKindOfClass:[UINavigationController class]]) {
|
|
|
|
UINavigationController *settingsNavigationController = (UINavigationController*)settings;
|
|
|
|
for (UIViewController *viewController in settingsNavigationController.viewControllers) {
|
|
|
|
if ([viewController isKindOfClass:[SettingsViewController class]]) {
|
|
|
|
settingsViewController = (SettingsViewController*)viewController;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sanity check
|
2015-04-17 12:24:08 +00:00
|
|
|
NSAssert(homeViewController &&recentsViewController && contactsViewController && settingsViewController, @"Something wrong in Main.storyboard");
|
2014-10-08 12:14:12 +00:00
|
|
|
}
|
|
|
|
|
2014-10-13 12:45:29 +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-04-30 14:19:12 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
// Dispose of any resources that can be recreated.
|
|
|
|
}
|
|
|
|
|
2014-10-15 14:13:35 +00:00
|
|
|
- (void)dealloc {
|
2015-04-17 12:24:08 +00:00
|
|
|
|
|
|
|
homeViewController = nil;
|
2014-10-15 14:13:35 +00:00
|
|
|
recentsNavigationController = nil;
|
|
|
|
recentsViewController = nil;
|
2015-04-14 08:55:18 +00:00
|
|
|
contactsViewController = nil;
|
2015-04-13 16:00:39 +00:00
|
|
|
settingsViewController = nil;
|
2014-11-04 16:26:33 +00:00
|
|
|
|
|
|
|
[self dismissMediaPicker];
|
2014-10-15 14:13:35 +00:00
|
|
|
}
|
|
|
|
|
2014-10-13 12:45:29 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2014-11-04 16:26:33 +00:00
|
|
|
- (void)restoreInitialDisplay {
|
|
|
|
// Dismiss potential media picker
|
|
|
|
if (mediaPicker) {
|
|
|
|
if (mediaPicker.delegate && [mediaPicker.delegate respondsToSelector:@selector(imagePickerControllerDidCancel:)]) {
|
|
|
|
[mediaPicker.delegate imagePickerControllerDidCancel:mediaPicker];
|
|
|
|
} else {
|
|
|
|
[self dismissMediaPicker];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-10 09:11:45 +00:00
|
|
|
[self popRoomViewControllerAnimated:NO];
|
2014-11-04 16:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2015-04-17 13:45:32 +00:00
|
|
|
- (void)setMxSession:(MXSession *)mxSession {
|
|
|
|
// Update home tab
|
|
|
|
homeViewController.mxSession = mxSession;
|
2014-11-03 16:54:09 +00:00
|
|
|
|
2015-04-17 13:45:32 +00:00
|
|
|
// List all the recents for the logged user
|
|
|
|
MXKRecentListDataSource *recentlistDataSource = nil;
|
|
|
|
if (mxSession) {
|
|
|
|
recentlistDataSource = [[RecentListDataSource alloc] initWithMatrixSession:mxSession];
|
|
|
|
}
|
|
|
|
[recentsViewController displayList:recentlistDataSource];
|
2015-04-17 12:24:08 +00:00
|
|
|
|
2015-04-17 13:45:32 +00:00
|
|
|
// Update contacts tab
|
|
|
|
contactsViewController.mxSession = mxSession;
|
2015-04-14 08:55:18 +00:00
|
|
|
|
2015-04-17 13:45:32 +00:00
|
|
|
// Update settings tab
|
|
|
|
settingsViewController.mxSession = mxSession;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showAuthenticationScreen {
|
2015-04-13 16:00:39 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-10-13 12:45:29 +00:00
|
|
|
- (void)showRoomCreationForm {
|
|
|
|
// Switch in Home Tab
|
|
|
|
[self setSelectedIndex:TABBAR_HOME_INDEX];
|
|
|
|
}
|
|
|
|
|
2014-10-15 14:13:35 +00:00
|
|
|
- (void)showRoom:(NSString*)roomId {
|
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-04-03 13:02:16 +00:00
|
|
|
recentsViewController.selectedRoomId = roomId;
|
2014-10-30 17:23:02 +00:00
|
|
|
});
|
2014-10-10 12:30:09 +00:00
|
|
|
}
|
|
|
|
|
2014-12-10 09:11:45 +00:00
|
|
|
- (void)popRoomViewControllerAnimated:(BOOL)animated {
|
|
|
|
// Force back to recents list if room details is displayed in Recents Tab
|
|
|
|
if (recentsViewController) {
|
|
|
|
[recentsNavigationController popToViewController:recentsViewController animated:animated];
|
2015-01-22 16:26:51 +00:00
|
|
|
// Release the current selected room
|
2015-04-03 13:02:16 +00:00
|
|
|
recentsViewController.selectedRoomId = nil;
|
2014-12-10 09:11:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-08 16:30:06 +00:00
|
|
|
- (BOOL)isPresentingMediaPicker {
|
|
|
|
return nil != mediaPicker;
|
|
|
|
}
|
|
|
|
|
2014-11-04 16:26:33 +00:00
|
|
|
- (void)presentMediaPicker:(UIImagePickerController*)aMediaPicker {
|
|
|
|
[self dismissMediaPicker];
|
|
|
|
[self presentViewController:aMediaPicker animated:YES completion:^{
|
|
|
|
mediaPicker = aMediaPicker;
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
- (void)dismissMediaPicker {
|
|
|
|
if (mediaPicker) {
|
|
|
|
[self dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
mediaPicker.delegate = nil;
|
|
|
|
mediaPicker = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-29 10:32:15 +00:00
|
|
|
- (void)setVisibleRoomId:(NSString *)aVisibleRoomId {
|
2015-04-30 14:19:12 +00:00
|
|
|
|
|
|
|
// Presently only the first account is used
|
|
|
|
// TODO GFO: handle multi-session
|
|
|
|
MXKAccount *account = [[MXKAccountManager sharedManager].accounts firstObject];
|
|
|
|
if (account) {
|
|
|
|
// Enable inApp notification for this room
|
|
|
|
[account updateNotificationListenerForRoomId:aVisibleRoomId ignore:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-29 10:32:15 +00:00
|
|
|
_visibleRoomId = aVisibleRoomId;
|
|
|
|
}
|
|
|
|
|
2014-10-08 12:14:12 +00:00
|
|
|
@end
|