From f1d2c0c476ec0cb90606d3dfb4fda15ae66c50c9 Mon Sep 17 00:00:00 2001 From: Denis Morozov Date: Fri, 16 Jun 2017 19:21:07 +0300 Subject: [PATCH] Add call section to settings screen --- Riot/Assets/en.lproj/Vector.strings | 4 + Riot/ViewController/SettingsViewController.m | 91 ++++++++++++++++---- 2 files changed, 79 insertions(+), 16 deletions(-) diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 04e01d3bc..90e3367bb 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -260,6 +260,7 @@ "settings_user_settings" = "USER SETTINGS"; "settings_notifications_settings" = "NOTIFICATION SETTINGS"; +"settings_calls_settings" = "CALLS"; "settings_ignored_users" = "IGNORED USERS"; "settings_contacts" = "LOCAL CONTACTS"; "settings_advanced" = "ADVANCED"; @@ -298,6 +299,9 @@ //"settings_join_leave_rooms" = "When people join or leave rooms"; //"settings_call_invitations" = "Call invitations"; +"settings_enable_callkit" = "Integrated calling"; +"settings_callkit_info" = "Receive incoming calls on your lock screen. See your Riot calls in the system's call history. If iCloud is enabled, this call history will be shared with Apple."; + "settings_unignore_user" = "Show all messages from %@?"; "settings_contacts_discover_matrix_users" = "Use emails and phone numbers to discover users"; diff --git a/Riot/ViewController/SettingsViewController.m b/Riot/ViewController/SettingsViewController.m index 5d3cb9cd6..9524af54c 100644 --- a/Riot/ViewController/SettingsViewController.m +++ b/Riot/ViewController/SettingsViewController.m @@ -17,34 +17,29 @@ #import "SettingsViewController.h" -#import "RageShakeManager.h" - -#import "AppDelegate.h" - -#import "RiotDesignValues.h" - -#import "AvatarGenerator.h" - -#import +#import #import #import +#import +#import -#import "MXKEncryptionKeysExportView.h" - +#import "AppDelegate.h" +#import "AvatarGenerator.h" #import "CountryPickerViewController.h" +#import "MXKEncryptionKeysExportView.h" +#import "NBPhoneNumberUtil.h" +#import "RageShakeManager.h" +#import "RiotDesignValues.h" #import "TableViewCellWithPhoneNumberTextField.h" -#import "NBPhoneNumberUtil.h" - -#import "OLMKit/OLMKit.h" - -NSString* const kSettingsViewControllerPhoneBookCountryCellId = @"kSettingsViewControllerPhoneBookCountryCellId"; +static NSString* const kSettingsViewControllerPhoneBookCountryCellId = @"kSettingsViewControllerPhoneBookCountryCellId"; enum { SETTINGS_SECTION_SIGN_OUT_INDEX = 0, SETTINGS_SECTION_USER_SETTINGS_INDEX, SETTINGS_SECTION_NOTIFICATIONS_SETTINGS_INDEX, + SETTINGS_SECTION_CALLS_INDEX, SETTINGS_SECTION_IGNORED_USERS_INDEX, SETTINGS_SECTION_CONTACTS_INDEX, SETTINGS_SECTION_ADVANCED_INDEX, @@ -68,6 +63,13 @@ enum NOTIFICATION_SETTINGS_COUNT }; +enum +{ + CALLS_ENABLE_CALLKIT_INDEX = 0, + CALLS_DESCRIPTION_INDEX, + CALLS_COUNT +}; + enum { OTHER_VERSION_INDEX = 0, @@ -1075,6 +1077,13 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); { count = NOTIFICATION_SETTINGS_COUNT; } + else if (section == SETTINGS_SECTION_CALLS_INDEX) + { + if ([MXCallKitAdapter callKitAvailable]) + { + count = CALLS_COUNT; + } + } else if (section == SETTINGS_SECTION_IGNORED_USERS_INDEX) { if ([AppDelegate theDelegate].mxSessions.count > 0) @@ -1516,6 +1525,29 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); cell = globalInfoCell; } } + else if (section == SETTINGS_SECTION_CALLS_INDEX) + { + if (row == CALLS_ENABLE_CALLKIT_INDEX) + { + MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath]; + labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_enable_callkit", @"Vector", nil); + labelAndSwitchCell.mxkSwitch.on = [MXKAppSettings standardAppSettings].isCallKitEnabled; + labelAndSwitchCell.mxkSwitch.enabled = YES; + [labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; + [labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleCallKit:) forControlEvents:UIControlEventTouchUpInside]; + + cell = labelAndSwitchCell; + } + else if (row == CALLS_DESCRIPTION_INDEX) + { + MXKTableViewCell *globalInfoCell = [self getDefaultTableViewCell:tableView]; + globalInfoCell.textLabel.text = NSLocalizedStringFromTable(@"settings_callkit_info", @"Vector", nil); + globalInfoCell.textLabel.numberOfLines = 0; + globalInfoCell.selectionStyle = UITableViewCellSelectionStyleNone; + + cell = globalInfoCell; + } + } else if (section == SETTINGS_SECTION_IGNORED_USERS_INDEX) { MXKTableViewCell *ignoredUserCell = [self getDefaultTableViewCell:tableView]; @@ -1798,6 +1830,13 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); { return NSLocalizedStringFromTable(@"settings_notifications_settings", @"Vector", nil); } + else if (section == SETTINGS_SECTION_CALLS_INDEX) + { + if ([MXCallKitAdapter callKitAvailable]) + { + return NSLocalizedStringFromTable(@"settings_calls_settings", @"Vector", nil); + } + } else if (section == SETTINGS_SECTION_IGNORED_USERS_INDEX) { // Check whether this section is visible @@ -1892,6 +1931,13 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); } } } + else if (section == SETTINGS_SECTION_CALLS_INDEX) + { + if (![MXCallKitAdapter callKitAvailable]) + { + return SECTION_TITLE_PADDING_WHEN_HIDDEN; + } + } return 24; } @@ -1910,6 +1956,13 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); } } } + else if (section == SETTINGS_SECTION_CALLS_INDEX) + { + if (![MXCallKitAdapter callKitAvailable]) + { + return SECTION_TITLE_PADDING_WHEN_HIDDEN; + } + } return 24; } @@ -2311,6 +2364,12 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); } } +- (void)toggleCallKit:(id)sender +{ + UISwitch *switchButton = (UISwitch*)sender; + [MXKAppSettings standardAppSettings].enableCallKit = switchButton.isOn; +} + - (void)toggleLocalContactsSync:(id)sender { UISwitch *switchButton = (UISwitch*)sender;