diff --git a/Vector.xcodeproj/project.pbxproj b/Vector.xcodeproj/project.pbxproj index e3b187038..3e2b04cd0 100644 --- a/Vector.xcodeproj/project.pbxproj +++ b/Vector.xcodeproj/project.pbxproj @@ -23,14 +23,34 @@ F094AA2E1B78E42600B1FBBF /* countryCodes.plist in Resources */ = {isa = PBXBuildFile; fileRef = F094AA141B78E42600B1FBBF /* countryCodes.plist */; }; F094AA2F1B78E42600B1FBBF /* AccountDetailsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA171B78E42600B1FBBF /* AccountDetailsViewController.m */; }; F094AA301B78E42600B1FBBF /* AuthenticationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA191B78E42600B1FBBF /* AuthenticationViewController.m */; }; - F094AA311B78E42600B1FBBF /* ContactsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA1B1B78E42600B1FBBF /* ContactsViewController.m */; }; F094AA321B78E42600B1FBBF /* GlobalNotificationSettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA1D1B78E42600B1FBBF /* GlobalNotificationSettingsViewController.m */; }; - F094AA331B78E42600B1FBBF /* HomeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA1F1B78E42600B1FBBF /* HomeViewController.m */; }; F094AA341B78E42600B1FBBF /* MasterTabBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA211B78E42600B1FBBF /* MasterTabBarController.m */; }; F094AA351B78E42600B1FBBF /* RecentsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA231B78E42600B1FBBF /* RecentsViewController.m */; }; F094AA361B78E42600B1FBBF /* RoomMembersViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA251B78E42600B1FBBF /* RoomMembersViewController.m */; }; F094AA371B78E42600B1FBBF /* RoomViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA271B78E42600B1FBBF /* RoomViewController.m */; }; F094AA381B78E42600B1FBBF /* SettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F094AA291B78E42600B1FBBF /* SettingsViewController.m */; }; + F0DD7D4C1B7AA8C900C4BE02 /* attach.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D1C1B7AA8C900C4BE02 /* attach.png */; }; + F0DD7D4D1B7AA8C900C4BE02 /* attach@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D1D1B7AA8C900C4BE02 /* attach@2x.png */; }; + F0DD7D601B7AA8C900C4BE02 /* hide.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D301B7AA8C900C4BE02 /* hide.png */; }; + F0DD7D611B7AA8C900C4BE02 /* hide@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D311B7AA8C900C4BE02 /* hide@2x.png */; }; + F0DD7D641B7AA8C900C4BE02 /* logo.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D341B7AA8C900C4BE02 /* logo.png */; }; + F0DD7D651B7AA8C900C4BE02 /* logo@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D351B7AA8C900C4BE02 /* logo@2x.png */; }; + F0DD7D661B7AA8C900C4BE02 /* members.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D361B7AA8C900C4BE02 /* members.png */; }; + F0DD7D671B7AA8C900C4BE02 /* members@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D371B7AA8C900C4BE02 /* members@2x.png */; }; + F0DD7D681B7AA8C900C4BE02 /* menu.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D381B7AA8C900C4BE02 /* menu.png */; }; + F0DD7D691B7AA8C900C4BE02 /* menu@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D391B7AA8C900C4BE02 /* menu@2x.png */; }; + F0DD7D6C1B7AA8C900C4BE02 /* search.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D3C1B7AA8C900C4BE02 /* search.png */; }; + F0DD7D6D1B7AA8C900C4BE02 /* search@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D3D1B7AA8C900C4BE02 /* search@2x.png */; }; + F0DD7D721B7AA8C900C4BE02 /* tab_settings.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D421B7AA8C900C4BE02 /* tab_settings.png */; }; + F0DD7D731B7AA8C900C4BE02 /* tab_settings@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D431B7AA8C900C4BE02 /* tab_settings@2x.png */; }; + F0DD7D741B7AA8C900C4BE02 /* typing.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D441B7AA8C900C4BE02 /* typing.png */; }; + F0DD7D751B7AA8C900C4BE02 /* typing@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D451B7AA8C900C4BE02 /* typing@2x.png */; }; + F0DD7D781B7AA8C900C4BE02 /* video.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D481B7AA8C900C4BE02 /* video.png */; }; + F0DD7D791B7AA8C900C4BE02 /* video@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D491B7AA8C900C4BE02 /* video@2x.png */; }; + F0DD7D7A1B7AA8C900C4BE02 /* voip.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D4A1B7AA8C900C4BE02 /* voip.png */; }; + F0DD7D7B1B7AA8C900C4BE02 /* voip@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D4B1B7AA8C900C4BE02 /* voip@2x.png */; }; + F0DD7D7E1B7AAA3C00C4BE02 /* icon_users.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D7C1B7AAA3C00C4BE02 /* icon_users.png */; }; + F0DD7D7F1B7AAA3C00C4BE02 /* icon_users@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0DD7D7D1B7AAA3C00C4BE02 /* icon_users@2x.png */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -71,12 +91,8 @@ F094AA171B78E42600B1FBBF /* AccountDetailsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AccountDetailsViewController.m; sourceTree = ""; }; F094AA181B78E42600B1FBBF /* AuthenticationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AuthenticationViewController.h; sourceTree = ""; }; F094AA191B78E42600B1FBBF /* AuthenticationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AuthenticationViewController.m; sourceTree = ""; }; - F094AA1A1B78E42600B1FBBF /* ContactsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContactsViewController.h; sourceTree = ""; }; - F094AA1B1B78E42600B1FBBF /* ContactsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContactsViewController.m; sourceTree = ""; }; F094AA1C1B78E42600B1FBBF /* GlobalNotificationSettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GlobalNotificationSettingsViewController.h; sourceTree = ""; }; F094AA1D1B78E42600B1FBBF /* GlobalNotificationSettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GlobalNotificationSettingsViewController.m; sourceTree = ""; }; - F094AA1E1B78E42600B1FBBF /* HomeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HomeViewController.h; sourceTree = ""; }; - F094AA1F1B78E42600B1FBBF /* HomeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HomeViewController.m; sourceTree = ""; }; F094AA201B78E42600B1FBBF /* MasterTabBarController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MasterTabBarController.h; sourceTree = ""; }; F094AA211B78E42600B1FBBF /* MasterTabBarController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MasterTabBarController.m; sourceTree = ""; }; F094AA221B78E42600B1FBBF /* RecentsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RecentsViewController.h; sourceTree = ""; }; @@ -87,6 +103,28 @@ F094AA271B78E42600B1FBBF /* RoomViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomViewController.m; sourceTree = ""; }; F094AA281B78E42600B1FBBF /* SettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingsViewController.h; sourceTree = ""; }; F094AA291B78E42600B1FBBF /* SettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingsViewController.m; sourceTree = ""; }; + F0DD7D1C1B7AA8C900C4BE02 /* attach.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = attach.png; sourceTree = ""; }; + F0DD7D1D1B7AA8C900C4BE02 /* attach@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "attach@2x.png"; sourceTree = ""; }; + F0DD7D301B7AA8C900C4BE02 /* hide.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = hide.png; sourceTree = ""; }; + F0DD7D311B7AA8C900C4BE02 /* hide@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "hide@2x.png"; sourceTree = ""; }; + F0DD7D341B7AA8C900C4BE02 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = ""; }; + F0DD7D351B7AA8C900C4BE02 /* logo@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "logo@2x.png"; sourceTree = ""; }; + F0DD7D361B7AA8C900C4BE02 /* members.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = members.png; sourceTree = ""; }; + F0DD7D371B7AA8C900C4BE02 /* members@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "members@2x.png"; sourceTree = ""; }; + F0DD7D381B7AA8C900C4BE02 /* menu.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = menu.png; sourceTree = ""; }; + F0DD7D391B7AA8C900C4BE02 /* menu@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "menu@2x.png"; sourceTree = ""; }; + F0DD7D3C1B7AA8C900C4BE02 /* search.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = search.png; sourceTree = ""; }; + F0DD7D3D1B7AA8C900C4BE02 /* search@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "search@2x.png"; sourceTree = ""; }; + F0DD7D421B7AA8C900C4BE02 /* tab_settings.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tab_settings.png; sourceTree = ""; }; + F0DD7D431B7AA8C900C4BE02 /* tab_settings@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tab_settings@2x.png"; sourceTree = ""; }; + F0DD7D441B7AA8C900C4BE02 /* typing.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = typing.png; sourceTree = ""; }; + F0DD7D451B7AA8C900C4BE02 /* typing@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "typing@2x.png"; sourceTree = ""; }; + F0DD7D481B7AA8C900C4BE02 /* video.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = video.png; sourceTree = ""; }; + F0DD7D491B7AA8C900C4BE02 /* video@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "video@2x.png"; sourceTree = ""; }; + F0DD7D4A1B7AA8C900C4BE02 /* voip.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = voip.png; sourceTree = ""; }; + F0DD7D4B1B7AA8C900C4BE02 /* voip@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "voip@2x.png"; sourceTree = ""; }; + F0DD7D7C1B7AAA3C00C4BE02 /* icon_users.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon_users.png; sourceTree = ""; }; + F0DD7D7D1B7AAA3C00C4BE02 /* icon_users@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_users@2x.png"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -203,20 +241,13 @@ F094AA0A1B78E42600B1FBBF /* Assets */ = { isa = PBXGroup; children = ( + F0DD7D1B1B7AA8C900C4BE02 /* Images */, F094AA0B1B78E42600B1FBBF /* Localizable.strings */, F094AA0D1B78E42600B1FBBF /* Vector.strings */, - F094AA0F1B78E42600B1FBBF /* Images */, ); path = Assets; sourceTree = ""; }; - F094AA0F1B78E42600B1FBBF /* Images */ = { - isa = PBXGroup; - children = ( - ); - path = Images; - sourceTree = ""; - }; F094AA101B78E42600B1FBBF /* Model */ = { isa = PBXGroup; children = ( @@ -241,12 +272,8 @@ F094AA171B78E42600B1FBBF /* AccountDetailsViewController.m */, F094AA181B78E42600B1FBBF /* AuthenticationViewController.h */, F094AA191B78E42600B1FBBF /* AuthenticationViewController.m */, - F094AA1A1B78E42600B1FBBF /* ContactsViewController.h */, - F094AA1B1B78E42600B1FBBF /* ContactsViewController.m */, F094AA1C1B78E42600B1FBBF /* GlobalNotificationSettingsViewController.h */, F094AA1D1B78E42600B1FBBF /* GlobalNotificationSettingsViewController.m */, - F094AA1E1B78E42600B1FBBF /* HomeViewController.h */, - F094AA1F1B78E42600B1FBBF /* HomeViewController.m */, F094AA201B78E42600B1FBBF /* MasterTabBarController.h */, F094AA211B78E42600B1FBBF /* MasterTabBarController.m */, F094AA221B78E42600B1FBBF /* RecentsViewController.h */, @@ -261,6 +288,35 @@ path = ViewController; sourceTree = ""; }; + F0DD7D1B1B7AA8C900C4BE02 /* Images */ = { + isa = PBXGroup; + children = ( + F0DD7D7C1B7AAA3C00C4BE02 /* icon_users.png */, + F0DD7D7D1B7AAA3C00C4BE02 /* icon_users@2x.png */, + F0DD7D1C1B7AA8C900C4BE02 /* attach.png */, + F0DD7D1D1B7AA8C900C4BE02 /* attach@2x.png */, + F0DD7D301B7AA8C900C4BE02 /* hide.png */, + F0DD7D311B7AA8C900C4BE02 /* hide@2x.png */, + F0DD7D341B7AA8C900C4BE02 /* logo.png */, + F0DD7D351B7AA8C900C4BE02 /* logo@2x.png */, + F0DD7D361B7AA8C900C4BE02 /* members.png */, + F0DD7D371B7AA8C900C4BE02 /* members@2x.png */, + F0DD7D381B7AA8C900C4BE02 /* menu.png */, + F0DD7D391B7AA8C900C4BE02 /* menu@2x.png */, + F0DD7D3C1B7AA8C900C4BE02 /* search.png */, + F0DD7D3D1B7AA8C900C4BE02 /* search@2x.png */, + F0DD7D421B7AA8C900C4BE02 /* tab_settings.png */, + F0DD7D431B7AA8C900C4BE02 /* tab_settings@2x.png */, + F0DD7D441B7AA8C900C4BE02 /* typing.png */, + F0DD7D451B7AA8C900C4BE02 /* typing@2x.png */, + F0DD7D481B7AA8C900C4BE02 /* video.png */, + F0DD7D491B7AA8C900C4BE02 /* video@2x.png */, + F0DD7D4A1B7AA8C900C4BE02 /* voip.png */, + F0DD7D4B1B7AA8C900C4BE02 /* voip@2x.png */, + ); + path = Images; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -343,12 +399,34 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + F0DD7D651B7AA8C900C4BE02 /* logo@2x.png in Resources */, + F0DD7D611B7AA8C900C4BE02 /* hide@2x.png in Resources */, + F0DD7D751B7AA8C900C4BE02 /* typing@2x.png in Resources */, + F0DD7D671B7AA8C900C4BE02 /* members@2x.png in Resources */, + F0DD7D721B7AA8C900C4BE02 /* tab_settings.png in Resources */, + F0DD7D7B1B7AA8C900C4BE02 /* voip@2x.png in Resources */, F094AA2E1B78E42600B1FBBF /* countryCodes.plist in Resources */, + F0DD7D7E1B7AAA3C00C4BE02 /* icon_users.png in Resources */, F094AA2B1B78E42600B1FBBF /* Localizable.strings in Resources */, + F0DD7D4C1B7AA8C900C4BE02 /* attach.png in Resources */, + F0DD7D691B7AA8C900C4BE02 /* menu@2x.png in Resources */, + F0DD7D731B7AA8C900C4BE02 /* tab_settings@2x.png in Resources */, + F0DD7D641B7AA8C900C4BE02 /* logo.png in Resources */, + F0DD7D7F1B7AAA3C00C4BE02 /* icon_users@2x.png in Resources */, F094A9B41B78D8F000B1FBBF /* Main.storyboard in Resources */, + F0DD7D601B7AA8C900C4BE02 /* hide.png in Resources */, + F0DD7D741B7AA8C900C4BE02 /* typing.png in Resources */, + F0DD7D681B7AA8C900C4BE02 /* menu.png in Resources */, + F0DD7D7A1B7AA8C900C4BE02 /* voip.png in Resources */, F094A9B91B78D8F000B1FBBF /* LaunchScreen.xib in Resources */, F094A9B61B78D8F000B1FBBF /* Images.xcassets in Resources */, + F0DD7D6D1B7AA8C900C4BE02 /* search@2x.png in Resources */, + F0DD7D791B7AA8C900C4BE02 /* video@2x.png in Resources */, + F0DD7D661B7AA8C900C4BE02 /* members.png in Resources */, F094AA061B78E3D400B1FBBF /* Vector-Defaults.plist in Resources */, + F0DD7D781B7AA8C900C4BE02 /* video.png in Resources */, + F0DD7D4D1B7AA8C900C4BE02 /* attach@2x.png in Resources */, + F0DD7D6C1B7AA8C900C4BE02 /* search.png in Resources */, F094AA2C1B78E42600B1FBBF /* Vector.strings in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -401,9 +479,7 @@ buildActionMask = 2147483647; files = ( F094A9AB1B78D8F000B1FBBF /* AppDelegate.m in Sources */, - F094AA311B78E42600B1FBBF /* ContactsViewController.m in Sources */, F094AA2F1B78E42600B1FBBF /* AccountDetailsViewController.m in Sources */, - F094AA331B78E42600B1FBBF /* HomeViewController.m in Sources */, F094AA051B78E3D400B1FBBF /* empty.mm in Sources */, F094AA321B78E42600B1FBBF /* GlobalNotificationSettingsViewController.m in Sources */, F094A9A81B78D8F000B1FBBF /* main.m in Sources */, diff --git a/Vector/API/RageShakeManager.m b/Vector/API/RageShakeManager.m index dad493842..107e2845e 100644 --- a/Vector/API/RageShakeManager.m +++ b/Vector/API/RageShakeManager.m @@ -67,7 +67,7 @@ static RageShakeManager* sharedInstance = nil; - (void)promptCrashReportInViewController:(UIViewController*)viewController { if ([MXLogger crashLog] && [MFMailComposeViewController canSendMail]) { - confirmationAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"bug_report_prompt", @"MatrixConsole", nil) message:nil style:MXKAlertStyleAlert]; + confirmationAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"bug_report_prompt", @"Vector", nil) message:nil style:MXKAlertStyleAlert]; __weak typeof(self) weakSelf = self; [confirmationAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { @@ -110,7 +110,7 @@ static RageShakeManager* sharedInstance = nil; && (([[NSDate date] timeIntervalSince1970] - startShakingTimeStamp) > RAGESHAKEMANAGER_MINIMUM_SHAKING_DURATION)) { if ([responder isKindOfClass:[UIViewController class]] && [MFMailComposeViewController canSendMail]) { - confirmationAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"rage_shake_prompt", @"MatrixConsole", nil) message:nil style:MXKAlertStyleAlert]; + confirmationAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"rage_shake_prompt", @"Vector", nil) message:nil style:MXKAlertStyleAlert]; __weak typeof(self) weakSelf = self; [confirmationAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { diff --git a/Vector/AppDelegate.m b/Vector/AppDelegate.m index 772d56718..3b816e6bb 100644 --- a/Vector/AppDelegate.m +++ b/Vector/AppDelegate.m @@ -128,7 +128,7 @@ _build = buildNumber; } else { - _build = buildBranch ? buildBranch : NSLocalizedStringFromTable(@"settings_config_no_build_info", @"MatrixConsole", nil); + _build = buildBranch ? buildBranch : NSLocalizedStringFromTable(@"settings_config_no_build_info", @"Vector", nil); } } return _build; @@ -176,8 +176,8 @@ self.masterTabBarController = (MasterTabBarController*)self.window.rootViewController; self.masterTabBarController.delegate = self; - // By default the "Home" tab is focused - [self.masterTabBarController setSelectedIndex:TABBAR_HOME_INDEX]; + // By default the "Recents" tab is focused + [self.masterTabBarController setSelectedIndex:TABBAR_RECENTS_INDEX]; UIViewController* recents = [self.masterTabBarController.viewControllers objectAtIndex:TABBAR_RECENTS_INDEX]; if ([recents isKindOfClass:[UISplitViewController class]]) @@ -556,9 +556,6 @@ // Set up push notifications [self registerUserNotificationSettings]; - // When user is already logged, we launch the app on Recents - [self.masterTabBarController setSelectedIndex:TABBAR_RECENTS_INDEX]; - // Observe inApp notifications toggle change for each account for (MXKAccount *account in mxAccounts) { @@ -617,8 +614,8 @@ // Reset the contact manager [[MXKContactManager sharedManager] reset]; - // By default the "Home" tab is focussed - [self.masterTabBarController setSelectedIndex:TABBAR_HOME_INDEX]; + // By default the "Recents" tab is focussed + [self.masterTabBarController setSelectedIndex:TABBAR_RECENTS_INDEX]; } - (MXKAlert*)showErrorAsAlert:(NSError*)error @@ -720,7 +717,7 @@ weakSelf.mxInAppNotification = nil; [account updateNotificationListenerForRoomId:event.roomId ignore:YES]; }]; - [self.mxInAppNotification addActionWithTitle:NSLocalizedStringFromTable(@"view", @"MatrixConsole", nil) + [self.mxInAppNotification addActionWithTitle:NSLocalizedStringFromTable(@"view", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { @@ -1014,7 +1011,7 @@ // Create statusBarButton callStatusBarButton = [UIButton buttonWithType:UIButtonTypeCustom]; callStatusBarButton.frame = CGRectMake(0, 0, topBarSize.width,topBarSize.height); - NSString *btnTitle = NSLocalizedStringFromTable(@"return_to_call", @"MatrixConsole", nil); + NSString *btnTitle = NSLocalizedStringFromTable(@"return_to_call", @"Vector", nil); [callStatusBarButton setTitle:btnTitle forState:UIControlStateNormal]; [callStatusBarButton setTitle:btnTitle forState:UIControlStateHighlighted]; diff --git a/Vector/Assets/Images/icon_users.png b/Vector/Assets/Images/icon_users.png new file mode 100755 index 000000000..5a914b6a1 Binary files /dev/null and b/Vector/Assets/Images/icon_users.png differ diff --git a/Vector/Assets/Images/icon_users@2x.png b/Vector/Assets/Images/icon_users@2x.png new file mode 100755 index 000000000..2a1b5998a Binary files /dev/null and b/Vector/Assets/Images/icon_users@2x.png differ diff --git a/Vector/Assets/Images/tab_settings.png b/Vector/Assets/Images/tab_settings.png new file mode 100644 index 000000000..bf96bdb02 Binary files /dev/null and b/Vector/Assets/Images/tab_settings.png differ diff --git a/Vector/Assets/Images/tab_settings@2x.png b/Vector/Assets/Images/tab_settings@2x.png new file mode 100644 index 000000000..72bbabfd4 Binary files /dev/null and b/Vector/Assets/Images/tab_settings@2x.png differ diff --git a/Vector/Assets/en.lproj/Vector.strings b/Vector/Assets/en.lproj/Vector.strings index 323b80a8c..9216e7edd 100644 --- a/Vector/Assets/en.lproj/Vector.strings +++ b/Vector/Assets/en.lproj/Vector.strings @@ -18,6 +18,24 @@ "recents" = "Recents"; "accounts" = "Accounts"; +// Actions +"view" = "View"; +"mark_all_as_read_prompt" = "Mark all as read?"; + +// Settings +"account_logout_all" = "Logout all accounts"; + +"settings_config_ios_console_version" = "Console version: %@"; +"settings_config_ios_kit_version" = "MatrixKit version: %@"; +"settings_config_ios_sdk_version" = "MatrixSDK version: %@"; +"settings_config_build_number" = "Build: %@"; +"settings_config_no_build_info" = "(no build info)"; +"settings_title_config" = "Configuration"; +"settings_clear_cache" = "Clear cache"; + +"notification_settings_global_notification_settings" = "Global Notification Settings"; + // Others +"public_room_section_title" = "Public Rooms (at %@):"; "bug_report_prompt" = "The application has crashed last time. Would you like to submit a crash report?"; "rage_shake_prompt" = "You seem to be shaking the phone in frustration. Would you like to submit a bug report?"; \ No newline at end of file diff --git a/Vector/Base.lproj/Main.storyboard b/Vector/Base.lproj/Main.storyboard index 00ed192c6..5c35d884c 100644 --- a/Vector/Base.lproj/Main.storyboard +++ b/Vector/Base.lproj/Main.storyboard @@ -1,8 +1,7 @@ - + - - + @@ -27,7 +26,7 @@ - + @@ -49,14 +48,6 @@ - - - - - - - - @@ -86,61 +77,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -159,23 +95,6 @@ - - - - - - - - - - - - - - - - - @@ -188,9 +107,7 @@ - - @@ -198,19 +115,6 @@ - - - - - - - - - - - - - @@ -314,33 +218,14 @@ - - - - - - - - - - - - - - - - - - - - + diff --git a/Vector/Model/RecentListDataSource.h b/Vector/Model/RecentListDataSource.h index add41af98..076ca6c41 100644 --- a/Vector/Model/RecentListDataSource.h +++ b/Vector/Model/RecentListDataSource.h @@ -17,8 +17,48 @@ #import /** - The data source for Console `RecentsViewController`. + The data source for `RecentsViewController` in Vector + List the recents (interleaved in only one section in case of multi-sessions) and the available public rooms. + A section of public rooms is added for each added REST client. + + Two different types of cell data are handled by this data source: id for the recents + and MXPublicRoom* for the public rooms added after the recents list. + See publicRoomsFirstSection property to know which type is expected for cell data at a specific indexPath. */ @interface RecentListDataSource : MXKInterleavedRecentsDataSource +/** + The first Public rooms sections (-1 if none). + */ +@property NSInteger publicRoomsFirstSection; + +/** + Add a matrix REST Client. It is used to retrieve public rooms. + + @param restClient a restClient. + @param onComplete the callback called once public rooms are updated for this client. + */ +- (void)addRestClient:(MXRestClient*)restClient onComplete:(void (^)())onComplete; + +/** + Remove a matrix REST Client. + */ +- (void)removeRestClient:(MXRestClient*)restClient; + +/** + Refresh public rooms + + @param restClient a restClient, or nil to refresh public rooms for all added client. + @param onComplete the callback called once public rooms are updated. + */ +- (void)refreshPublicRooms:(MXRestClient*)restClient onComplete:(void (^)())onComplete; + +/** + Get the public room displayed in the cell at the given index path. + + @param indexPath the index of the cell + @return a public room or nil if the provided indexPath does not correspond to a public room section. + */ +- (MXPublicRoom*)publicRoomAtIndexPath:(NSIndexPath*)indexPath; + @end diff --git a/Vector/Model/RecentListDataSource.m b/Vector/Model/RecentListDataSource.m index 661225c85..e60a6b898 100644 --- a/Vector/Model/RecentListDataSource.m +++ b/Vector/Model/RecentListDataSource.m @@ -18,36 +18,607 @@ #import "AppDelegate.h" +#import "NSBundle+MatrixKit.h" + +@interface RecentListDataSource () +{ + // + UIButton *recentsShrinkButton; + BOOL areRecentsShrinked; + + // Homeserver list + NSMutableArray *homeServers; + // All registered REST clients + NSMutableArray *restClients; + // REST clients by homeserver + NSMutableDictionary *restClientDict; + // Public rooms by homeserver + NSMutableDictionary *publicRoomsDict; + // Array of shrinked homeservers. + NSMutableArray *shrinkedHomeServers; + // Count current refresh requests + NSInteger refreshCount; + + // List of public room names to highlight in displayed list + NSArray* highlightedPublicRooms; + + // Search in public rooms + NSMutableDictionary *filteredPublicRoomsDict; +} +@end + @implementation RecentListDataSource -#pragma mark - UITableViewDataSource - -- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { - // Return NO if you do not want the specified item to be editable. - return YES; +- (instancetype)init +{ + self = [super init]; + if (self) + { + 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 + } + return self; } -- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { - if (editingStyle == UITableViewCellEditingStyleDelete) { - // Leave the selected room - id recentCellData = [self cellDataAtIndexPath:indexPath]; +- (void)destroy +{ + homeServers = nil; + restClients = nil; + restClientDict = nil; + publicRoomsDict = nil; + filteredPublicRoomsDict = nil; + shrinkedHomeServers = nil; + + highlightedPublicRooms = nil; + + [super destroy]; +} + +#pragma mark - + +- (void)addRestClient:(MXRestClient*)restClient onComplete:(void (^)())onComplete +{ + if (!restClient.homeserver) + { + return; + } + + if (!homeServers) + { + homeServers = [NSMutableArray array]; + } + if (!restClients) + { + restClients = [NSMutableArray array]; + } + if (!restClientDict) + { + restClientDict = [NSMutableDictionary dictionary]; + } + + if ([restClients indexOfObject:restClient] == NSNotFound) + { + [restClients addObject:restClient]; - // cancel pending uploads/downloads - // they are useless by now - [MXKMediaManager cancelDownloadsInCacheFolder:recentCellData.roomDataSource.room.state.roomId]; - // TODO GFO cancel pending uploads related to this room + if ([homeServers indexOfObject:restClient.homeserver] == NSNotFound){ + [homeServers addObject:restClient.homeserver]; + [restClientDict setObject:restClient forKey:restClient.homeserver]; + [self refreshPublicRooms:restClient onComplete:onComplete]; + } + } +} + +- (void)removeRestClient:(MXRestClient *)restClient +{ + NSUInteger index = [restClients indexOfObject:restClient]; + if (index != NSNotFound) + { + [restClients removeObjectAtIndex:index]; - [recentCellData.roomDataSource.room leave:^{ - // Refresh table display - if (self.delegate) { + // Check whether this client was reported in rest client dictionary + for (NSString *homeserver in homeServers) + { + if ([restClientDict objectForKey:homeserver] == restClient) + { + [restClientDict removeObjectForKey:homeserver]; + BOOL removeHomeServer = YES; + + // Look for an other rest client for this homeserver (if any) + for (MXRestClient *client in restClients) + { + if ([client.homeserver isEqualToString:homeserver]) + { + [restClientDict setObject:client forKey:homeserver]; + removeHomeServer = NO; + break; + } + } + + if (removeHomeServer) + { + [homeServers removeObject:homeserver]; + [publicRoomsDict removeObjectForKey:homeserver]; + } + + [self refreshPublicRooms:nil onComplete:nil]; + break; + } + } + } +} + +- (void)removeClosedRestClients +{ + // We check here all registered clients (Some of them may have been closed). + for (NSInteger index = 0; index < restClients.count; index ++) + { + MXRestClient *restClient = [restClients objectAtIndex:index]; + if (!restClient.homeserver.length) + { + [self removeRestClient:restClient]; + } + } +} + +- (void)refreshPublicRooms:(MXRestClient*)restClient onComplete:(void (^)())onComplete +{ + NSArray *selectedClients; + if (restClient) + { + selectedClients = @[restClient]; + } + else + { + // refresh registered clients by removing closed ones. + [self removeClosedRestClients]; + + // Consider only one client by homeserver. + selectedClients = restClientDict.allValues; + } + + if (!selectedClients.count) + { + return; + } + + refreshCount += selectedClients.count; + + if (!publicRoomsDict) + { + publicRoomsDict = [NSMutableDictionary dictionaryWithCapacity:restClientDict.count]; + } + if (!shrinkedHomeServers) + { + shrinkedHomeServers = [NSMutableArray array]; + } + + for (NSInteger index = 0; index < selectedClients.count; index ++) + { + MXRestClient *restClient = [selectedClients objectAtIndex:index]; + + // Retrieve public rooms + [restClient publicRooms:^(NSArray *rooms) { + + NSArray *publicRooms = [rooms sortedArrayUsingComparator:^NSComparisonResult(id a, id b) { + + MXPublicRoom *firstRoom = (MXPublicRoom*)a; + MXPublicRoom *secondRoom = (MXPublicRoom*)b; + + // Compare member count + if (firstRoom.numJoinedMembers < secondRoom.numJoinedMembers) + { + return NSOrderedDescending; + } + else if (firstRoom.numJoinedMembers > secondRoom.numJoinedMembers) + { + return NSOrderedAscending; + } + else + { + // Alphabetic order + return [firstRoom.displayname compare:secondRoom.displayname options:NSCaseInsensitiveSearch]; + } + }]; + + if (publicRooms.count && restClient.homeserver) + { + [publicRoomsDict setObject:publicRooms forKey:restClient.homeserver]; + } + + refreshCount--; + if (refreshCount == 0) + { [self.delegate dataSource:self didCellChange:nil]; + + if (onComplete) + { + onComplete(); + } } } failure:^(NSError *error) { - NSLog(@"[Console RecentListDataSource] Failed to leave room (%@) failed: %@", recentCellData.roomDataSource.room.state.roomId, error); + + NSLog(@"[RecentListDataSource] Failed to get public rooms for %@: %@", restClient.homeserver, error); //Alert user [[AppDelegate theDelegate] showErrorAsAlert:error]; + + refreshCount--; + if (refreshCount == 0) + { + [self.delegate dataSource:self didCellChange:nil]; + + if (onComplete) + { + onComplete(); + } + } + }]; } } +- (MXPublicRoom*)publicRoomAtIndexPath:(NSIndexPath*)indexPath +{ + MXPublicRoom *publicRoom = nil; + + if (_publicRoomsFirstSection != -1 && indexPath.section >= _publicRoomsFirstSection) + { + NSInteger index = indexPath.section - _publicRoomsFirstSection; + if (index < homeServers.count) + { + NSString *homeserver = [homeServers objectAtIndex:index]; + NSArray *publicRooms = nil; + if (filteredPublicRoomsDict) + { + publicRooms = [filteredPublicRoomsDict objectForKey:homeserver]; + } + else + { + publicRooms = [publicRoomsDict objectForKey:homeserver]; + } + + if (indexPath.row < publicRooms.count) + { + publicRoom = [publicRooms objectAtIndex:indexPath.row]; + } + } + } + + return publicRoom; +} + +#pragma mark - Override MXKRecentsDataSource + +- (void)addMatrixSession:(MXSession *)matrixSession +{ + [super addMatrixSession:matrixSession]; + + [self addRestClient:matrixSession.matrixRestClient onComplete:nil]; +} + +- (void)removeMatrixSession:(MXSession*)matrixSession +{ + [super removeMatrixSession:matrixSession]; + + // Remove the related REST Client + if (matrixSession.matrixRestClient) + { + [self removeRestClient:matrixSession.matrixRestClient]; + } + else + { + // Here the matrix session is closed, the rest client reference has been removed. + // Force a full refresh + [self refreshPublicRooms:nil onComplete:nil]; + } +} + +- (void)searchWithPatterns:(NSArray*)patternsList +{ + [super searchWithPatterns:patternsList]; + + // Update filtered list + if (patternsList.count) + { + if (filteredPublicRoomsDict) + { + [filteredPublicRoomsDict removeAllObjects]; + } + else + { + filteredPublicRoomsDict = [NSMutableDictionary dictionaryWithCapacity:homeServers.count]; + } + + for (NSString* pattern in patternsList) + { + for (NSString *homeserver in homeServers) + { + NSArray *publicRooms = [publicRoomsDict objectForKey:homeserver]; + + NSMutableArray *filteredRooms = [filteredPublicRoomsDict objectForKey:homeserver]; + if (!filteredRooms) + { + filteredRooms = [NSMutableArray array]; + } + + for (MXPublicRoom *publicRoom in publicRooms) + { + if ([[publicRoom displayname] rangeOfString:pattern options:NSCaseInsensitiveSearch].location != NSNotFound) + { + if ([filteredRooms indexOfObject:publicRoom] == NSNotFound) + { + [filteredRooms addObject:publicRoom]; + } + } + } + + if (filteredRooms.count) + { + [filteredPublicRoomsDict setObject:filteredRooms forKey:homeserver]; + } + } + } + } + else + { + filteredPublicRoomsDict = nil; + } + + [self.delegate dataSource:self didCellChange:nil]; +} + +- (CGFloat)cellHeightAtIndexPath:(NSIndexPath*)indexPath +{ + if (_publicRoomsFirstSection != -1 && indexPath.section >= _publicRoomsFirstSection) + { + return 60; + } + return [super cellHeightAtIndexPath:indexPath]; +} + +- (UIView *)viewForHeaderInSection:(NSInteger)section withFrame:(CGRect)frame +{ + UIView *sectionHeader = nil; + NSString* sectionTitle; + BOOL isShrinked = NO; + NSInteger buttonTag; + + if (section < _publicRoomsFirstSection) + { + sectionHeader = [super viewForHeaderInSection:section withFrame:frame]; + + // Here sectionHeader is nil if there is only one session + if (!sectionHeader) + { + // Let's create a header to shrink recents + sectionTitle = self.mxSession.myUser.userId; + if (self.unreadCount) + { + sectionTitle = [NSString stringWithFormat:@"%@ (%tu)", sectionTitle, self.unreadCount]; + } + + isShrinked = areRecentsShrinked; + buttonTag = 0; + } + } + else + { + NSArray *publicRooms = nil; + NSString *homeserver; + NSInteger index = section - _publicRoomsFirstSection; + if (index < homeServers.count) + { + homeserver = [homeServers objectAtIndex:index]; + + if (filteredPublicRoomsDict) + { + publicRooms = [filteredPublicRoomsDict objectForKey:homeserver]; + } + else + { + publicRooms = [publicRoomsDict objectForKey:homeserver]; + } + } + + if (publicRooms) + { + sectionTitle = [NSString stringWithFormat:NSLocalizedStringFromTable(@"public_room_section_title", @"Vector", nil), homeserver]; + isShrinked = ([shrinkedHomeServers indexOfObject:homeserver] != NSNotFound); + buttonTag = self.displayedRecentsDataSourcesCount + index; + } + } + + if (!sectionHeader && sectionTitle.length) + { + sectionHeader = [[UIView alloc] initWithFrame:frame]; + sectionHeader.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]; + + // Add shrink button + UIButton *shrinkButton = [UIButton buttonWithType:UIButtonTypeCustom]; + CGRect frame = sectionHeader.frame; + frame.origin.x = frame.origin.y = 0; + shrinkButton.frame = frame; + shrinkButton.backgroundColor = [UIColor clearColor]; + [shrinkButton addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; + shrinkButton.tag = buttonTag; + [sectionHeader addSubview:shrinkButton]; + sectionHeader.userInteractionEnabled = YES; + + // Add shrink icon + UIImage *chevron; + if (isShrinked) + { + chevron = [NSBundle mxk_imageFromMXKAssetsBundleWithName:@"disclosure"]; + } + else + { + chevron = [NSBundle mxk_imageFromMXKAssetsBundleWithName:@"shrink"]; + } + UIImageView *chevronView = [[UIImageView alloc] initWithImage:chevron]; + chevronView.contentMode = UIViewContentModeCenter; + frame = chevronView.frame; + frame.origin.x = sectionHeader.frame.size.width - frame.size.width - 8; + frame.origin.y = (sectionHeader.frame.size.height - frame.size.height) / 2; + chevronView.frame = frame; + [sectionHeader addSubview:chevronView]; + chevronView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin); + + // Add label + frame = sectionHeader.frame; + frame.origin.x = 5; + frame.origin.y = 5; + frame.size.width = chevronView.frame.origin.x - 10; + frame.size.height -= 10; + UILabel *headerLabel = [[UILabel alloc] initWithFrame:frame]; + headerLabel.font = [UIFont boldSystemFontOfSize:16]; + headerLabel.backgroundColor = [UIColor clearColor]; + headerLabel.text = sectionTitle; + [sectionHeader addSubview:headerLabel]; + } + + return sectionHeader; +} + +- (IBAction)onButtonPressed:(id)sender +{ + if ([sender isKindOfClass:[UIButton class]]) + { + UIButton *shrinkButton = (UIButton*)sender; + + if (shrinkButton.tag < self.displayedRecentsDataSourcesCount) + { + if (self.displayedRecentsDataSourcesCount > 1) + { + [super onButtonPressed:sender]; + } + else + { + areRecentsShrinked = !areRecentsShrinked; + [self.delegate dataSource:self didCellChange:nil]; + } + } + else + { + NSInteger tag = shrinkButton.tag - self.displayedRecentsDataSourcesCount; + if (tag < homeServers.count) + { + NSString *homeserver = [homeServers objectAtIndex:tag]; + + NSUInteger index = [shrinkedHomeServers indexOfObject:homeserver]; + if (index != NSNotFound) + { + // Disclose the public rooms list + [shrinkedHomeServers removeObjectAtIndex:index]; + } + else + { + // Shrink the public rooms list from this homeserver. + [shrinkedHomeServers addObject:homeserver]; + } + // trigger table refresh + [self.delegate dataSource:self didCellChange:nil]; + } + } + } +} + +#pragma mark - UITableViewDataSource + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + NSInteger sectionNb = [super numberOfSectionsInTableView:tableView]; + + _publicRoomsFirstSection = -1; + + if (homeServers.count) + { + // Add a section for each list of public rooms + _publicRoomsFirstSection = sectionNb; + sectionNb += homeServers.count; + } + + return sectionNb; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + NSInteger count = 0; + + if (_publicRoomsFirstSection == -1 || section < _publicRoomsFirstSection) + { + count = [super tableView:tableView numberOfRowsInSection:section]; + + if (areRecentsShrinked) + { + count = 0; + } + + } + else + { + NSArray *publicRooms = nil; + NSInteger index = section - _publicRoomsFirstSection; + if (index < homeServers.count) + { + NSString *homeserver = [homeServers objectAtIndex:index]; + + // Check whether the list is shrinked + if ([shrinkedHomeServers indexOfObject:homeserver] == NSNotFound) + { + if (filteredPublicRoomsDict) + { + publicRooms = [filteredPublicRoomsDict objectForKey:homeserver]; + } + else + { + publicRooms = [publicRoomsDict objectForKey:homeserver]; + } + } + } + + count = publicRooms.count; + } + + return count; +} + +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath +{ + // Public rooms are not editable + if (_publicRoomsFirstSection == -1 || indexPath.section < _publicRoomsFirstSection) + { + return YES; + } + + return NO; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell; + + if (_publicRoomsFirstSection == -1 || indexPath.section < _publicRoomsFirstSection) + { + cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]; + } + else + { + MXKPublicRoomTableViewCell *publicRoomCell = [tableView dequeueReusableCellWithIdentifier:[MXKPublicRoomTableViewCell defaultReuseIdentifier]]; + if (!publicRoomCell) + { + publicRoomCell = [[MXKPublicRoomTableViewCell alloc] init]; + } + + MXPublicRoom *publicRoom = [self publicRoomAtIndexPath:indexPath]; + if (publicRoom) + { + [publicRoomCell render:publicRoom]; + // Highlight? + publicRoomCell.focused = (publicRoomCell.roomDisplayName.text && [highlightedPublicRooms indexOfObject:publicRoomCell.roomDisplayName.text] != NSNotFound); + } + + cell = publicRoomCell; + } + + return cell; +} + @end diff --git a/Vector/ViewController/AccountDetailsViewController.m b/Vector/ViewController/AccountDetailsViewController.m index c91abdf6f..2226721b0 100644 --- a/Vector/ViewController/AccountDetailsViewController.m +++ b/Vector/ViewController/AccountDetailsViewController.m @@ -71,8 +71,8 @@ { globalNotifSettingsBtnCell = [[MXKTableViewCellWithButton alloc] init]; } - [globalNotifSettingsBtnCell.mxkButton setTitle:NSLocalizedStringFromTable(@"notification_settings_global_notification_settings", @"MatrixConsole", nil) forState:UIControlStateNormal]; - [globalNotifSettingsBtnCell.mxkButton setTitle:NSLocalizedStringFromTable(@"notification_settings_global_notification_settings", @"MatrixConsole", nil) forState:UIControlStateHighlighted]; + [globalNotifSettingsBtnCell.mxkButton setTitle:NSLocalizedStringFromTable(@"notification_settings_global_notification_settings", @"Vector", nil) forState:UIControlStateNormal]; + [globalNotifSettingsBtnCell.mxkButton setTitle:NSLocalizedStringFromTable(@"notification_settings_global_notification_settings", @"Vector", nil) forState:UIControlStateHighlighted]; [globalNotifSettingsBtnCell.mxkButton addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; globalNotifSettingsButton = globalNotifSettingsBtnCell.mxkButton; diff --git a/Vector/ViewController/ContactsViewController.h b/Vector/ViewController/ContactsViewController.h deleted file mode 100644 index 2810f8be7..000000000 --- a/Vector/ViewController/ContactsViewController.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - 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 - -// SMS -#import -#import - -/** - 'ContactsViewController' inherits MXKContactListViewController to handle contact list. - */ -@interface ContactsViewController : MXKContactListViewController -@end - diff --git a/Vector/ViewController/ContactsViewController.m b/Vector/ViewController/ContactsViewController.m deleted file mode 100644 index 02ae9f2b8..000000000 --- a/Vector/ViewController/ContactsViewController.m +++ /dev/null @@ -1,285 +0,0 @@ -/* - 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 "ContactsViewController.h" - -#import "AppDelegate.h" - -#import "RageShakeManager.h" - -#import "NSBundle+MatrixKit.h" - -@interface ContactsViewController () -{ - /** - Tap on thumbnail --> display matrix information. - */ - MXKContact* selectedContact; -} - -@property (strong, nonatomic) MXKAlert *startChatMenu; -@property (strong, nonatomic) MXKAlert *allowContactSyncAlert; -@end - -@implementation ContactsViewController - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - [self.tableView setSectionIndexColor:[AppDelegate theDelegate].masterTabBarController.tabBar.tintColor]; - [self.tableView setSectionIndexBackgroundColor:[UIColor clearColor]]; - - // Set rageShake handler - self.rageShakeManager = [RageShakeManager sharedManager]; - - // The view controller handles itself the selected contact - self.delegate = self; -} - -- (void)destroy -{ - if (self.startChatMenu) - { - [self.startChatMenu dismiss:NO]; - } - if (self.allowContactSyncAlert) - { - [self.allowContactSyncAlert dismiss:NO]; - } - - selectedContact = nil; - - [super destroy]; -} - -#pragma mark - Actions - -- (IBAction)onSegmentValueChange:(id)sender -{ - [super onSegmentValueChange:sender]; - - if (sender == self.contactsControls) - { - // Did the user select local contacts? - if (self.contactsControls.selectedSegmentIndex) - { - MXKAppSettings* appSettings = [MXKAppSettings standardAppSettings]; - - if (!appSettings.syncLocalContacts) - { - __weak typeof(self) weakSelf = self; - - self.allowContactSyncAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"contact_local_sync_prompt", @"MatrixConsole", nil) message:nil style:MXKAlertStyleAlert]; - - [self.allowContactSyncAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"no"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) - { - weakSelf.allowContactSyncAlert = nil; - }]; - - [self.allowContactSyncAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"yes"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) - { - weakSelf.allowContactSyncAlert = nil; - dispatch_async(dispatch_get_main_queue(), ^{ - appSettings.syncLocalContacts = YES; - [weakSelf.tableView reloadData]; - }); - }]; - - [self.allowContactSyncAlert showInViewController:self]; - } - } - } -} - -#pragma mark - MXKContactListViewControllerDelegate - -- (void)contactListViewController:(MXKContactListViewController *)contactListViewController didSelectContact:(NSString*)contactId -{ - MXKContact *contact = [[MXKContactManager sharedManager] contactWithContactID:contactId]; - - __weak typeof(self) weakSelf = self; - NSArray* matrixIDs = contact.matrixIdentifiers; - - // matrix user ? - if (matrixIDs.count) - { - // Display action sheet only if at least one session is available for this user - BOOL isSessionAvailable = NO; - - NSArray *mxSessions = self.mxSessions; - for (NSString* userID in matrixIDs) - { - for (MXSession *mxSession in mxSessions) - { - if ([mxSession userWithUserId:userID]) - { - isSessionAvailable = YES; - break; - } - } - } - - if (isSessionAvailable) - { - // only 1 matrix ID - if (matrixIDs.count == 1) - { - NSString* matrixID = [matrixIDs objectAtIndex:0]; - - self.startChatMenu = [[MXKAlert alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTable(@"chat_with_user", @"MatrixConsole", nil), matrixID] message:nil style:MXKAlertStyleAlert]; - - [self.startChatMenu addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) - { - weakSelf.startChatMenu = nil; - }]; - - [self.startChatMenu addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) - { - weakSelf.startChatMenu = nil; - - [[AppDelegate theDelegate] startPrivateOneToOneRoomWithUserId:matrixID]; - }]; - } - else - { - self.startChatMenu = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"chat_with", @"MatrixConsole", nil) message:nil style:MXKAlertStyleActionSheet]; - - for(NSString* matrixID in matrixIDs) - { - [self.startChatMenu addActionWithTitle:matrixID style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) - { - weakSelf.startChatMenu = nil; - - [[AppDelegate theDelegate] startPrivateOneToOneRoomWithUserId:matrixID]; - }]; - } - - [self.startChatMenu addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) - { - weakSelf.startChatMenu = nil; - }]; - - self.startChatMenu.sourceView = self.tableView; - } - - [self.startChatMenu showInViewController:self]; - } - } - else - { - // invite to use matrix - if (([MFMessageComposeViewController canSendText] ? contact.emailAddresses.count : 0) + (contact.phoneNumbers.count > 0)) - { - - self.startChatMenu = [[MXKAlert alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTable(@"invite_this_user_to_use_matrix", @"MatrixConsole", nil)] message:nil style:MXKAlertStyleActionSheet]; - - // check if the target can send SMSes - if ([MFMessageComposeViewController canSendText]) - { - // list phonenumbers - for(MXKPhoneNumber* phonenumber in contact.phoneNumbers) - { - [self.startChatMenu addActionWithTitle:phonenumber.textNumber style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) - { - weakSelf.startChatMenu = nil; - - // launch SMS composer - MFMessageComposeViewController *messageComposer = [[MFMessageComposeViewController alloc] init]; - - if (messageComposer) - - { - messageComposer.messageComposeDelegate = weakSelf; - messageComposer.body = NSLocalizedStringFromTable(@"invitation_message", @"MatrixConsole", nil); - messageComposer.recipients = [NSArray arrayWithObject:phonenumber.textNumber]; - - dispatch_async(dispatch_get_main_queue(), ^{ - [weakSelf presentViewController:messageComposer animated:YES completion:nil]; - }); - } - }]; - } - } - - // list emails - for(MXKEmail* email in contact.emailAddresses) - { - [self.startChatMenu addActionWithTitle:email.emailAddress style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) - { - weakSelf.startChatMenu = nil; - - dispatch_async(dispatch_get_main_queue(), ^{ - - NSString* subject = [NSLocalizedStringFromTable(@"invitation_subject", @"MatrixConsole", nil) stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - NSString* body = [NSLocalizedStringFromTable(@"invitation_message", @"MatrixConsole", nil) stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - - [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@?subject=%@&body=%@", email.emailAddress, subject, body]]]; - }); - }]; - } - - [self.startChatMenu addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) - { - weakSelf.startChatMenu = nil; - }]; - - self.startChatMenu.sourceView = self.tableView; - [self.startChatMenu showInViewController:self]; - } - } -} - -- (void)contactListViewController:(MXKContactListViewController *)contactListViewController didTapContactThumbnail:(NSString*)contactId -{ - MXKContact *contact = [[MXKContactManager sharedManager] contactWithContactID:contactId]; - - // open detailled sheet if there - if (contact.matrixIdentifiers.count > 0) - { - selectedContact = contact; - [self performSegueWithIdentifier:@"showContactDetails" sender:self]; - } -} - -#pragma mark - Segues - -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender -{ - // Keep ref on destinationViewController - [super prepareForSegue:segue sender:sender]; - - if ([segue.identifier isEqualToString:@"showContactDetails"]) - { - MXKContactDetailsViewController *contactDetailsViewController = segue.destinationViewController; - // Set rageShake handler - contactDetailsViewController.rageShakeManager = [RageShakeManager sharedManager]; - // Set delegate to handle start chat option - contactDetailsViewController.delegate = [AppDelegate theDelegate]; - - contactDetailsViewController.contact = selectedContact; - selectedContact = nil; - } -} - -#pragma mark MFMessageComposeViewControllerDelegate - -- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result -{ - [self dismissViewControllerAnimated:YES completion:nil]; -} - -@end diff --git a/Vector/ViewController/HomeViewController.h b/Vector/ViewController/HomeViewController.h deleted file mode 100644 index fff1719fb..000000000 --- a/Vector/ViewController/HomeViewController.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - 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 - -@interface HomeViewController:MXKViewController - -@property (weak, nonatomic) IBOutlet UISearchBar *publicRoomsSearchBar; -@property (weak, nonatomic) IBOutlet UITableView *tableView; - -@property (weak, nonatomic) IBOutlet NSLayoutConstraint *publicRoomsSearchBarHeightConstraint; -@property (weak, nonatomic) IBOutlet NSLayoutConstraint *publicRoomsSearchBarTopConstraint; -@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewBottomConstraint; - -/** - Add a matrix REST Client. It is used to make Matrix API requests and retrieve public rooms. - */ -- (void)addRestClient:(MXRestClient*)restClient; - -/** - Remove a matrix REST Client. - */ -- (void)removeRestClient:(MXRestClient*)restClient; - -/** - Enable the search in recents list according to the room display name (YES by default). - Set NO this property to disable this option and hide the related bar button. - */ -@property (nonatomic) BOOL enableSearch; - -@end - diff --git a/Vector/ViewController/HomeViewController.m b/Vector/ViewController/HomeViewController.m deleted file mode 100644 index 2964b452d..000000000 --- a/Vector/ViewController/HomeViewController.m +++ /dev/null @@ -1,1092 +0,0 @@ -/* - 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 "AppDelegate.h" - -#import "RageShakeManager.h" - -NSString *const kHomeViewControllerCreateRoomCellId = @"kHomeViewControllerCreateRoomCellId"; - -@interface HomeViewController () -{ - // Room creation section - NSInteger createRoomSection; - MXKRoomCreationView *createRoomView; - - // Join room by alias section - NSInteger joinRoomSection; - MXKTableViewCellWithTextFieldAndButton* joinRoomCell; - - // Public rooms sections - NSInteger publicRoomsFirstSection; - // Homeserver list - NSMutableArray *homeServers; - // All registered REST clients - NSMutableArray *restClients; - // REST clients by homeserver - NSMutableDictionary *restClientDict; - // Public rooms by homeserver - NSMutableDictionary *publicRoomsDict; - // Array of shrinked homeservers. - NSMutableArray *shrinkedHomeServers; - // Count current refresh requests - NSInteger refreshCount; - - // List of public room names to highlight in displayed list - NSArray* highlightedPublicRooms; - - // Search in public rooms - UIBarButtonItem *searchButton; - BOOL searchBarShouldEndEditing; - NSMutableDictionary *filteredPublicRoomsDict; -} - -@end - -@implementation HomeViewController - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - // Set rageShake handler - self.rageShakeManager = [RageShakeManager sharedManager]; - - // Prepare room creation section - createRoomView = [MXKRoomCreationView roomCreationView]; - createRoomView.delegate = self; - - // Init - 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 - - // Adjust Top and Bottom constraints to take into account potential navBar and tabBar. - if ([NSLayoutConstraint respondsToSelector:@selector(deactivateConstraints:)]) - { - [NSLayoutConstraint deactivateConstraints:@[_publicRoomsSearchBarTopConstraint, _tableViewBottomConstraint]]; - } - else - { - [self.view removeConstraint:_publicRoomsSearchBarTopConstraint]; - [self.view removeConstraint:_tableViewBottomConstraint]; - } - - _publicRoomsSearchBarTopConstraint = [NSLayoutConstraint constraintWithItem:self.topLayoutGuide - attribute:NSLayoutAttributeBottom - relatedBy:NSLayoutRelationEqual - toItem:_publicRoomsSearchBar - attribute:NSLayoutAttributeTop - multiplier:1.0f - constant:0.0f]; - - _tableViewBottomConstraint = [NSLayoutConstraint constraintWithItem:self.bottomLayoutGuide - attribute:NSLayoutAttributeTop - relatedBy:NSLayoutRelationEqual - toItem:self.tableView - attribute:NSLayoutAttributeBottom - multiplier:1.0f - constant:0.0f]; - - if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)]) - { - [NSLayoutConstraint activateConstraints:@[_publicRoomsSearchBarTopConstraint, _tableViewBottomConstraint]]; - } - else - { - [self.view addConstraint:_publicRoomsSearchBarTopConstraint]; - [self.view addConstraint:_tableViewBottomConstraint]; - } - - // Hide search bar by default - _publicRoomsSearchBar.hidden = YES; - _publicRoomsSearchBarHeightConstraint.constant = 0; - [self.view setNeedsUpdateConstraints]; - - // Add search option in navigation bar - self.enableSearch = YES; - - // Add an accessory view to the search bar in order to retrieve keyboard view. - _publicRoomsSearchBar.inputAccessoryView = [[UIView alloc] initWithFrame:CGRectZero]; -} - -- (void)didReceiveMemoryWarning -{ - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - -- (void)dealloc{ - highlightedPublicRooms = nil; - _publicRoomsSearchBar.inputAccessoryView = nil; - searchButton = nil; - - [self destroy]; -} - -- (void)viewWillAppear:(BOOL)animated -{ - [super viewWillAppear:animated]; - - // Refresh all listed public rooms - [self refreshPublicRooms:nil]; -} - -- (void)viewWillDisappear:(BOOL)animated -{ - [super viewWillDisappear:animated]; - - // Leave potential search session - if (!_publicRoomsSearchBar.isHidden) - { - [self searchBarCancelButtonClicked:_publicRoomsSearchBar]; - } -} - -#pragma mark - Override MXKViewController - -- (void)stopActivityIndicator -{ - // Check whether public rooms refresh is in progress - if (refreshCount) - { - return; - } - - [super stopActivityIndicator]; -} - -- (void)onKeyboardShowAnimationComplete -{ - // Check first if the search bar is the first responder - UIView *keyboardView = _publicRoomsSearchBar.inputAccessoryView.superview; - if (!keyboardView) - { - // Check other potential first responder - keyboardView = joinRoomCell.inputAccessoryView.superview; - - if (!keyboardView) - { - keyboardView = createRoomView.inputAccessoryView.superview; - } - } - - // Report the keyboard view in order to track keyboard frame changes - self.keyboardView = keyboardView; -} - -- (void)setKeyboardHeight:(CGFloat)keyboardHeight -{ - - // Deduce the bottom constraint for the table view (Don't forget the potential tabBar) - CGFloat tableViewBottomConst = keyboardHeight - self.bottomLayoutGuide.length; - // Check whether the keyboard is over the tabBar - if (tableViewBottomConst < 0) - { - tableViewBottomConst = 0; - } - - // Update constraints - _tableViewBottomConstraint.constant = tableViewBottomConst; - - // Force layout immediately to take into account new constraint - [self.view layoutIfNeeded]; -} - -- (void)destroy -{ - [createRoomView removeFromSuperview]; - [createRoomView destroy]; - - homeServers = nil; - restClients = nil; - restClientDict = nil; - publicRoomsDict = nil; - filteredPublicRoomsDict = nil; - shrinkedHomeServers = nil; - - [super destroy]; -} - -- (void)addMatrixSession:(MXSession *)mxSession -{ - [super addMatrixSession:mxSession]; - - // Report the related REST Client to retrieve public rooms - [self addRestClient:mxSession.matrixRestClient]; - - [self.tableView reloadData]; -} - -- (void)removeMatrixSession:(MXSession *)mxSession -{ - [super removeMatrixSession:mxSession]; - - // Remove the related REST Client - if (mxSession.matrixRestClient) - { - [self removeRestClient:mxSession.matrixRestClient]; - } - else - { - // Here the matrix session is closed, the rest client reference has been removed. - // Force a full refresh - [self refreshPublicRooms:nil]; - } - - [self.tableView reloadData]; -} - -#pragma mark - - -- (void)addRestClient:(MXRestClient*)restClient -{ - if (!restClient.homeserver) - { - return; - } - - if (!homeServers) - { - homeServers = [NSMutableArray array]; - } - if (!restClients) - { - restClients = [NSMutableArray array]; - } - if (!restClientDict) - { - restClientDict = [NSMutableDictionary dictionary]; - } - - if ([restClients indexOfObject:restClient] == NSNotFound) - { - [restClients addObject:restClient]; - - if ([homeServers indexOfObject:restClient.homeserver] == NSNotFound){ - [homeServers addObject:restClient.homeserver]; - [restClientDict setObject:restClient forKey:restClient.homeserver]; - [self refreshPublicRooms:restClient]; - } - } -} - -- (void)removeRestClient:(MXRestClient *)restClient -{ - NSUInteger index = [restClients indexOfObject:restClient]; - if (index != NSNotFound) - { - [restClients removeObjectAtIndex:index]; - - // Check whether this client was reported in rest client dictionary - for (NSString *homeserver in homeServers) - { - if ([restClientDict objectForKey:homeserver] == restClient) - { - [restClientDict removeObjectForKey:homeserver]; - BOOL removeHomeServer = YES; - - // Look for an other rest client for this homeserver (if any) - for (MXRestClient *client in restClients) - { - if ([client.homeserver isEqualToString:homeserver]) - { - [restClientDict setObject:client forKey:homeserver]; - removeHomeServer = NO; - break; - } - } - - if (removeHomeServer) - { - [homeServers removeObject:homeserver]; - [publicRoomsDict removeObjectForKey:homeserver]; - } - - [self refreshPublicRooms:nil]; - break; - } - } - } -} - -- (void)setEnableSearch:(BOOL)enableSearch -{ - if (enableSearch) - { - if (!searchButton) - { - searchButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(search:)]; - } - - // Add it in right bar items - NSArray *rightBarButtonItems = self.navigationItem.rightBarButtonItems; - self.navigationItem.rightBarButtonItems = rightBarButtonItems ? [rightBarButtonItems arrayByAddingObject:searchButton] : @[searchButton]; - } - else - { - NSMutableArray *rightBarButtonItems = [NSMutableArray arrayWithArray: self.navigationItem.rightBarButtonItems]; - [rightBarButtonItems removeObject:searchButton]; - self.navigationItem.rightBarButtonItems = rightBarButtonItems; - } -} - -#pragma mark - Internals - -- (void)removeClosedRestClients -{ - // We check here all registered clients (Some of them may have been closed). - for (NSInteger index = 0; index < restClients.count; index ++) - { - MXRestClient *restClient = [restClients objectAtIndex:index]; - if (!restClient.homeserver.length) - { - [self removeRestClient:restClient]; - } - } -} - -- (void)refreshPublicRooms:(MXRestClient*)restClient -{ - NSArray *selectedClients; - if (restClient) { - selectedClients = @[restClient]; - } else { - // refresh registered clients by removing closed ones. - [self removeClosedRestClients]; - - // Consider only one client by homeserver. - selectedClients = restClientDict.allValues; - } - - if (!selectedClients.count) - { - return; - } - - refreshCount += selectedClients.count; - [self startActivityIndicator]; - - if (!publicRoomsDict) - { - publicRoomsDict = [NSMutableDictionary dictionaryWithCapacity:restClientDict.count]; - } - if (!shrinkedHomeServers) - { - shrinkedHomeServers = [NSMutableArray array]; - } - - for (NSInteger index = 0; index < selectedClients.count; index ++) - { - MXRestClient *restClient = [selectedClients objectAtIndex:index]; - - // Retrieve public rooms - [restClient publicRooms:^(NSArray *rooms){ - NSArray *publicRooms = [rooms sortedArrayUsingComparator:^NSComparisonResult(id a, id b) - { - - MXPublicRoom *firstRoom = (MXPublicRoom*)a; - MXPublicRoom *secondRoom = (MXPublicRoom*)b; - - // Compare member count - if (firstRoom.numJoinedMembers < secondRoom.numJoinedMembers) - { - return NSOrderedDescending; - } - else if (firstRoom.numJoinedMembers > secondRoom.numJoinedMembers) - { - return NSOrderedAscending; - } - else - { - // Alphabetic order - return [firstRoom.displayname compare:secondRoom.displayname options:NSCaseInsensitiveSearch]; - } - }]; - - if (publicRooms.count && restClient.homeserver) - { - [publicRoomsDict setObject:publicRooms forKey:restClient.homeserver]; - } - - refreshCount--; - if (refreshCount == 0) - { - [self publicRoomsDidRefresh]; - } - } - failure:^(NSError *error){ - NSLog(@"[HomeVC] Failed to get public rooms for %@: %@", restClient.homeserver, error); - //Alert user - [[AppDelegate theDelegate] showErrorAsAlert:error]; - - refreshCount--; - if (refreshCount == 0) - { - [self publicRoomsDidRefresh]; - } - }]; - } -} - -- (void)publicRoomsDidRefresh -{ - [self stopActivityIndicator]; - - // Refresh only the sections related to public rooms (in order to not dismiss potential keyboard). - NSInteger sectionNb = [self numberOfSectionsInTableView:self.tableView]; - if (publicRoomsFirstSection != -1) - { - sectionNb -= publicRoomsFirstSection; - NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange (publicRoomsFirstSection, sectionNb)]; - [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone]; - } -} - -- (IBAction)search:(id)sender -{ - if (_publicRoomsSearchBar.isHidden) - { - // Check whether there are data in which search - if (publicRoomsDict.count) - { - // Show search bar - _publicRoomsSearchBar.hidden = NO; - _publicRoomsSearchBarHeightConstraint.constant = 44; - [self.view setNeedsUpdateConstraints]; - - searchBarShouldEndEditing = NO; - [_publicRoomsSearchBar becomeFirstResponder]; - } - } - else - { - [self searchBarCancelButtonClicked: _publicRoomsSearchBar]; - } - - [self.tableView reloadData]; -} - -- (void)dismissKeyboard -{ - [createRoomView dismissKeyboard]; - - [joinRoomCell.mxkTextField resignFirstResponder]; - - if (_publicRoomsSearchBar) - { - [self searchBarCancelButtonClicked: _publicRoomsSearchBar]; - } -} - -#pragma mark - MXKRoomCreationView Delegate - -- (void)roomCreationView:(MXKRoomCreationView *)creationView presentMXKAlert:(MXKAlert *)alert -{ - [self dismissKeyboard]; - [alert showInViewController:self]; -} - -- (void)roomCreationView:(MXKRoomCreationView *)creationView showRoom:(NSString *)roomId withMatrixSession:(MXSession *)mxSession -{ - [[AppDelegate theDelegate].masterTabBarController showRoom:roomId withMatrixSession:mxSession]; -} - -#pragma mark - UITextField delegate - -- (void)textFieldDidBeginEditing:(UITextField *)textField -{ - if (textField == joinRoomCell.mxkTextField) - { - if (textField.text.length == 0) - { - textField.text = @"#"; - } - } -} - -- (void)textFieldDidEndEditing:(UITextField *)textField -{ - if (textField == joinRoomCell.mxkTextField) - { - if (textField.text.length < 2) - { - // reset text field - textField.text = nil; - joinRoomCell.mxkButton.enabled = NO; - } - } -} - -- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string -{ - // Auto complete room alias - if (textField == joinRoomCell.mxkTextField) - { - // Add # if none - if (!textField.text.length || textField.text.length == range.length) - { - if ([string hasPrefix:@"#"] == NO) - { - textField.text = [NSString stringWithFormat:@"#%@",string]; - // Update Join button status - joinRoomCell.mxkButton.enabled = YES; - return NO; - } - } - } - return YES; -} - -- (BOOL)textFieldShouldReturn:(UITextField*) textField -{ - // "Done" key has been pressed - [textField resignFirstResponder]; - return YES; -} - -#pragma mark - Actions - -- (IBAction)onButtonPressed:(id)sender -{ - if (sender == joinRoomCell.mxkButton) - { - [self dismissKeyboard]; - - // Handle multi-sessions here - [[AppDelegate theDelegate] selectMatrixAccount:^(MXKAccount *selectedAccount) - { - // Disable button to prevent multiple request - joinRoomCell.mxkButton.enabled = NO; - - NSString *roomAlias = joinRoomCell.mxkTextField.text; - // Remove white space from both ends - roomAlias = [roomAlias stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; - - // Check - if (roomAlias.length) - { - [selectedAccount.mxSession joinRoom:roomAlias success:^(MXRoom *room) - { - // Reset text fields - joinRoomCell.mxkTextField.text = nil; - // Show the room - [[AppDelegate theDelegate].masterTabBarController showRoom:room.state.roomId withMatrixSession:selectedAccount.mxSession]; - } failure:^(NSError *error) - { - joinRoomCell.mxkButton.enabled = YES; - NSLog(@"[HomeVC] Failed to join room alias (%@): %@", roomAlias, error); - // Alert user - [[AppDelegate theDelegate] showErrorAsAlert:error]; - }]; - } - else - { - // Reset text fields - joinRoomCell.mxkTextField.text = nil; - } - }]; - } - else if ([sender isKindOfClass:[UIButton class]]) - { - UIButton *shrinkButton = (UIButton*)sender; - - if (shrinkButton.tag < homeServers.count) - { - NSString *homeserver = [homeServers objectAtIndex:shrinkButton.tag]; - - NSUInteger index = [shrinkedHomeServers indexOfObject:homeserver]; - if (index != NSNotFound) - { - // Disclose the public rooms list - [shrinkedHomeServers removeObjectAtIndex:index]; - } - else - { - // Shrink the public rooms list from this homeserver. - [shrinkedHomeServers addObject:homeserver]; - } - // Refresh table - [self.tableView reloadData]; - } - } -} - -#pragma mark - Table view data source - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView -{ - NSInteger count = 0; - - createRoomSection = joinRoomSection = publicRoomsFirstSection = -1; - - // Room creation and join room alias required a matrix session, besides these sections are hidden during search session. - if (self.mxSessions.count && _publicRoomsSearchBar.isHidden) - { - createRoomSection = count++; - joinRoomSection = count++; - } - - if (homeServers.count) - { - publicRoomsFirstSection = count; - count += homeServers.count; - } - return count; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ - NSInteger count = 0; - - if (section == createRoomSection) - { - count = 1; - } - else if (section == joinRoomSection) - { - count = 1; - } - else if (publicRoomsFirstSection != -1) - { - NSArray *publicRooms = nil; - NSInteger index = section - publicRoomsFirstSection; - if (index < homeServers.count) - { - NSString *homeserver = [homeServers objectAtIndex:index]; - - // Check whether the list is shrinked - if ([shrinkedHomeServers indexOfObject:homeserver] == NSNotFound) - { - if (filteredPublicRoomsDict) - { - publicRooms = [filteredPublicRoomsDict objectForKey:homeserver]; - } - else - { - publicRooms = [publicRoomsDict objectForKey:homeserver]; - } - } - } - - count = publicRooms.count; - } - return count; -} - -- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath -{ - if (indexPath.section == createRoomSection) - { - return createRoomView.actualFrameHeight; - } - else if ((publicRoomsFirstSection != -1) && (indexPath.section >= publicRoomsFirstSection)) - { - return 60; - } - return 44; -} - -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - UITableViewCell *cell; - - if (indexPath.section == createRoomSection) - { - [createRoomView removeFromSuperview]; - // Update view data - createRoomView.mxSessions = self.mxSessions; - - cell = [tableView dequeueReusableCellWithIdentifier:kHomeViewControllerCreateRoomCellId]; - if (!cell) - { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kHomeViewControllerCreateRoomCellId]; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - } - - // Add creation view in full size - [cell.contentView addSubview:createRoomView]; - [cell.contentView addConstraint:[NSLayoutConstraint constraintWithItem:cell.contentView - attribute:NSLayoutAttributeBottom - relatedBy:NSLayoutRelationEqual - toItem:createRoomView - attribute:NSLayoutAttributeBottom - multiplier:1.0f - constant:0.0f]]; - [cell.contentView addConstraint:[NSLayoutConstraint constraintWithItem:cell.contentView - attribute:NSLayoutAttributeTop - relatedBy:NSLayoutRelationEqual - toItem:createRoomView - attribute:NSLayoutAttributeTop - multiplier:1.0f - constant:0.0f]]; - [cell.contentView addConstraint:[NSLayoutConstraint constraintWithItem:cell.contentView - attribute:NSLayoutAttributeLeading - relatedBy:NSLayoutRelationEqual - toItem:createRoomView - attribute:NSLayoutAttributeLeading - multiplier:1.0f - constant:0.0f]]; - [cell.contentView addConstraint:[NSLayoutConstraint constraintWithItem:cell.contentView - attribute:NSLayoutAttributeTrailing - relatedBy:NSLayoutRelationEqual - toItem:createRoomView - attribute:NSLayoutAttributeTrailing - multiplier:1.0f - constant:0.0f]]; - [cell.contentView setNeedsUpdateConstraints]; - - } - else if (indexPath.section == joinRoomSection) - { - // Report the current value (if any) - NSString *currentAlias = nil; - if (joinRoomCell) - { - currentAlias = joinRoomCell.mxkTextField.text; - } - - joinRoomCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithTextFieldAndButton defaultReuseIdentifier]]; - if (!joinRoomCell) - { - joinRoomCell = [[MXKTableViewCellWithTextFieldAndButton alloc] init]; - } - - joinRoomCell.mxkTextField.text = currentAlias; - joinRoomCell.mxkButton.enabled = (currentAlias.length != 0); - [joinRoomCell.mxkButton setTitle:NSLocalizedStringFromTable(@"join", @"MatrixConsole", nil) forState:UIControlStateNormal]; - [joinRoomCell.mxkButton setTitle:NSLocalizedStringFromTable(@"join", @"MatrixConsole", nil) forState:UIControlStateHighlighted]; - [joinRoomCell.mxkButton addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; - - cell = joinRoomCell; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - } - else - { - MXKPublicRoomTableViewCell *publicRoomCell = [tableView dequeueReusableCellWithIdentifier:[MXKPublicRoomTableViewCell defaultReuseIdentifier]]; - if (!publicRoomCell) - { - publicRoomCell = [[MXKPublicRoomTableViewCell alloc] init]; - } - - MXPublicRoom *publicRoom; - NSInteger index = indexPath.section - publicRoomsFirstSection; - if (index < homeServers.count) - { - NSString *homeserver = [homeServers objectAtIndex:index]; - NSArray *publicRooms = nil; - if (filteredPublicRoomsDict) - { - publicRooms = [filteredPublicRoomsDict objectForKey:homeserver]; - } - else - { - publicRooms = [publicRoomsDict objectForKey:homeserver]; - } - - if (indexPath.row < publicRooms.count) - { - publicRoom = [publicRooms objectAtIndex:indexPath.row]; - } - } - - if (publicRoom) - { - [publicRoomCell render:publicRoom]; - // Highlight? - publicRoomCell.focused = (publicRoomCell.roomDisplayName.text && [highlightedPublicRooms indexOfObject:publicRoomCell.roomDisplayName.text] != NSNotFound); - } - - cell = publicRoomCell; - } - - return cell; -} - -#pragma mark - Table view delegate - -- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section -{ - // In case of search session, homeservers with no result are hidden. - if (filteredPublicRoomsDict) - { - NSInteger index = section - publicRoomsFirstSection; - if (index < homeServers.count) - { - NSString *homeserver = [homeServers objectAtIndex:index]; - NSArray *publicRooms = [filteredPublicRoomsDict objectForKey:homeserver]; - if (!publicRooms.count) - { - return 0; - } - } - } - return 40; -} - -- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section -{ - UIView *sectionHeader = [[UIView alloc] initWithFrame:[tableView rectForHeaderInSection:section]]; - sectionHeader.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]; - UILabel *sectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, sectionHeader.frame.size.width - 10, sectionHeader.frame.size.height - 10)]; - sectionLabel.font = [UIFont boldSystemFontOfSize:16]; - sectionLabel.backgroundColor = [UIColor clearColor]; - [sectionHeader addSubview:sectionLabel]; - - if (section == createRoomSection) - { - sectionLabel.text = NSLocalizedStringFromTable(@"create_room", @"MatrixConsole", nil); - } - else if (section == joinRoomSection) - { - sectionLabel.text = NSLocalizedStringFromTable(@"join_room", @"MatrixConsole", nil); - } - else - { - NSArray *publicRooms = nil; - NSString *homeserver; - NSInteger index = section - publicRoomsFirstSection; - if (index < homeServers.count) - { - homeserver = [homeServers objectAtIndex:index]; - - if (filteredPublicRoomsDict) - { - publicRooms = [filteredPublicRoomsDict objectForKey:homeserver]; - } - else - { - publicRooms = [publicRoomsDict objectForKey:homeserver]; - } - } - - if (publicRooms) - { - sectionLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"public_room_section_title", @"MatrixConsole", nil), homeserver]; - - if (homeServers.count > 1) - { - // Add shrink button - UIButton *shrinkButton = [UIButton buttonWithType:UIButtonTypeCustom]; - CGRect frame = sectionHeader.frame; - frame.origin.x = frame.origin.y = 0; - shrinkButton.frame = frame; - shrinkButton.backgroundColor = [UIColor clearColor]; - [shrinkButton addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; - shrinkButton.tag = index; - [sectionHeader addSubview:shrinkButton]; - sectionHeader.userInteractionEnabled = YES; - - // Add shrink icon - UIImage *chevron; - if ([shrinkedHomeServers indexOfObject:homeserver] != NSNotFound) - { - chevron = [UIImage imageNamed:@"disclosure"]; - } - else - { - chevron =[UIImage imageNamed:@"shrink"]; - } - UIImageView *chevronView = [[UIImageView alloc] initWithImage:chevron]; - chevronView.contentMode = UIViewContentModeCenter; - frame = chevronView.frame; - frame.origin.x = sectionHeader.frame.size.width - frame.size.width - 8; - frame.origin.y = (sectionHeader.frame.size.height - frame.size.height) / 2; - chevronView.frame = frame; - [sectionHeader addSubview:chevronView]; - chevronView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin); - - // Update label frame - frame = sectionHeader.frame; - frame.origin.x = 5; - frame.origin.y = 5; - frame.size.width = chevronView.frame.origin.x - 10; - frame.size.height -= 10; - sectionLabel.frame = frame; - } - } - else - { - sectionLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"public_room_empty_section_title", @"MatrixConsole", nil), homeserver]; - } - } - - return sectionHeader; -} - -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath -{ - if (indexPath.section < publicRoomsFirstSection) - { - [tableView deselectRowAtIndexPath:indexPath animated:NO]; - } - else - { - // Hide the keyboard when user select a room - [self dismissKeyboard]; - - // Handle multi-sessions here - [[AppDelegate theDelegate] selectMatrixAccount:^(MXKAccount *selectedAccount) - { - MXPublicRoom *publicRoom; - NSInteger index = indexPath.section - publicRoomsFirstSection; - if (index < homeServers.count) - { - NSString *homeserver = [homeServers objectAtIndex:index]; - NSArray *publicRooms = nil; - if (filteredPublicRoomsDict) - { - publicRooms = [filteredPublicRoomsDict objectForKey:homeserver]; - } - else - { - publicRooms = [publicRoomsDict objectForKey:homeserver]; - } - - if (indexPath.row < publicRooms.count) - { - publicRoom = [publicRooms objectAtIndex:indexPath.row]; - } - } - - if (publicRoom) - { - // Check whether the user has already joined the selected public room - if ([selectedAccount.mxSession roomWithRoomId:publicRoom.roomId]) - { - // Open selected room - [[AppDelegate theDelegate].masterTabBarController showRoom:publicRoom.roomId withMatrixSession:selectedAccount.mxSession]; - } - else - { - // Join the selected room - UIActivityIndicatorView *loadingWheel = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; - UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; - if (selectedCell) - { - CGPoint center = CGPointMake(selectedCell.frame.size.width / 2, selectedCell.frame.size.height / 2); - loadingWheel.center = center; - [selectedCell addSubview:loadingWheel]; - } - [loadingWheel startAnimating]; - [selectedAccount.mxSession joinRoom:publicRoom.roomId success:^(MXRoom *room) - { - // Show joined room - [loadingWheel stopAnimating]; - [loadingWheel removeFromSuperview]; - [[AppDelegate theDelegate].masterTabBarController showRoom:publicRoom.roomId withMatrixSession:selectedAccount.mxSession]; - } failure:^(NSError *error) - { - NSLog(@"[HomeVC] Failed to join public room (%@): %@", publicRoom.displayname, error); - //Alert user - [loadingWheel stopAnimating]; - [loadingWheel removeFromSuperview]; - [[AppDelegate theDelegate] showErrorAsAlert:error]; - }]; - } - - [tableView deselectRowAtIndexPath:indexPath animated:YES]; - } - }]; - } -} - -#pragma mark - UISearchBarDelegate - -- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar -{ - searchBarShouldEndEditing = NO; - return YES; -} - -- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar -{ - return searchBarShouldEndEditing; -} - -- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText -{ - // Update filtered list - if (searchText.length) - { - if (filteredPublicRoomsDict) - { - [filteredPublicRoomsDict removeAllObjects]; - } - else - { - filteredPublicRoomsDict = [NSMutableDictionary dictionaryWithCapacity:homeServers.count]; - } - - for (NSString *homeserver in homeServers) - { - NSArray *publicRooms = [publicRoomsDict objectForKey:homeserver]; - - NSMutableArray *filteredRooms = [NSMutableArray array]; - for (MXPublicRoom *publicRoom in publicRooms) - { - if ([[publicRoom displayname] rangeOfString:searchText options:NSCaseInsensitiveSearch].location != NSNotFound) - { - [filteredRooms addObject:publicRoom]; - } - } - - if (filteredRooms.count) - { - [filteredPublicRoomsDict setObject:filteredRooms forKey:homeserver]; - } - } - } - else - { - filteredPublicRoomsDict = nil; - } - // Refresh display - [self.tableView reloadData]; - if (filteredPublicRoomsDict.count) - { - [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO]; - } -} - -- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar -{ - // "Done" key has been pressed - searchBarShouldEndEditing = YES; - [searchBar resignFirstResponder]; -} - -- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar -{ - // Leave search - searchBarShouldEndEditing = YES; - [searchBar resignFirstResponder]; - - _publicRoomsSearchBar.hidden = YES; - _publicRoomsSearchBarHeightConstraint.constant = 0; - [self.view setNeedsUpdateConstraints]; - - _publicRoomsSearchBar.text = nil; - - filteredPublicRoomsDict = nil; - [self.tableView reloadData]; - if (self.tableView.numberOfSections && [self tableView:self.tableView numberOfRowsInSection:0]) - { - [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO]; - } -} - -@end diff --git a/Vector/ViewController/MasterTabBarController.h b/Vector/ViewController/MasterTabBarController.h index 48c5e9477..6a0cffa42 100644 --- a/Vector/ViewController/MasterTabBarController.h +++ b/Vector/ViewController/MasterTabBarController.h @@ -18,11 +18,9 @@ #import -#define TABBAR_HOME_INDEX 0 -#define TABBAR_RECENTS_INDEX 1 -#define TABBAR_CONTACTS_INDEX 2 -#define TABBAR_SETTINGS_INDEX 3 -#define TABBAR_COUNT 4 +#define TABBAR_RECENTS_INDEX 0 +#define TABBAR_SETTINGS_INDEX 1 +#define TABBAR_COUNT 2 @interface MasterTabBarController : UITabBarController diff --git a/Vector/ViewController/MasterTabBarController.m b/Vector/ViewController/MasterTabBarController.m index c421c25c5..b3191f0fa 100644 --- a/Vector/ViewController/MasterTabBarController.m +++ b/Vector/ViewController/MasterTabBarController.m @@ -18,13 +18,9 @@ #import "AppDelegate.h" -#import "HomeViewController.h" - #import "RecentsViewController.h" #import "RecentListDataSource.h" -#import "ContactsViewController.h" - #import "SettingsViewController.h" @interface MasterTabBarController () @@ -33,13 +29,10 @@ NSMutableArray *mxSessionArray; // Tab bar view controllers - HomeViewController *homeViewController; UINavigationController *recentsNavigationController; RecentsViewController *recentsViewController; - ContactsViewController *contactsViewController; - SettingsViewController *settingsViewController; // mediaPicker @@ -83,34 +76,6 @@ } } - // 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; - } - } - } - - // 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]]) @@ -126,7 +91,7 @@ } // Sanity check - NSAssert(homeViewController &&recentsViewController && contactsViewController && settingsViewController, @"Something wrong in Main.storyboard"); + NSAssert(recentsViewController && settingsViewController, @"Something wrong in Main.storyboard"); } - (void)viewDidAppear:(BOOL)animated @@ -152,10 +117,8 @@ { mxSessionArray = nil; - homeViewController = nil; recentsNavigationController = nil; recentsViewController = nil; - contactsViewController = nil; settingsViewController = nil; [self dismissMediaPicker]; @@ -204,10 +167,6 @@ [recentsViewController.dataSource addMatrixSession:mxSession]; } - // Update home tab - [homeViewController addMatrixSession:mxSession]; - // Update contacts tab - [contactsViewController addMatrixSession:mxSession]; // Update settings tab [settingsViewController addMatrixSession:mxSession]; @@ -220,10 +179,6 @@ // Update recents data source [recentsViewController.dataSource removeMatrixSession:mxSession]; - // Update home tab - [homeViewController removeMatrixSession:mxSession]; - // Update contacts tab - [contactsViewController removeMatrixSession:mxSession]; // Update settings tab [settingsViewController removeMatrixSession:mxSession]; @@ -247,8 +202,7 @@ - (void)showRoomCreationForm { - // Switch in Home Tab - [self setSelectedIndex:TABBAR_HOME_INDEX]; + // TODO } - (void)showRoom:(NSString*)roomId withMatrixSession:(MXSession*)mxSession diff --git a/Vector/ViewController/RecentsViewController.m b/Vector/ViewController/RecentsViewController.m index 279727986..46a526456 100644 --- a/Vector/ViewController/RecentsViewController.m +++ b/Vector/ViewController/RecentsViewController.m @@ -23,6 +23,8 @@ #import "NSBundle+MatrixKit.h" +#import "RecentListDataSource.h" + @interface RecentsViewController () { // Recents refresh handling @@ -132,6 +134,15 @@ [self.recentsTableView deselectRowAtIndexPath:indexPath animated:NO]; } + RecentListDataSource *recentListDataSource = (RecentListDataSource*)self.dataSource; + if (recentListDataSource) + { + [self startActivityIndicator]; + [recentListDataSource refreshPublicRooms:nil onComplete:^{ + [self stopActivityIndicator]; + }]; + } + [self.navigationController.navigationBar addGestureRecognizer:navigationBarTapGesture]; } @@ -172,6 +183,67 @@ } } +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section +{ + return 35; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + // Check whether the selected row is a public room or not + RecentListDataSource *recentListDataSource = (RecentListDataSource*)self.dataSource; + if (recentListDataSource && recentListDataSource.publicRoomsFirstSection != -1 && indexPath.section >= recentListDataSource.publicRoomsFirstSection) + { + MXPublicRoom *publicRoom = [recentListDataSource publicRoomAtIndexPath:indexPath]; + if (publicRoom) + { + // Handle multi-sessions here + [[AppDelegate theDelegate] selectMatrixAccount:^(MXKAccount *selectedAccount) { + // Check whether the user has already joined the selected public room + if ([selectedAccount.mxSession roomWithRoomId:publicRoom.roomId]) + { + // Open selected room + [[AppDelegate theDelegate].masterTabBarController showRoom:publicRoom.roomId withMatrixSession:selectedAccount.mxSession]; + } + else + { + // Join the selected room + UIActivityIndicatorView *loadingWheel = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; + UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; + if (selectedCell) + { + CGPoint center = CGPointMake(selectedCell.frame.size.width / 2, selectedCell.frame.size.height / 2); + loadingWheel.center = center; + [selectedCell addSubview:loadingWheel]; + } + [loadingWheel startAnimating]; + [selectedAccount.mxSession joinRoom:publicRoom.roomId success:^(MXRoom *room) + { + // Show joined room + [loadingWheel stopAnimating]; + [loadingWheel removeFromSuperview]; + [[AppDelegate theDelegate].masterTabBarController showRoom:publicRoom.roomId withMatrixSession:selectedAccount.mxSession]; + } failure:^(NSError *error) + { + NSLog(@"[HomeVC] Failed to join public room (%@): %@", publicRoom.displayname, error); + //Alert user + [loadingWheel stopAnimating]; + [loadingWheel removeFromSuperview]; + [[AppDelegate theDelegate] showErrorAsAlert:error]; + }]; + } + + }]; + } + [tableView deselectRowAtIndexPath:indexPath animated:YES]; + } + else + { + // Let super handle the selected row + [super tableView:tableView didSelectRowAtIndexPath:indexPath]; + } +} + #pragma mark - - (void)selectRoomWithId:(NSString*)roomId inMatrixSession:(MXSession*)matrixSession @@ -220,7 +292,7 @@ - (void)updateNavigationBarTitle { - NSString *title = NSLocalizedStringFromTable(@"recents", @"MatrixConsole", nil); + NSString *title = NSLocalizedStringFromTable(@"recents", @"Vector", nil); if (self.dataSource.unreadCount) { @@ -292,7 +364,7 @@ { __weak typeof(self) weakSelf = self; - markAllAsReadAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"mark_all_as_read_prompt", @"MatrixConsole", nil) message:nil style:MXKAlertStyleAlert]; + markAllAsReadAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"mark_all_as_read_prompt", @"Vector", nil) message:nil style:MXKAlertStyleAlert]; markAllAsReadAlert.cancelButtonIndex = [markAllAsReadAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"no"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { diff --git a/Vector/ViewController/SettingsViewController.h b/Vector/ViewController/SettingsViewController.h index 596b55481..5650aac2d 100644 --- a/Vector/ViewController/SettingsViewController.h +++ b/Vector/ViewController/SettingsViewController.h @@ -16,13 +16,7 @@ #import -@interface SettingsViewController : MXKTableViewController - -/** - The application settings displayed in the view controller. - By default the shared application settings are considered. - */ -@property (nonatomic) MXKAppSettings *settings; +@interface SettingsViewController : MXKTableViewController @end diff --git a/Vector/ViewController/SettingsViewController.m b/Vector/ViewController/SettingsViewController.m index 5c8b1eaeb..6556c175e 100644 --- a/Vector/ViewController/SettingsViewController.m +++ b/Vector/ViewController/SettingsViewController.m @@ -21,20 +21,8 @@ #import "AppDelegate.h" #define SETTINGS_SECTION_ACCOUNTS_INDEX 0 -#define SETTINGS_SECTION_CONTACTS_INDEX 1 -#define SETTINGS_SECTION_ROOMS_INDEX 2 -#define SETTINGS_SECTION_CONFIGURATION_INDEX 3 -#define SETTINGS_SECTION_COMMANDS_INDEX 4 -#define SETTINGS_SECTION_COUNT 5 - -#define SETTINGS_SECTION_ROOMS_DISPLAY_ALL_EVENTS_INDEX 0 -#define SETTINGS_SECTION_ROOMS_SHOW_REDACTIONS_INDEX 1 -#define SETTINGS_SECTION_ROOMS_SHOW_UNSUPPORTED_EVENTS_INDEX 2 -#define SETTINGS_SECTION_ROOMS_SORT_MEMBERS_INDEX 3 -#define SETTINGS_SECTION_ROOMS_DISPLAY_LEFT_MEMBERS_INDEX 4 -#define SETTINGS_SECTION_ROOMS_SET_CACHE_SIZE_INDEX 5 -#define SETTINGS_SECTION_ROOMS_CLEAR_CACHE_INDEX 6 -#define SETTINGS_SECTION_ROOMS_INDEX_COUNT 7 +#define SETTINGS_SECTION_CONFIGURATION_INDEX 1 +#define SETTINGS_SECTION_COUNT 2 @interface SettingsViewController () { @@ -42,25 +30,6 @@ id removedAccountObserver; id accountUserInfoObserver; - // Contacts - UISwitch *contactsSyncSwitch; - // Country codes management - NSArray* countryCodes; - NSString* countryCode; - NSString* selectedCountryCode; - BOOL isSelectingCountryCode; - // Dynamic rows in Contacts section - NSInteger syncLocalContactsRowIndex; - NSInteger countryCodeRowIndex; - - // Rooms settings - UISwitch *allEventsSwitch; - UISwitch *redactionsSwitch; - UISwitch *unsupportedEventsSwitch; - UISwitch *sortMembersSwitch; - UISwitch *displayLeftMembersSwitch; - MXKTableViewCellWithLabelAndSlider* maxCacheSizeCell; - NSUInteger minimumCacheSize; UIButton *clearCacheButton; } @@ -73,17 +42,6 @@ [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. - // Consider the standard settings by default - _settings = [MXKAppSettings standardAppSettings]; - - // Initialize the minimum cache size with the current value - minimumCacheSize = self.minCachesSize; - - // country selection - NSString *path = [[NSBundle mainBundle] pathForResource:@"countryCodes" ofType:@"plist"]; - countryCodes = [NSArray arrayWithContentsOfFile:path]; - isSelectingCountryCode = NO; - // Setup `MXKRoomMemberListViewController` properties self.rageShakeManager = [RageShakeManager sharedManager]; @@ -141,20 +99,6 @@ { [super viewWillAppear:animated]; - if (!_settings) - { - // Consider the standard settings by default - _settings = [MXKAppSettings standardAppSettings]; - } - - selectedCountryCode = countryCode = [_settings phonebookCountryCode]; - - // Update the minimum cache size with the current value - // Dispatch this operation to not freeze the app - dispatch_async(dispatch_get_main_queue(), ^{ - minimumCacheSize = self.minCachesSize; - }); - // Refresh display [self.tableView reloadData]; } @@ -162,18 +106,6 @@ - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; - - // if country has been updated - // update the contact phonenumbers - // and check if they match now to Matrix Users - if (![countryCode isEqualToString:selectedCountryCode]) - { - - [_settings setPhonebookCountryCode:selectedCountryCode]; - countryCode = selectedCountryCode; - } - - countryCode = [_settings phonebookCountryCode]; } #pragma mark - Internal methods @@ -196,15 +128,7 @@ [[NSNotificationCenter defaultCenter] removeObserver:self]; selectedAccount = nil; - - contactsSyncSwitch = nil; - - allEventsSwitch = nil; - redactionsSwitch = nil; - unsupportedEventsSwitch = nil; - sortMembersSwitch = nil; - displayLeftMembersSwitch = nil; - maxCacheSizeCell = nil; + clearCacheButton = nil; } @@ -238,65 +162,12 @@ - (IBAction)onButtonPressed:(id)sender { - if (sender == allEventsSwitch) - { - _settings.showAllEventsInRoomHistory = allEventsSwitch.on; - } - else if (sender == redactionsSwitch) - { - _settings.showRedactionsInRoomHistory = redactionsSwitch.on; - } - else if (sender == unsupportedEventsSwitch) - { - _settings.showUnsupportedEventsInRoomHistory = unsupportedEventsSwitch.on; - } - else if (sender == sortMembersSwitch) - { - _settings.sortRoomMembersUsingLastSeenTime = sortMembersSwitch.on; - } - else if (sender == displayLeftMembersSwitch) - { - _settings.showLeftMembersInRoomMemberList = displayLeftMembersSwitch.on; - } - else if (sender == contactsSyncSwitch) - { - _settings.syncLocalContacts = contactsSyncSwitch.on; - isSelectingCountryCode = NO; - - dispatch_async(dispatch_get_main_queue(), ^{ - [self.tableView reloadData]; - }); - } - else if (sender == clearCacheButton) + if (sender == clearCacheButton) { [[AppDelegate theDelegate] reloadMatrixSessions:YES]; } } -- (IBAction)onSliderValueChange:(id)sender -{ - if (sender == maxCacheSizeCell.mxkSlider) - { - UISlider* slider = maxCacheSizeCell.mxkSlider; - - // check if the upper bounds have been updated - if (slider.maximumValue != self.maxAllowedCachesSize) - { - slider.maximumValue = self.maxAllowedCachesSize; - } - - // check if the value does not exceed the bounds - if (slider.value < minimumCacheSize) - { - slider.value = minimumCacheSize; - } - - [self setCurrentMaxCachesSize:slider.value]; - - maxCacheSizeCell.mxkLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"settings_max_cache_size", @"MatrixConsole", nil), [NSByteCountFormatter stringFromByteCount:self.currentMaxCachesSize countStyle:NSByteCountFormatterCountStyleFile]]; - } -} - #pragma mark - Segues - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender @@ -326,28 +197,9 @@ { count = [[MXKAccountManager sharedManager] accounts].count + 1; // Add one cell in this section to display "logout all" option. } - else if (section == SETTINGS_SECTION_CONTACTS_INDEX) - { - countryCodeRowIndex = syncLocalContactsRowIndex = -1; - - // init row index - syncLocalContactsRowIndex = count++; - if ([_settings syncLocalContacts]) - { - countryCodeRowIndex = count++; - } - } - else if (section == SETTINGS_SECTION_ROOMS_INDEX) - { - count = SETTINGS_SECTION_ROOMS_INDEX_COUNT; - } else if (section == SETTINGS_SECTION_CONFIGURATION_INDEX) { - count = 1; - } - else if (section == SETTINGS_SECTION_COMMANDS_INDEX) - { - count = 1; + count = 2; } return count; @@ -387,8 +239,8 @@ { logoutBtnCell = [[MXKTableViewCellWithButton alloc] init]; } - [logoutBtnCell.mxkButton setTitle:NSLocalizedStringFromTable(@"account_logout_all", @"MatrixConsole", nil) forState:UIControlStateNormal]; - [logoutBtnCell.mxkButton setTitle:NSLocalizedStringFromTable(@"account_logout_all", @"MatrixConsole", nil) forState:UIControlStateHighlighted]; + [logoutBtnCell.mxkButton setTitle:NSLocalizedStringFromTable(@"account_logout_all", @"Vector", nil) forState:UIControlStateNormal]; + [logoutBtnCell.mxkButton setTitle:NSLocalizedStringFromTable(@"account_logout_all", @"Vector", nil) forState:UIControlStateHighlighted]; [logoutBtnCell.mxkButton removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; [logoutBtnCell.mxkButton addTarget:self action:@selector(logout:) forControlEvents:UIControlEventTouchUpInside]; @@ -396,82 +248,27 @@ cell = logoutBtnCell; } } - else if (indexPath.section == SETTINGS_SECTION_CONTACTS_INDEX) + else if (indexPath.section == SETTINGS_SECTION_CONFIGURATION_INDEX) { - if (indexPath.row == syncLocalContactsRowIndex) + if (indexPath.row == 0) { - MXKTableViewCellWithLabelAndSwitch *contactsCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier]]; - if (!contactsCell) + MXKTableViewCellWithTextView *configurationCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithTextView defaultReuseIdentifier]]; + if (!configurationCell) { - contactsCell = [[MXKTableViewCellWithLabelAndSwitch alloc] init]; + configurationCell = [[MXKTableViewCellWithTextView alloc] init]; } - [contactsCell.mxkSwitch addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventValueChanged]; - - contactsCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_contact_sync", @"MatrixConsole", nil); - contactsCell.mxkSwitch.on = [_settings syncLocalContacts]; - contactsSyncSwitch = contactsCell.mxkSwitch; - cell = contactsCell; + NSString* appVersion = [AppDelegate theDelegate].appVersion; + NSString* build = [AppDelegate theDelegate].build; + if (build.length) + { + build = [NSString stringWithFormat:NSLocalizedStringFromTable(@"settings_config_build_number", @"Vector", nil), build]; + } + NSString *configurationFormatText = [NSString stringWithFormat:@"%@\n%@\n%@\n%@", NSLocalizedStringFromTable(@"settings_config_ios_console_version", @"Vector", nil), NSLocalizedStringFromTable(@"settings_config_ios_kit_version", @"Vector", nil), NSLocalizedStringFromTable(@"settings_config_ios_sdk_version", @"Vector", nil), @"%@"]; + configurationCell.mxkTextView.text = [NSString stringWithFormat:configurationFormatText, appVersion, MatrixKitVersion, MatrixSDKVersion, build]; + cell = configurationCell; } - else if (indexPath.row == countryCodeRowIndex) - { - int index = 0; - NSString* countryName = @""; - - for(NSDictionary* dict in countryCodes) - { - if ([[dict valueForKey:@"id"] isEqualToString:selectedCountryCode]) - { - countryName = [dict valueForKey:@"country"]; - break; - } - - index++; - } - - // there is no country code selection - if (!isSelectingCountryCode) - { - MXKTableViewCellWithLabelAndSubLabel *countryCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndSubLabel defaultReuseIdentifier]]; - if (!countryCell) - { - countryCell = [[MXKTableViewCellWithLabelAndSubLabel alloc] init]; - } - - countryCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_country_select", @"MatrixConsole", nil); - countryCell.mxkSublabel.text = countryName; - countryCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; - cell = countryCell; - - } - else - { - // there is a selection in progress - MXKTableViewCellWithPicker *pickerCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithPicker defaultReuseIdentifier]]; - if (!pickerCell) - { - pickerCell = [[MXKTableViewCellWithPicker alloc] init]; - } - - // display a picker - pickerCell.mxkPickerView.delegate = self; - pickerCell.mxkPickerView.dataSource = self; - - if (countryName.length > 0) - { - dispatch_async(dispatch_get_main_queue(), ^{ - [pickerCell.mxkPickerView selectRow:index inComponent:0 animated:NO]; - }); - } - - cell = pickerCell; - } - } - - } - else if (indexPath.section == SETTINGS_SECTION_ROOMS_INDEX) - { - if (indexPath.row == SETTINGS_SECTION_ROOMS_CLEAR_CACHE_INDEX) + else if (indexPath.row == 1) { MXKTableViewCellWithButton *clearCacheBtnCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithButton defaultReuseIdentifier]]; if (!clearCacheBtnCell) @@ -479,7 +276,7 @@ clearCacheBtnCell = [[MXKTableViewCellWithButton alloc] init]; } - NSString *btnTitle = [NSString stringWithFormat:@"%@ (%@)", NSLocalizedStringFromTable(@"settings_clear_cache", @"MatrixConsole", nil), [NSByteCountFormatter stringFromByteCount:self.cachesSize countStyle:NSByteCountFormatterCountStyleFile]]; + NSString *btnTitle = [NSString stringWithFormat:@"%@", NSLocalizedStringFromTable(@"settings_clear_cache", @"Vector", nil)]; [clearCacheBtnCell.mxkButton setTitle:btnTitle forState:UIControlStateNormal]; [clearCacheBtnCell.mxkButton setTitle:btnTitle forState:UIControlStateHighlighted]; @@ -490,95 +287,6 @@ cell = clearCacheBtnCell; } - else if (indexPath.row == SETTINGS_SECTION_ROOMS_SET_CACHE_SIZE_INDEX) - { - maxCacheSizeCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndSlider defaultReuseIdentifier]]; - if (!maxCacheSizeCell) - { - maxCacheSizeCell = [[MXKTableViewCellWithLabelAndSlider alloc] init]; - } - - maxCacheSizeCell.mxkSlider.minimumValue = 0; - maxCacheSizeCell.mxkSlider.maximumValue = self.maxAllowedCachesSize; - maxCacheSizeCell.mxkSlider.value = self.currentMaxCachesSize; - - [self onSliderValueChange:maxCacheSizeCell.mxkSlider]; - - [maxCacheSizeCell.mxkSlider addTarget:self action:@selector(onSliderValueChange:) forControlEvents:UIControlEventValueChanged]; - cell = maxCacheSizeCell; - } - else - { - MXKTableViewCellWithLabelAndSwitch *roomsSettingCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier]]; - if (!roomsSettingCell) - { - roomsSettingCell = [[MXKTableViewCellWithLabelAndSwitch alloc] init]; - } - - [roomsSettingCell.mxkSwitch addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventValueChanged]; - - if (indexPath.row == SETTINGS_SECTION_ROOMS_DISPLAY_ALL_EVENTS_INDEX) - { - roomsSettingCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_display_all_events", @"MatrixConsole", nil); - roomsSettingCell.mxkSwitch.on = [_settings showAllEventsInRoomHistory]; - allEventsSwitch = roomsSettingCell.mxkSwitch; - } - else if (indexPath.row == SETTINGS_SECTION_ROOMS_SHOW_REDACTIONS_INDEX) - { - roomsSettingCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_show_redactions", @"MatrixConsole", nil); - roomsSettingCell.mxkSwitch.on = [_settings showRedactionsInRoomHistory]; - redactionsSwitch = roomsSettingCell.mxkSwitch; - } - else if (indexPath.row == SETTINGS_SECTION_ROOMS_SHOW_UNSUPPORTED_EVENTS_INDEX) - { - roomsSettingCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_show_unsupported_events", @"MatrixConsole", nil); - roomsSettingCell.mxkSwitch.on = [_settings showUnsupportedEventsInRoomHistory]; - unsupportedEventsSwitch = roomsSettingCell.mxkSwitch; - } - else if (indexPath.row == SETTINGS_SECTION_ROOMS_SORT_MEMBERS_INDEX) - { - roomsSettingCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_sort_by_last_seen", @"MatrixConsole", nil); - roomsSettingCell.mxkSwitch.on = [_settings sortRoomMembersUsingLastSeenTime]; - sortMembersSwitch = roomsSettingCell.mxkSwitch; - } - else if (indexPath.row == SETTINGS_SECTION_ROOMS_DISPLAY_LEFT_MEMBERS_INDEX) - { - roomsSettingCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_display_left_members", @"MatrixConsole", nil); - roomsSettingCell.mxkSwitch.on = [_settings showLeftMembersInRoomMemberList]; - displayLeftMembersSwitch = roomsSettingCell.mxkSwitch; - } - - cell = roomsSettingCell; - } - } - else if (indexPath.section == SETTINGS_SECTION_CONFIGURATION_INDEX) - { - MXKTableViewCellWithTextView *configurationCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithTextView defaultReuseIdentifier]]; - if (!configurationCell) - { - configurationCell = [[MXKTableViewCellWithTextView alloc] init]; - } - - NSString* appVersion = [AppDelegate theDelegate].appVersion; - NSString* build = [AppDelegate theDelegate].build; - if (build.length) - { - build = [NSString stringWithFormat:NSLocalizedStringFromTable(@"settings_config_build_number", @"MatrixConsole", nil), build]; - } - NSString *configurationFormatText = [NSString stringWithFormat:@"%@\n%@\n%@\n%@", NSLocalizedStringFromTable(@"settings_config_ios_console_version", @"MatrixConsole", nil), NSLocalizedStringFromTable(@"settings_config_ios_kit_version", @"MatrixConsole", nil), NSLocalizedStringFromTable(@"settings_config_ios_sdk_version", @"MatrixConsole", nil), @"%@"]; - configurationCell.mxkTextView.text = [NSString stringWithFormat:configurationFormatText, appVersion, MatrixKitVersion, MatrixSDKVersion, build]; - cell = configurationCell; - } - else if (indexPath.section == SETTINGS_SECTION_COMMANDS_INDEX) - { - MXKTableViewCellWithTextView *commandsCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithTextView defaultReuseIdentifier]]; - if (!commandsCell) - { - commandsCell = [[MXKTableViewCellWithTextView alloc] init]; - } - - commandsCell.mxkTextView.text = NSLocalizedStringFromTable(@"settings_command_commands", @"MatrixConsole", nil); - cell = commandsCell; } return cell; @@ -592,23 +300,7 @@ { return 50; } - else if (indexPath.section == SETTINGS_SECTION_CONTACTS_INDEX) - { - - if ((indexPath.row == countryCodeRowIndex) && isSelectingCountryCode) - { - - return 164; - } - } - else if (indexPath.section == SETTINGS_SECTION_ROOMS_INDEX) - { - if (indexPath.row == SETTINGS_SECTION_ROOMS_SET_CACHE_SIZE_INDEX) - { - return 88; - } - } - else if (indexPath.section == SETTINGS_SECTION_CONFIGURATION_INDEX) + else if (indexPath.section == SETTINGS_SECTION_CONFIGURATION_INDEX && indexPath.row == 0) { UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, MAXFLOAT)]; textView.font = [UIFont systemFontOfSize:14]; @@ -616,21 +308,13 @@ NSString* build = [AppDelegate theDelegate].build; if (build.length) { - build = [NSString stringWithFormat:NSLocalizedStringFromTable(@"settings_config_build_number", @"MatrixConsole", nil), build]; + build = [NSString stringWithFormat:NSLocalizedStringFromTable(@"settings_config_build_number", @"Vector", nil), build]; } - NSString *configurationFormatText = [NSString stringWithFormat:@"%@\n%@\n%@\n%@", NSLocalizedStringFromTable(@"settings_config_ios_console_version", @"MatrixConsole", nil), NSLocalizedStringFromTable(@"settings_config_ios_kit_version", @"MatrixConsole", nil), NSLocalizedStringFromTable(@"settings_config_ios_sdk_version", @"MatrixConsole", nil), @"%@"]; + NSString *configurationFormatText = [NSString stringWithFormat:@"%@\n%@\n%@\n%@", NSLocalizedStringFromTable(@"settings_config_ios_console_version", @"Vector", nil), NSLocalizedStringFromTable(@"settings_config_ios_kit_version", @"Vector", nil), NSLocalizedStringFromTable(@"settings_config_ios_sdk_version", @"Vector", nil), @"%@"]; textView.text = [NSString stringWithFormat:configurationFormatText, appVersion, MatrixKitVersion, MatrixSDKVersion, build]; CGSize contentSize = [textView sizeThatFits:textView.frame.size]; return contentSize.height + 1; } - else if (indexPath.section == SETTINGS_SECTION_COMMANDS_INDEX) - { - UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, MAXFLOAT)]; - textView.font = [UIFont systemFontOfSize:14]; - textView.text = NSLocalizedStringFromTable(@"settings_command_commands", @"MatrixConsole", nil); - CGSize contentSize = [textView sizeThatFits:textView.frame.size]; - return contentSize.height + 1; - } return 44; } @@ -656,7 +340,7 @@ if (section == SETTINGS_SECTION_ACCOUNTS_INDEX) { - sectionLabel.text = NSLocalizedStringFromTable(@"accounts", @"MatrixConsole", nil); + sectionLabel.text = NSLocalizedStringFromTable(@"accounts", @"Vector", nil); UIButton *addAccount = [UIButton buttonWithType:UIButtonTypeContactAdd]; [addAccount addTarget:self action:@selector(addAccount:) forControlEvents:UIControlEventTouchUpInside]; @@ -671,21 +355,9 @@ sectionHeader.userInteractionEnabled = YES; } - else if (section == SETTINGS_SECTION_CONTACTS_INDEX) - { - sectionLabel.text = NSLocalizedStringFromTable(@"contacts", @"MatrixConsole", nil); - } - else if (section == SETTINGS_SECTION_ROOMS_INDEX) - { - sectionLabel.text = NSLocalizedStringFromTable(@"settings_title_rooms", @"MatrixConsole", nil); - } else if (section == SETTINGS_SECTION_CONFIGURATION_INDEX) { - sectionLabel.text = NSLocalizedStringFromTable(@"settings_title_config", @"MatrixConsole", nil); - } - else if (section == SETTINGS_SECTION_COMMANDS_INDEX) - { - sectionLabel.text = NSLocalizedStringFromTable(@"settings_title_commands", @"MatrixConsole", nil); + sectionLabel.text = NSLocalizedStringFromTable(@"settings_title_config", @"Vector", nil); } else { @@ -708,104 +380,8 @@ [self performSegueWithIdentifier:@"showAccountDetails" sender:self]; } } - else if (indexPath.section == SETTINGS_SECTION_CONTACTS_INDEX) - { - if (indexPath.row == countryCodeRowIndex) - { - isSelectingCountryCode = YES; - - dispatch_async(dispatch_get_main_queue(), ^{ - [self.tableView reloadData]; - }); - } - } [aTableView deselectRowAtIndexPath:indexPath animated:YES]; } } -#pragma mark - UIPickerViewDataSource - -- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView -{ - return 1; -} - -- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component -{ - return [countryCodes count]; -} - -#pragma mark - UIPickerViewDelegate - -- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component -{ - return [[countryCodes objectAtIndex:row] valueForKey:@"country"]; -} - -- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component -{ - // sanity check - if ((row >= 0) && (row < countryCodes.count)) - { - NSDictionary* dict = [countryCodes objectAtIndex:row]; - selectedCountryCode = [dict valueForKey:@"id"]; - } - - isSelectingCountryCode = NO; - - dispatch_async(dispatch_get_main_queue(), ^{ - [self.tableView reloadData]; - }); -} - -#pragma mark - Cache handling - -// return the MX cache size in bytes -- (NSUInteger)MXCacheSize -{ - NSUInteger cacheSize = 0; - - NSArray *mxSessions = self.mxSessions; - for (MXSession *mxSession in mxSessions) - { - if (mxSession.store && [mxSession.store isKindOfClass:[MXFileStore class]]) - { - MXFileStore *fileStore = (MXFileStore*)mxSession.store; - cacheSize += fileStore.diskUsage; - } - } - - return cacheSize; -} - -// return the sum of the caches (MX cache + media cache ...) in bytes -- (NSUInteger)cachesSize -{ - return self.MXCacheSize + [MXKMediaManager cacheSize]; -} - -// defines the min allow cache size in bytes -- (NSUInteger)minCachesSize -{ - // add a 50MB margin to avoid cache file deletion - return self.MXCacheSize + [MXKMediaManager minCacheSize] + 50 * 1024 * 1024; -} - -// defines the current max caches size in bytes -- (NSUInteger)currentMaxCachesSize -{ - return self.MXCacheSize + [MXKMediaManager currentMaxCacheSize]; -} - -- (void)setCurrentMaxCachesSize:(NSUInteger)maxCachesSize -{ - [MXKMediaManager setCurrentMaxCacheSize:maxCachesSize - self.MXCacheSize]; -} - -// defines the max allowed caches size in bytes -- (NSUInteger) maxAllowedCachesSize -{ - return self.MXCacheSize + [MXKMediaManager maxAllowedCacheSize]; -} - @end