diff --git a/matrixConsole.xcodeproj/project.pbxproj b/matrixConsole.xcodeproj/project.pbxproj index ed8b460d6..2e50ee5c4 100644 --- a/matrixConsole.xcodeproj/project.pbxproj +++ b/matrixConsole.xcodeproj/project.pbxproj @@ -9,9 +9,6 @@ /* Begin PBXBuildFile section */ 3198D9E11A68338B00556695 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3198D9E31A68338B00556695 /* Localizable.strings */; }; 32501A9B1A9B978400C5938F /* MXCRegistrationWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 32501A9A1A9B978400C5938F /* MXCRegistrationWebView.m */; }; - 710CA4BF1A7FBEDB00EEFB96 /* MXCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 710CA4BE1A7FBEDB00EEFB96 /* MXCViewController.m */; }; - 710CA4C21A7FBFED00EEFB96 /* RageShakableUIResponder.m in Sources */ = {isa = PBXBuildFile; fileRef = 710CA4C11A7FBFED00EEFB96 /* RageShakableUIResponder.m */; }; - 710CA4C51A7FC27100EEFB96 /* MXCTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 710CA4C41A7FC27100EEFB96 /* MXCTableViewController.m */; }; 710CC3BF1A6E9F14006EE973 /* matrixUser.png in Resources */ = {isa = PBXBuildFile; fileRef = 710CC3BE1A6E9F14006EE973 /* matrixUser.png */; }; 710CC3C21A70F28F006EE973 /* MXCContactField.m in Sources */ = {isa = PBXBuildFile; fileRef = 710CC3C11A70F28F006EE973 /* MXCContactField.m */; }; 71193D241A6D64F900E59A9E /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 71193D231A6D64F900E59A9E /* AddressBook.framework */; }; @@ -90,12 +87,6 @@ 3198D9E21A68338B00556695 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; 32501A991A9B978400C5938F /* MXCRegistrationWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXCRegistrationWebView.h; sourceTree = ""; }; 32501A9A1A9B978400C5938F /* MXCRegistrationWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXCRegistrationWebView.m; sourceTree = ""; }; - 710CA4BD1A7FBEDB00EEFB96 /* MXCViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXCViewController.h; sourceTree = ""; }; - 710CA4BE1A7FBEDB00EEFB96 /* MXCViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXCViewController.m; sourceTree = ""; }; - 710CA4C01A7FBFED00EEFB96 /* RageShakableUIResponder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RageShakableUIResponder.h; sourceTree = ""; }; - 710CA4C11A7FBFED00EEFB96 /* RageShakableUIResponder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RageShakableUIResponder.m; sourceTree = ""; }; - 710CA4C31A7FC27100EEFB96 /* MXCTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXCTableViewController.h; sourceTree = ""; }; - 710CA4C41A7FC27100EEFB96 /* MXCTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXCTableViewController.m; sourceTree = ""; }; 710CC3BE1A6E9F14006EE973 /* matrixUser.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = matrixUser.png; sourceTree = ""; }; 710CC3C01A70F28F006EE973 /* MXCContactField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXCContactField.h; sourceTree = ""; }; 710CC3C11A70F28F006EE973 /* MXCContactField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXCContactField.m; sourceTree = ""; }; @@ -302,10 +293,6 @@ F03EF5EF19F171EB00A0EE52 /* MasterTabBarController.m */, 71DB9DBF1A495B6400504A09 /* MemberViewController.h */, 71DB9DC01A495B6400504A09 /* MemberViewController.m */, - 710CA4C31A7FC27100EEFB96 /* MXCTableViewController.h */, - 710CA4C41A7FC27100EEFB96 /* MXCTableViewController.m */, - 710CA4BD1A7FBEDB00EEFB96 /* MXCViewController.h */, - 710CA4BE1A7FBEDB00EEFB96 /* MXCViewController.m */, F03EF5F019F171EB00A0EE52 /* RecentsViewController.h */, F03EF5F119F171EB00A0EE52 /* RecentsViewController.m */, F0ADEFF91AD7D2B3008A4F21 /* RoomMembersViewController.h */, @@ -360,8 +347,6 @@ 71193D331A6E49F000E59A9E /* MXCEmail.m */, 71193D341A6E49F000E59A9E /* MXCPhoneNumber.h */, 71193D351A6E49F000E59A9E /* MXCPhoneNumber.m */, - 710CA4C01A7FBFED00EEFB96 /* RageShakableUIResponder.h */, - 710CA4C11A7FBFED00EEFB96 /* RageShakableUIResponder.m */, F0F535BD1ACDE46200B603F8 /* RecentListDataSource.h */, F0F535BE1ACDE46200B603F8 /* RecentListDataSource.m */, 71193D3C1A6E61AD00E59A9E /* SectionedContacts.h */, @@ -593,7 +578,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 710CA4BF1A7FBEDB00EEFB96 /* MXCViewController.m in Sources */, 7176294F1A77FED800927125 /* ContactDetailsTableCell.m in Sources */, F04A8AD81A3B3DF4008AC915 /* RoomTitleView.m in Sources */, 32501A9B1A9B978400C5938F /* MXCRegistrationWebView.m in Sources */, @@ -611,9 +595,7 @@ 710CC3C21A70F28F006EE973 /* MXCContactField.m in Sources */, F03EF5FA19F171EB00A0EE52 /* RoomViewController.m in Sources */, F03EF5F819F171EB00A0EE52 /* MasterTabBarController.m in Sources */, - 710CA4C21A7FBFED00EEFB96 /* RageShakableUIResponder.m in Sources */, F0F535BB1ACD6C4F00B603F8 /* RageShakeManager.m in Sources */, - 710CA4C51A7FC27100EEFB96 /* MXCTableViewController.m in Sources */, F03EF5F619F171EB00A0EE52 /* HomeViewController.m in Sources */, 71DB9DC11A495B6400504A09 /* MemberViewController.m in Sources */, F03EF5F919F171EB00A0EE52 /* RecentsViewController.m in Sources */, diff --git a/matrixConsole/API/MatrixSDKHandler.h b/matrixConsole/API/MatrixSDKHandler.h index 8bd9c74bc..d082e9e00 100644 --- a/matrixConsole/API/MatrixSDKHandler.h +++ b/matrixConsole/API/MatrixSDKHandler.h @@ -60,9 +60,6 @@ typedef enum : NSUInteger { - (void)enableInAppNotifications:(BOOL)isEnabled; -// return a userIds list of 1:1 room members -- (NSArray*)oneToOneRoomMemberIDs; - // Searches if a private OneToOne room has been started with this user // Returns the room ID (nil if not found) - (NSString*)privateOneToOneRoomIdWithUserId:(NSString*)userId; diff --git a/matrixConsole/API/MatrixSDKHandler.m b/matrixConsole/API/MatrixSDKHandler.m index b9822e05e..bb5fe69c5 100644 --- a/matrixConsole/API/MatrixSDKHandler.m +++ b/matrixConsole/API/MatrixSDKHandler.m @@ -637,37 +637,7 @@ static MatrixSDKHandler *sharedHandler = nil; #pragma mark - Room handling -// return a MatrixIDs list of 1:1 room members -- (NSArray*)oneToOneRoomMemberIDs { - - NSMutableArray* matrixIDs = [[NSMutableArray alloc] init]; - MatrixSDKHandler *mxHandler = [MatrixSDKHandler sharedHandler]; - - if (mxHandler.mxSession) { - NSArray *recentEvents = [NSMutableArray arrayWithArray:[mxHandler.mxSession recentsWithTypeIn:mxHandler.eventsFilterForMessages]]; - - for (MXEvent *mxEvent in recentEvents) { - MXRoom *mxRoom = [mxHandler.mxSession roomWithRoomId:mxEvent.roomId]; - - NSArray* membersList = [mxRoom.state members]; - - // keep only 1:1 chat - if ([mxRoom.state members].count <= 2) { - - for (MXRoomMember* member in membersList) { - // not myself - if (![member.userId isEqualToString:mxHandler.userId]) { - if ([matrixIDs indexOfObject:member.userId] == NSNotFound) { - [matrixIDs addObject:member.userId]; - } - } - } - } - } - } - - return matrixIDs; -} + - (NSString*)privateOneToOneRoomIdWithUserId:(NSString*)userId { if (self.mxSession) { diff --git a/matrixConsole/AppDelegate.m b/matrixConsole/AppDelegate.m index 877221683..7aee69344 100644 --- a/matrixConsole/AppDelegate.m +++ b/matrixConsole/AppDelegate.m @@ -21,7 +21,7 @@ #import "MatrixSDKHandler.h" #import "SettingsViewController.h" #import "ContactManager.h" -#import "RageShakableUIResponder.h" +#import "RageShakeManager.h" #import "AFNetworkReachabilityManager.h" @@ -208,7 +208,7 @@ // check if the app crashed last time if ([MXLogger crashLog]) { - [RageShakableUIResponder reportCrash:self.masterTabBarController.selectedViewController]; + [[RageShakeManager sharedManager] promptCrashReportInViewController:self.masterTabBarController.selectedViewController]; } } diff --git a/matrixConsole/Base.lproj/Main.storyboard b/matrixConsole/Base.lproj/Main.storyboard index daab8912f..6531a801f 100644 --- a/matrixConsole/Base.lproj/Main.storyboard +++ b/matrixConsole/Base.lproj/Main.storyboard @@ -1,6 +1,7 @@ - + + @@ -992,12 +993,12 @@ - + @@ -1527,15 +1528,6 @@ - - - - - - - - - @@ -1623,11 +1615,9 @@ - - @@ -1635,7 +1625,6 @@ - diff --git a/matrixConsole/Model/RageShakableUIResponder.h b/matrixConsole/Model/RageShakableUIResponder.h deleted file mode 100644 index f7d075c76..000000000 --- a/matrixConsole/Model/RageShakableUIResponder.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - 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. - */ - -#import - -#import - -// TODO GFO: Remove this class - -@interface RageShakableUIResponder : UIResponder - -+ (void)startShaking:(UIResponder*)controller; -+ (void)stopShaking:(UIResponder*)controller; -+ (void)cancel:(UIResponder*)controller; -+ (void)applicationBecomesActive; -+ (void)reportCrash:(UIViewController*)viewController; - -@end diff --git a/matrixConsole/Model/RageShakableUIResponder.m b/matrixConsole/Model/RageShakableUIResponder.m deleted file mode 100644 index ca306024a..000000000 --- a/matrixConsole/Model/RageShakableUIResponder.m +++ /dev/null @@ -1,265 +0,0 @@ -/* - 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. - */ - -#define RAGESHAKABLEUIRESPONDER_MINIMUM_SHAKING_DURATION 2 - -#import "RageShakableUIResponder.h" - -#import "AppDelegate.h" -#import "MatrixSDKHandler.h" - -#import "GBDeviceInfo_iOS.h" - -@interface RageShakableUIResponder() { - MXKAlert *confirmationAlert; - double startShakingTimeStamp; - bool isShaking; - bool ignoreShakeEnd; - - UIViewController* parentViewController; - MFMailComposeViewController* mailComposer; -} -@end - -@implementation RageShakableUIResponder - -static RageShakableUIResponder* sharedInstance = nil; - -- (id) init { - self = [super init]; - - if (self) { - mailComposer = nil; - confirmationAlert = nil; - startShakingTimeStamp = 0; - isShaking = NO; - ignoreShakeEnd = NO; - } - - return self; -} - -+ (void)startShaking:(UIResponder*)responder { - if (!sharedInstance) { - sharedInstance = [[RageShakableUIResponder alloc] init]; - } - - RageShakableUIResponder* rageShakableUIResponder = [responder isKindOfClass:[RageShakableUIResponder class]] ? (RageShakableUIResponder*)responder : sharedInstance; - - // only start if the application is in foreground - if ([AppDelegate theDelegate].isAppForeground && !rageShakableUIResponder->confirmationAlert) { - NSLog(@"[RageShake] Start shaking with [%@]", [responder class]); - - rageShakableUIResponder->startShakingTimeStamp = [[NSDate date] timeIntervalSince1970]; - - rageShakableUIResponder->isShaking = YES; - rageShakableUIResponder->ignoreShakeEnd = NO; - } -} - -+ (void)stopShaking:(UIResponder*)responder { - if (!sharedInstance) { - sharedInstance = [[RageShakableUIResponder alloc] init]; - } - - NSLog(@"[RageShake] Stop shaking with [%@]", [responder class]); - - RageShakableUIResponder* rageShakableUIResponder = [responder isKindOfClass:[RageShakableUIResponder class]] ? (RageShakableUIResponder*)responder : sharedInstance; - - if (rageShakableUIResponder && [AppDelegate theDelegate].isAppForeground && (([[NSDate date] timeIntervalSince1970] - rageShakableUIResponder->startShakingTimeStamp) > RAGESHAKABLEUIRESPONDER_MINIMUM_SHAKING_DURATION) && !rageShakableUIResponder->confirmationAlert) { - if (!rageShakableUIResponder->ignoreShakeEnd) { - rageShakableUIResponder->startShakingTimeStamp = [[NSDate date] timeIntervalSince1970]; - - if ([responder isKindOfClass:[UIViewController class]]) { - rageShakableUIResponder->confirmationAlert = [[MXKAlert alloc] initWithTitle:@"You seem to be shaking the phone in frustration. Would you like to submit a bug report?" message:nil style:MXKAlertStyleAlert]; - - [rageShakableUIResponder->confirmationAlert addActionWithTitle:@"Cancel" style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { - sharedInstance->confirmationAlert = nil; - }]; - - [rageShakableUIResponder->confirmationAlert addActionWithTitle:@"OK" style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { - sharedInstance->confirmationAlert = nil; - [RageShakableUIResponder sendEmail:(UIViewController*)responder withSnapshot:YES]; - }]; - - [rageShakableUIResponder->confirmationAlert showInViewController:(UIViewController*)responder]; - } - } else { - [RageShakableUIResponder sendEmail:nil withSnapshot:NO]; - } - } - - rageShakableUIResponder->isShaking = NO; - rageShakableUIResponder->ignoreShakeEnd = NO; -} - -+ (void)cancel:(UIResponder*)responder { - - if (!sharedInstance) { - sharedInstance = [[RageShakableUIResponder alloc] init]; - } - - RageShakableUIResponder* rageShakableUIResponder = [responder isKindOfClass:[RageShakableUIResponder class]] ? (RageShakableUIResponder*)responder : sharedInstance; - - // Arathorn succeeded to shake the device and to put the application in background at the same time (magic finders) - // it should prevent any screenshot alert in this crazy case - rageShakableUIResponder->startShakingTimeStamp = [[NSDate date] timeIntervalSince1970]; - - if (rageShakableUIResponder->isShaking) { - rageShakableUIResponder->ignoreShakeEnd = YES; - } -} - -+ (void)reportCrash:(UIViewController*)viewController { - if ([MXLogger crashLog]) { - if (!sharedInstance) { - sharedInstance = [[RageShakableUIResponder alloc] init]; - } - - sharedInstance->confirmationAlert = [[MXKAlert alloc] initWithTitle:@"The application has crashed last time. Would you like to submit a crash report?" message:nil style:MXKAlertStyleAlert]; - - [sharedInstance->confirmationAlert addActionWithTitle:@"Cancel" style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { - // Erase the crash log (there is only chance for the user to send it) - [MXLogger deleteCrashLog]; - sharedInstance->confirmationAlert = nil; - }]; - - [sharedInstance->confirmationAlert addActionWithTitle:@"OK" style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { - sharedInstance->confirmationAlert = nil; - [RageShakableUIResponder sendEmail:viewController withSnapshot:NO]; - }]; - - [sharedInstance->confirmationAlert showInViewController:viewController]; - } -} - -+ (void)applicationBecomesActive { - [RageShakableUIResponder cancel:nil]; -} - -// Prepare and send a report email -// If `snapshot` is YES, a screenshot of `controller` will be sent as image attachment to the email -+ (void)sendEmail:(UIViewController*)controller withSnapshot:(BOOL)snapshot { - - UIImage *image; - - if (snapshot) { - AppDelegate* theDelegate = [AppDelegate theDelegate]; - UIGraphicsBeginImageContextWithOptions(theDelegate.window.bounds.size, NO, [UIScreen mainScreen].scale); - - // Iterate over every window from back to front - for (UIWindow *window in [[UIApplication sharedApplication] windows]) - { - if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) - { - // -renderInContext: renders in the coordinate space of the layer, - // so we must first apply the layer's geometry to the graphics context - CGContextSaveGState(UIGraphicsGetCurrentContext()); - // Center the context around the window's anchor point - CGContextTranslateCTM(UIGraphicsGetCurrentContext(), [window center].x, [window center].y); - // Apply the window's transform about the anchor point - CGContextConcatCTM(UIGraphicsGetCurrentContext(), [window transform]); - // Offset by the portion of the bounds left of and above the anchor point - CGContextTranslateCTM(UIGraphicsGetCurrentContext(), - -[window bounds].size.width * [[window layer] anchorPoint].x, - -[window bounds].size.height * [[window layer] anchorPoint].y); - - // Render the layer hierarchy to the current context - [[window layer] renderInContext:UIGraphicsGetCurrentContext()]; - - // Restore the context - CGContextRestoreGState(UIGraphicsGetCurrentContext()); - } - } - image = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - - // the image is copied in the clipboard - [UIPasteboard generalPasteboard].image = image; - } - - if (controller) { - [controller.view snapshotViewAfterScreenUpdates:YES]; - - sharedInstance->parentViewController = controller; - sharedInstance->mailComposer = [[MFMailComposeViewController alloc] init]; - - if ([MXLogger crashLog]) { - [sharedInstance->mailComposer setSubject:@"Matrix crash report"]; - } - else { - [sharedInstance->mailComposer setSubject:@"Matrix bug report"]; - } - - [sharedInstance->mailComposer setToRecipients:[NSArray arrayWithObject:@"rageshake@matrix.org"]]; - - NSString* appVersion = [AppDelegate theDelegate].appVersion; - NSString* build = [AppDelegate theDelegate].build; - MatrixSDKHandler *mxHandler = [MatrixSDKHandler sharedHandler]; - - NSMutableString* message = [[NSMutableString alloc] init]; - - [message appendFormat:@"Something went wrong on my Matrix client: \n\n\n"]; - - [message appendFormat:@"-----> my comments <-----\n\n\n"]; - - [message appendFormat:@"------------------------------\n"]; - [message appendFormat:@"Application info\n"]; - [message appendFormat:@"userId: %@\n", mxHandler.userId]; - [message appendFormat:@"displayname: %@\n", mxHandler.mxSession.myUser.displayname]; - [message appendFormat:@"\n"]; - [message appendFormat:@"homeServerURL: %@\n", mxHandler.homeServerURL]; - [message appendFormat:@"homeServer: %@\n", mxHandler.homeServer]; - [message appendFormat:@"\n"]; - [message appendFormat:@"matrixConsole version: %@\n", appVersion]; - [message appendFormat:@"SDK version: %@\n", MatrixSDKVersion]; - if (build.length) { - [message appendFormat:@"Build: %@\n", build]; - } - [message appendFormat:@"------------------------------\n"]; - [message appendFormat:@"Device info\n"]; - [message appendFormat:@"model: %@\n", [GBDeviceInfo deviceDetails].modelString]; - [message appendFormat:@"operatingSystem: %@ %@\n", [[UIDevice currentDevice] systemName], [[UIDevice currentDevice] systemVersion]]; - - [sharedInstance->mailComposer setMessageBody:message isHTML:NO]; - - // Attach image only if required - if (image) { - [sharedInstance->mailComposer addAttachmentData:UIImageJPEGRepresentation(image, 1.0) mimeType:@"image/jpg" fileName:@"screenshot.jpg"]; - } - - // Add logs files - NSMutableArray *logFiles = [NSMutableArray arrayWithArray:[MXLogger logFiles]]; - if ([MXLogger crashLog]) { - [logFiles addObject:[MXLogger crashLog]]; - } - for (NSString *logFile in logFiles) { - NSData *logContent = [NSData dataWithContentsOfFile:logFile]; - [sharedInstance->mailComposer addAttachmentData:logContent mimeType:@"text/plain" fileName:[logFile lastPathComponent]]; - } - sharedInstance->mailComposer.mailComposeDelegate = sharedInstance; - [controller presentViewController:sharedInstance->mailComposer animated:YES completion:nil]; - } -} - -#pragma mark - MFMailComposeViewControllerDelegate delegate -- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { - // Do not send this crash anymore - [MXLogger deleteCrashLog]; - [controller dismissViewControllerAnimated:NO completion:nil]; -} - -@end diff --git a/matrixConsole/ViewController/AuthenticationViewController.h b/matrixConsole/ViewController/AuthenticationViewController.h index ab8527797..606f7c731 100644 --- a/matrixConsole/ViewController/AuthenticationViewController.h +++ b/matrixConsole/ViewController/AuthenticationViewController.h @@ -1,5 +1,5 @@ /* - Copyright 2014 OpenMarket Ltd + 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. @@ -14,11 +14,11 @@ limitations under the License. */ -#import "MXCViewController.h" +#import #import "AuthInputsView.h" -@interface AuthenticationViewController : MXCViewController +@interface AuthenticationViewController : MXKViewController @end diff --git a/matrixConsole/ViewController/AuthenticationViewController.m b/matrixConsole/ViewController/AuthenticationViewController.m index 46aedf46b..68af277ed 100644 --- a/matrixConsole/ViewController/AuthenticationViewController.m +++ b/matrixConsole/ViewController/AuthenticationViewController.m @@ -1,5 +1,5 @@ /* - Copyright 2014 OpenMarket Ltd + 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. @@ -20,6 +20,8 @@ #import "AppDelegate.h" #import "MXCRegistrationWebView.h" +#import "RageShakeManager.h" + @interface AuthenticationViewController () { // Current request in progress MXHTTPOperation *mxCurrentOperation; @@ -60,7 +62,7 @@ @property (weak, nonatomic) IBOutlet UIButton *submitButton; @property (weak, nonatomic) IBOutlet UIButton *authSwitchButton; -@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator; +@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *authenticationActivityIndicator; @property (weak, nonatomic) IBOutlet UILabel *noFlowLabel; @property (weak, nonatomic) IBOutlet UIButton *retryButton; @@ -107,6 +109,9 @@ _homeServerTextField.text = [[MatrixSDKHandler sharedHandler] homeServerURL]; _identityServerTextField.text = [[MatrixSDKHandler sharedHandler] identityServerURL]; + // Set rageShake handler + self.rageShakeManager = [RageShakeManager sharedManager]; + // Set initial auth type _authType = AuthenticationTypeLogin; } @@ -242,7 +247,7 @@ [mxCurrentOperation cancel]; mxCurrentOperation = nil; - [_activityIndicator startAnimating]; + [_authenticationActivityIndicator startAnimating]; self.selectedFlow = nil; if (_authType == AuthenticationTypeLogin) { mxCurrentOperation = [mxHandler.mxRestClient getLoginFlow:^(NSArray *flows) { @@ -265,7 +270,7 @@ } - (void)handleHomeServerFlows:(NSArray *)flows { - [_activityIndicator stopAnimating]; + [_authenticationActivityIndicator stopAnimating]; [supportedFlows removeAllObjects]; for (MXLoginFlow* flow in flows) { @@ -315,7 +320,7 @@ return; } - [_activityIndicator stopAnimating]; + [_authenticationActivityIndicator stopAnimating]; // Alert user NSString *title = [error.userInfo valueForKey:NSLocalizedFailureReasonErrorKey]; @@ -373,13 +378,13 @@ if (matrix.mxRestClient) { // Disable user interaction to prevent multiple requests [self setUserInteractionEnabled:NO]; - [_activityIndicator startAnimating]; + [_authenticationActivityIndicator startAnimating]; if (_authType == AuthenticationTypeLogin) { if ([_selectedFlow.type isEqualToString:kMXLoginFlowTypePassword]) { [matrix.mxRestClient loginWithUser:matrix.userLogin andPassword:_authInputsPasswordBasedView.passWordTextField.text success:^(MXCredentials *credentials){ - [_activityIndicator stopAnimating]; + [_authenticationActivityIndicator stopAnimating]; // Report credentials [matrix setUserId:credentials.userId]; @@ -422,7 +427,7 @@ } - (void)onFailureDuringAuthRequest:(NSError *)error { - [_activityIndicator stopAnimating]; + [_authenticationActivityIndicator stopAnimating]; [self setUserInteractionEnabled:YES]; NSLog(@"[AuthenticationVC] Auth request failed: %@", error); diff --git a/matrixConsole/ViewController/ContactDetailsViewController.h b/matrixConsole/ViewController/ContactDetailsViewController.h index 735b75bc0..3400e0cd6 100644 --- a/matrixConsole/ViewController/ContactDetailsViewController.h +++ b/matrixConsole/ViewController/ContactDetailsViewController.h @@ -1,5 +1,5 @@ /* - Copyright 2014 OpenMarket Ltd + 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. @@ -14,11 +14,11 @@ limitations under the License. */ -#import "MXCTableViewController.h" +#import #import "MXCContact.h" -@interface ContactDetailsViewController : MXCTableViewController +@interface ContactDetailsViewController : MXKTableViewController @property (strong, nonatomic) MXCContact* contact; @end diff --git a/matrixConsole/ViewController/ContactDetailsViewController.m b/matrixConsole/ViewController/ContactDetailsViewController.m index a87c2ec7e..27915a71b 100644 --- a/matrixConsole/ViewController/ContactDetailsViewController.m +++ b/matrixConsole/ViewController/ContactDetailsViewController.m @@ -1,5 +1,5 @@ /* - Copyright 2014 OpenMarket Ltd + 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. @@ -20,6 +20,8 @@ #import "MatrixSDKHandler.h" +#import "RageShakeManager.h" + @interface ContactDetailsViewController () { NSArray* matrixIDs; } @@ -45,6 +47,9 @@ self.tableView.separatorColor = [UIColor clearColor]; self.tableView.rowHeight = 44; self.tableView.allowsSelection = NO; + + // Set rageShake handler + self.rageShakeManager = [RageShakeManager sharedManager]; } - (void)viewWillAppear:(BOOL)animated { diff --git a/matrixConsole/ViewController/ContactsViewController.h b/matrixConsole/ViewController/ContactsViewController.h index aebb0e937..ae7e64308 100644 --- a/matrixConsole/ViewController/ContactsViewController.h +++ b/matrixConsole/ViewController/ContactsViewController.h @@ -1,5 +1,5 @@ /* - Copyright 2014 OpenMarket Ltd + 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. @@ -14,7 +14,7 @@ limitations under the License. */ -#import "MXCViewController.h" +#import // SMS #import @@ -22,7 +22,7 @@ #import "SectionedContacts.h" -@interface ContactsViewController : MXCViewController { +@interface ContactsViewController : MXKViewController { NSArray* collationTitles; } diff --git a/matrixConsole/ViewController/ContactsViewController.m b/matrixConsole/ViewController/ContactsViewController.m index e833c4df1..974c6f66b 100644 --- a/matrixConsole/ViewController/ContactsViewController.m +++ b/matrixConsole/ViewController/ContactsViewController.m @@ -1,5 +1,5 @@ /* - Copyright 2014 OpenMarket Ltd + 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. @@ -16,11 +16,9 @@ #import "ContactsViewController.h" -// SDK api -#import "MatrixSDKHandler.h" - // application info #import "AppDelegate.h" +#import "MatrixSDKHandler.h" // contacts management #import "ContactManager.h" @@ -34,6 +32,8 @@ // settings #import "AppSettings.h" +#import "RageShakeManager.h" + // #import "ContactDetailsViewController.h" @@ -67,7 +67,6 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl @property (strong, nonatomic) MXKAlert *allowContactSyncAlert; @property (weak, nonatomic) IBOutlet UITableView* tableView; @property (weak, nonatomic) IBOutlet UISegmentedControl* contactsControls; -@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator; @end @implementation ContactsViewController @@ -81,9 +80,6 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl // global init displayMatrixUsers = (0 == self.contactsControls.selectedSegmentIndex); matrixUserByMatrixID = [[NSMutableDictionary alloc] init]; - - // event listener - [[MatrixSDKHandler sharedHandler] addObserver:self forKeyPath:@"status" options:0 context:nil]; // add the search icon on the right // need to add more buttons ? @@ -91,6 +87,9 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl self.navigationItem.rightBarButtonItems = @[searchButton]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onContactsRefresh:) name:kContactManagerContactsListRefreshNotification object:nil]; + + // Set rageShake handler + self.rageShakeManager = [RageShakeManager sharedManager]; } - (void)viewWillAppear:(BOOL)animated { @@ -113,17 +112,6 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; } -- (void)startActivityIndicator { - [_activityIndicator.layer setCornerRadius:5]; - _activityIndicator.hidden = NO; - [_activityIndicator startAnimating]; -} - -- (void)stopActivityIndicator { - [_activityIndicator stopAnimating]; - _activityIndicator.hidden = YES; -} - - (void)scrollToTop { // stop any scrolling effect [UIView setAnimationsEnabled:NO]; @@ -151,6 +139,34 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl [self.tableView reloadData]; } +- (void)refreshMatrixUsers { + if (displayMatrixUsers) { + if (contactsSearchBar) { + [self updateSectionedMatrixContacts]; + latestSearchedPattern = nil; + [self searchBar:contactsSearchBar textDidChange:contactsSearchBar.text]; + } else { + [self.tableView reloadData]; + } + } +} + +#pragma mark - overridden MXKTableViewController methods + +- (void)setMxSession:(MXSession *)session { + + [super setMxSession:session]; + + [self refreshMatrixUsers]; +} + +- (void)didMatrixSessionStateChange { + + [super didMatrixSessionStateChange]; + + [self refreshMatrixUsers]; +} + #pragma mark - Keyboard handling - (void)onKeyboardWillShow:(NSNotification *)notif { @@ -242,15 +258,14 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl } - (void)updateSectionedMatrixContacts { - // Check whether mxSession is available in matrix handler - MatrixSDKHandler *mxHandler = [MatrixSDKHandler sharedHandler]; - if (!mxHandler.mxSession) { + // Check whether mxSession is available + if (!self.mxSession) { [self startActivityIndicator]; sectionedMatrixContacts = nil; } else { [self stopActivityIndicator]; - NSArray* usersIDs = [mxHandler oneToOneRoomMemberIDs]; + NSArray* usersIDs = [self oneToOneRoomMemberIDs]; // return a MatrixIDs list of 1:1 room members NSMutableArray* knownUserIDs = [[matrixUserByMatrixID allKeys] mutableCopy]; @@ -260,7 +275,7 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl // it could save thumbnail downloads for(NSString* userID in usersIDs) { // - MXUser* user = [mxHandler.mxSession userWithUserId:userID]; + MXUser* user = [self.mxSession userWithUserId:userID]; // sanity check if (user) { @@ -417,14 +432,13 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl __weak typeof(self) weakSelf = self; NSArray* matrixIDs = contact.matrixIdentifiers; + MatrixSDKHandler *mxHandler = [MatrixSDKHandler sharedHandler]; // matrix user ? if (matrixIDs.count) { - MatrixSDKHandler* mxHandler = [MatrixSDKHandler sharedHandler]; - // display only if the mxSession is available in matrix SDK handler - if (mxHandler.mxSession) { + if (self.mxSession) { // only 1 matrix ID if (matrixIDs.count == 1) { NSString* matrixID = [matrixIDs objectAtIndex:0]; @@ -519,25 +533,6 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl } } - -#pragma mark - KVO - -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if ([@"status" isEqualToString:keyPath]) { - dispatch_async(dispatch_get_main_queue(), ^{ - if (displayMatrixUsers) { - if (contactsSearchBar) { - [self updateSectionedMatrixContacts]; - latestSearchedPattern = nil; - [self searchBar:contactsSearchBar textDidChange:contactsSearchBar.text]; - } else { - [self.tableView reloadData]; - } - } - }); - } -} - #pragma mark - Actions - (void)onContactsRefresh:(NSNotification *)notif { @@ -545,7 +540,7 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl sectionedLocalContacts = nil; // there is an user id - if ([[MatrixSDKHandler sharedHandler] userId]) { + if (self.mxSession && self.mxSession.myUser.userId) { [self updateSectionedLocalContacts]; // if (!displayMatrixUsers) { @@ -759,4 +754,34 @@ NSString *const kInvitationMessage = @"I'd like to chat with you with matrix. Pl } } +#pragma mark - Matrix session handling + +// return a MatrixIDs list of 1:1 room members +- (NSArray*)oneToOneRoomMemberIDs { + + NSMutableArray* matrixIDs = [[NSMutableArray alloc] init]; + + if (self.mxSession) { + for (MXRoom *mxRoom in self.mxSession.rooms) { + + NSArray* membersList = [mxRoom.state members]; + + // keep only 1:1 chat + if ([mxRoom.state members].count <= 2) { + + for (MXRoomMember* member in membersList) { + // not myself + if (![member.userId isEqualToString:self.mxSession.myUser.userId]) { + if ([matrixIDs indexOfObject:member.userId] == NSNotFound) { + [matrixIDs addObject:member.userId]; + } + } + } + } + } + } + + return matrixIDs; +} + @end diff --git a/matrixConsole/ViewController/HomeViewController.h b/matrixConsole/ViewController/HomeViewController.h index fc11f089c..3f185a121 100644 --- a/matrixConsole/ViewController/HomeViewController.h +++ b/matrixConsole/ViewController/HomeViewController.h @@ -1,5 +1,5 @@ /* - Copyright 2014 OpenMarket Ltd + 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. @@ -14,9 +14,9 @@ limitations under the License. */ -#import "MXCTableViewController.h" +#import -@interface HomeViewController : MXCTableViewController +@interface HomeViewController : MXKTableViewController @end diff --git a/matrixConsole/ViewController/HomeViewController.m b/matrixConsole/ViewController/HomeViewController.m index 4b6ed04e2..3d4560686 100644 --- a/matrixConsole/ViewController/HomeViewController.m +++ b/matrixConsole/ViewController/HomeViewController.m @@ -1,5 +1,5 @@ /* - Copyright 2014 OpenMarket Ltd + 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. @@ -20,6 +20,8 @@ #import "AppDelegate.h" #import "PublicRoomTableCell.h" +#import "RageShakeManager.h" + @interface HomeViewController () { NSArray *publicRooms; @@ -68,6 +70,9 @@ _joinRoomSectionLabel.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]; _joinRoomBtn.enabled = NO; + // Set rageShake handler + self.rageShakeManager = [RageShakeManager sharedManager]; + // Init publicRooms = nil; highlightedPublicRooms = @[@"#matrix:matrix.org", @"#matrix-dev:matrix.org", @"#matrix-fr:matrix.org"]; // Add here a room name to highlight its display in public room list diff --git a/matrixConsole/ViewController/MXCTableViewController.h b/matrixConsole/ViewController/MXCTableViewController.h deleted file mode 100644 index 149c2d6ac..000000000 --- a/matrixConsole/ViewController/MXCTableViewController.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - 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. - */ - -#import - -#import "AFNetworkReachabilityManager.h" - -/** - * MXCTableViewController extends UITableViewController for the following points: - * - support rage shake mechanism - * - update navigation bar tintColor according to network reachability - */ - -@interface MXCTableViewController : UITableViewController - -@end - diff --git a/matrixConsole/ViewController/MXCTableViewController.m b/matrixConsole/ViewController/MXCTableViewController.m deleted file mode 100644 index 48ef93b01..000000000 --- a/matrixConsole/ViewController/MXCTableViewController.m +++ /dev/null @@ -1,110 +0,0 @@ -/* - 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. - */ -#import "MXCTableViewController.h" - -#import "RageShakableUIResponder.h" - -@interface MXCTableViewController () { - id mxcTableViewControllerReachabilityObserver; -} -@end - -@implementation MXCTableViewController - -- (void)viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; - - [RageShakableUIResponder cancel:self]; - - if (self.navigationController) { - // The navigation bar tintColor depends on reachability status - Register reachability observer - __weak typeof(self) weakSelf = self; - mxcTableViewControllerReachabilityObserver = [[NSNotificationCenter defaultCenter] addObserverForName:AFNetworkingReachabilityDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) { - [weakSelf onReachabilityStatusChange]; - }]; - // Force update - [self onReachabilityStatusChange]; - } -} - -- (void)viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; - - [[NSNotificationCenter defaultCenter] removeObserver:mxcTableViewControllerReachabilityObserver]; - [RageShakableUIResponder cancel:self]; -} - -#pragma mark - Reachability monitoring - -- (void)onReachabilityStatusChange { - // Retrieve the current reachability status - AFNetworkReachabilityManager *reachabilityManager = [AFNetworkReachabilityManager sharedManager]; - AFNetworkReachabilityStatus status = reachabilityManager.networkReachabilityStatus; - - // Retrieve the main navigation controller if the current view controller is embedded inside a split view controller. - UINavigationController *mainNavigationController = nil; - if (self.splitViewController) { - mainNavigationController = self.navigationController; - UIViewController *parentViewController = self.parentViewController; - while (parentViewController) { - if (parentViewController.navigationController) { - mainNavigationController = parentViewController.navigationController; - parentViewController = parentViewController.parentViewController; - } else { - break; - } - } - } - - // Update navigationBar tintColor - if (status == AFNetworkReachabilityStatusNotReachable) { - self.navigationController.navigationBar.barTintColor = [UIColor redColor]; - if (mainNavigationController) { - mainNavigationController.navigationBar.barTintColor = [UIColor redColor]; - } - } else if (status == AFNetworkReachabilityStatusReachableViaWiFi || status == AFNetworkReachabilityStatusReachableViaWWAN) { - self.navigationController.navigationBar.barTintColor = nil; - if (mainNavigationController) { - mainNavigationController.navigationBar.barTintColor = nil; - } - } -} - -#pragma mark - Rage shake handling - -- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { - if (motion == UIEventSubtypeMotionShake) { - [RageShakableUIResponder startShaking:self]; - } -} - -- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { - [self motionEnded:motion withEvent:event]; -} - -- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { - if (motion == UIEventSubtypeMotionShake) { - [RageShakableUIResponder stopShaking:self]; - } -} - -- (BOOL)canBecomeFirstResponder { - return YES; -} - -@end - - diff --git a/matrixConsole/ViewController/MXCViewController.h b/matrixConsole/ViewController/MXCViewController.h deleted file mode 100644 index 2d985ae62..000000000 --- a/matrixConsole/ViewController/MXCViewController.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - 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. - */ - -#import - -#import "AFNetworkReachabilityManager.h" - -/** - * MXCViewController extends UIViewController for the following points: - * - support rage shake mechanism - * - update navigation bar tintColor according to network reachability - */ - -@interface MXCViewController : UIViewController - -@end - diff --git a/matrixConsole/ViewController/MXCViewController.m b/matrixConsole/ViewController/MXCViewController.m deleted file mode 100644 index 68d159b87..000000000 --- a/matrixConsole/ViewController/MXCViewController.m +++ /dev/null @@ -1,110 +0,0 @@ -/* - 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. - */ -#import "MXCViewController.h" - -#import "RageShakableUIResponder.h" - -@interface MXCViewController () { - id mxcViewControllerReachabilityObserver; -} -@end - -@implementation MXCViewController - -- (void)viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; - - [RageShakableUIResponder cancel:self]; - - if (self.navigationController) { - // The navigation bar tintColor depends on reachability status - Register reachability observer - __weak typeof(self) weakSelf = self; - mxcViewControllerReachabilityObserver = [[NSNotificationCenter defaultCenter] addObserverForName:AFNetworkingReachabilityDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) { - [weakSelf onReachabilityStatusChange]; - }]; - // Force update - [self onReachabilityStatusChange]; - } -} - -- (void)viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; - - [[NSNotificationCenter defaultCenter] removeObserver:mxcViewControllerReachabilityObserver]; - [RageShakableUIResponder cancel:self]; -} - -#pragma mark - Reachability monitoring - -- (void)onReachabilityStatusChange { - // Retrieve the current reachability status - AFNetworkReachabilityManager *reachabilityManager = [AFNetworkReachabilityManager sharedManager]; - AFNetworkReachabilityStatus status = reachabilityManager.networkReachabilityStatus; - - // Retrieve the main navigation controller if the current view controller is embedded inside a split view controller. - UINavigationController *mainNavigationController = nil; - if (self.splitViewController) { - mainNavigationController = self.navigationController; - UIViewController *parentViewController = self.parentViewController; - while (parentViewController) { - if (parentViewController.navigationController) { - mainNavigationController = parentViewController.navigationController; - parentViewController = parentViewController.parentViewController; - } else { - break; - } - } - } - - // Update navigationBar tintColor - if (status == AFNetworkReachabilityStatusNotReachable) { - self.navigationController.navigationBar.barTintColor = [UIColor redColor]; - if (mainNavigationController) { - mainNavigationController.navigationBar.barTintColor = [UIColor redColor]; - } - } else if (status == AFNetworkReachabilityStatusReachableViaWiFi || status == AFNetworkReachabilityStatusReachableViaWWAN) { - self.navigationController.navigationBar.barTintColor = nil; - if (mainNavigationController) { - mainNavigationController.navigationBar.barTintColor = nil; - } - } -} - -#pragma mark - Rage shake handling - -- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { - if (motion == UIEventSubtypeMotionShake) { - [RageShakableUIResponder startShaking:self]; - } -} - -- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { - [self motionEnded:motion withEvent:event]; -} - -- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { - if (motion == UIEventSubtypeMotionShake) { - [RageShakableUIResponder stopShaking:self]; - } -} - -- (BOOL)canBecomeFirstResponder { - return YES; -} - -@end - - diff --git a/matrixConsole/ViewController/MasterTabBarController.m b/matrixConsole/ViewController/MasterTabBarController.m index 171f0131c..4f2bf0595 100644 --- a/matrixConsole/ViewController/MasterTabBarController.m +++ b/matrixConsole/ViewController/MasterTabBarController.m @@ -20,12 +20,16 @@ #import "RecentsViewController.h" #import "RecentListDataSource.h" +#import "ContactsViewController.h" + #import "SettingsViewController.h" @interface MasterTabBarController () { UINavigationController *recentsNavigationController; RecentsViewController *recentsViewController; + ContactsViewController *contactsViewController; + SettingsViewController *settingsViewController; UIImagePickerController *mediaPicker; @@ -62,6 +66,17 @@ } } + // 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; + } + } + } + // Retrieve the settings view controller UIViewController* settings = [self.viewControllers objectAtIndex:TABBAR_SETTINGS_INDEX]; if ([settings isKindOfClass:[UINavigationController class]]) { @@ -74,7 +89,7 @@ } // Sanity check - NSAssert(recentsViewController && settingsViewController, @"Something wrong in Main.storyboard"); + NSAssert(recentsViewController && contactsViewController && settingsViewController, @"Something wrong in Main.storyboard"); // Register session state observer sessionStateObserver = [[NSNotificationCenter defaultCenter] addObserverForName:MXSessionStateDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { @@ -87,6 +102,9 @@ MXKRecentListDataSource *listDataSource = [[RecentListDataSource alloc] initWithMatrixSession:mxSession]; [recentsViewController displayList:listDataSource]; + // Update contacts tab + contactsViewController.mxSession = mxSession; + // Update settings tab settingsViewController.mxSession = mxSession; } @@ -109,6 +127,7 @@ - (void)dealloc { recentsNavigationController = nil; recentsViewController = nil; + contactsViewController = nil; settingsViewController = nil; [self dismissMediaPicker]; @@ -136,6 +155,9 @@ - (void)showAuthenticationScreen { [self restoreInitialDisplay]; + // Reset mxSession information in contacts + contactsViewController.mxSession = nil; + // Reset user's information in settings settingsViewController.mxSession = nil; diff --git a/matrixConsole/ViewController/MemberViewController.h b/matrixConsole/ViewController/MemberViewController.h index 58d988798..6b0c61d6d 100644 --- a/matrixConsole/ViewController/MemberViewController.h +++ b/matrixConsole/ViewController/MemberViewController.h @@ -1,5 +1,5 @@ /* - Copyright 2014 OpenMarket Ltd + 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. @@ -14,11 +14,11 @@ limitations under the License. */ -#import "MXCTableViewController.h" +#import #import "MatrixSDKHandler.h" -@interface MemberViewController : MXCTableViewController +@interface MemberViewController : MXKTableViewController @property (strong, nonatomic) MXRoomMember *mxRoomMember; @property (strong, nonatomic) MXRoom *mxRoom; diff --git a/matrixConsole/ViewController/MemberViewController.m b/matrixConsole/ViewController/MemberViewController.m index 660293ebb..dad5eabc6 100644 --- a/matrixConsole/ViewController/MemberViewController.m +++ b/matrixConsole/ViewController/MemberViewController.m @@ -1,5 +1,5 @@ /* - Copyright 2014 OpenMarket Ltd + 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. @@ -19,6 +19,8 @@ #import "AppDelegate.h" #import "RoomMemberActionsCell.h" +#import "RageShakeManager.h" + @interface MemberViewController () { NSString *thumbnailURL; MXKMediaLoader* imageLoader; @@ -57,6 +59,9 @@ buttonsTitles = [[NSMutableArray alloc] init]; + // Set rageShake handler + self.rageShakeManager = [RageShakeManager sharedManager]; + // ignore useless update if (_mxRoomMember) { [self updateMemberInfo]; @@ -233,6 +238,7 @@ // ignore useless update if (![_mxRoomMember.userId isEqualToString:aRoomMember.userId]) { _mxRoomMember = aRoomMember; + [self updateMemberInfo]; } }