From 4ddff31ea86fbecf7954b5429184b3cabf77365d Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Fri, 12 Apr 2024 11:42:51 +0200 Subject: [PATCH 1/4] Add "Include calls in recents" setting. Signed-off-by: Ivan Sein --- NextcloudTalk/CallKitManager.m | 1 + NextcloudTalk/NCUserDefaults.h | 2 ++ NextcloudTalk/NCUserDefaults.m | 17 +++++++++++++++ .../SettingsTableViewController.swift | 21 +++++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/NextcloudTalk/CallKitManager.m b/NextcloudTalk/CallKitManager.m index 9fc279ac9..f3296d114 100644 --- a/NextcloudTalk/CallKitManager.m +++ b/NextcloudTalk/CallKitManager.m @@ -104,6 +104,7 @@ - (CXProvider *)provider configuration.supportsVideo = YES; configuration.maximumCallGroups = 1; configuration.maximumCallsPerCallGroup = 1; + configuration.includesCallsInRecents = [NCUserDefaults includeCallsInRecents]; configuration.supportedHandleTypes = [NSSet setWithObjects:@(CXHandleTypePhoneNumber), @(CXHandleTypeEmailAddress), @(CXHandleTypeGeneric), nil]; configuration.iconTemplateImageData = UIImagePNGRepresentation([UIImage imageNamed:@"app-logo-callkit"]); _provider = [[CXProvider alloc] initWithConfiguration:configuration]; diff --git a/NextcloudTalk/NCUserDefaults.h b/NextcloudTalk/NCUserDefaults.h index 92ef70168..7dff9c67c 100644 --- a/NextcloudTalk/NCUserDefaults.h +++ b/NextcloudTalk/NCUserDefaults.h @@ -31,6 +31,8 @@ NS_ASSUME_NONNULL_BEGIN + (NSInteger)preferredCameraFlashMode; + (void)setBackgroundBlurEnabled:(BOOL)enabled; + (BOOL)backgroundBlurEnabled; ++ (void)setIncludeCallsInRecentsEnabled:(BOOL)enabled; ++ (BOOL)includeCallsInRecents; @end diff --git a/NextcloudTalk/NCUserDefaults.m b/NextcloudTalk/NCUserDefaults.m index edb985d46..cd6bac36c 100644 --- a/NextcloudTalk/NCUserDefaults.m +++ b/NextcloudTalk/NCUserDefaults.m @@ -29,6 +29,7 @@ @implementation NCUserDefaults NSString * const kNCPreferredCameraFlashMode = @"ncPreferredCameraFlashMode"; NSString * const kNCBackgroundBlurEnabled = @"ncBackgroundBlurEnabled"; +NSString * const kNCIncludeCallsInRecents = @"ncIncludeCallsInRecents"; + (void)setPreferredCameraFlashMode:(NSInteger)flashMode { @@ -50,4 +51,20 @@ + (BOOL)backgroundBlurEnabled return [[[NSUserDefaults standardUserDefaults] objectForKey:kNCBackgroundBlurEnabled] boolValue]; } ++ (void)setIncludeCallsInRecentsEnabled:(BOOL)enabled +{ + [[NSUserDefaults standardUserDefaults] setObject:@(enabled) forKey:kNCIncludeCallsInRecents]; +} + ++ (BOOL)includeCallsInRecents +{ + id includeCallsInRecentsObject = [[NSUserDefaults standardUserDefaults] objectForKey:kNCIncludeCallsInRecents]; + if (!includeCallsInRecentsObject) { + [self setIncludeCallsInRecentsEnabled:YES]; + return YES; + } + + return [includeCallsInRecentsObject boolValue]; +} + @end diff --git a/NextcloudTalk/SettingsTableViewController.swift b/NextcloudTalk/SettingsTableViewController.swift index fe4828db6..85abd17fe 100644 --- a/NextcloudTalk/SettingsTableViewController.swift +++ b/NextcloudTalk/SettingsTableViewController.swift @@ -44,6 +44,7 @@ enum AccountSettingsOptions: Int { enum ConfigurationSectionOption: Int { case kConfigurationSectionOptionVideo = 0 + case kConfigurationSectionOptionRecents } enum AdvancedSectionOption: Int { @@ -73,6 +74,7 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate, U var contactSyncSwitch = UISwitch() var setPhoneAction: UIAlertAction? var phoneUtil = NBPhoneNumberUtil() + var includeInRecentsSwitch = UISwitch() var totalImageCacheSize = 0 var totalFileCacheSize = 0 @@ -116,6 +118,9 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate, U readStatusSwitch.frame = .zero readStatusSwitch.addTarget(self, action: #selector(readStatusValueChanged(_:)), for: .valueChanged) + includeInRecentsSwitch.frame = .zero + includeInRecentsSwitch.addTarget(self, action: #selector(includeInRecentsValueChanged(_:)), for: .valueChanged) + typingIndicatorSwitch.frame = .zero typingIndicatorSwitch.addTarget(self, action: #selector(typingIndicatorValueChanged(_:)), for: .valueChanged) @@ -217,6 +222,9 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate, U // Video quality options.append(ConfigurationSectionOption.kConfigurationSectionOptionVideo.rawValue) + // Calls in recents + options.append(ConfigurationSectionOption.kConfigurationSectionOptionRecents.rawValue) + return options } @@ -534,6 +542,10 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate, U self.present(errorDialog, animated: true, completion: nil) } + @objc func includeInRecentsValueChanged(_ sender: Any?) { + NCUserDefaults.setIncludeCallsInRecentsEnabled(includeInRecentsSwitch.isOn) + } + // MARK: - Advanced actions func diagnosticsPressed() { @@ -926,6 +938,15 @@ extension SettingsTableViewController { resolutionLabel.textColor = .secondaryLabel resolutionLabel.sizeToFit() cell.accessoryView = resolutionLabel + + case ConfigurationSectionOption.kConfigurationSectionOptionRecents.rawValue: + cell = UITableViewCell(style: .default, reuseIdentifier: videoConfigurationCellIdentifier) + cell.textLabel?.text = NSLocalizedString("Include calls in recents", comment: "") + cell.setSettingsImage(image: UIImage(systemName: "clock")?.applyingSymbolConfiguration(iconConfiguration)) + cell.selectionStyle = .none + cell.accessoryView = includeInRecentsSwitch + includeInRecentsSwitch.isOn = NCUserDefaults.includeCallsInRecents() + default: break } From 9c70a44a9e0b02ddb6ee45345e5569518b2433d5 Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Fri, 12 Apr 2024 11:43:35 +0200 Subject: [PATCH 2/4] Update localizable strings file. Signed-off-by: Ivan Sein --- NextcloudTalk/en.lproj/Localizable.strings | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NextcloudTalk/en.lproj/Localizable.strings b/NextcloudTalk/en.lproj/Localizable.strings index 4e985f172..7fb69e58d 100644 --- a/NextcloudTalk/en.lproj/Localizable.strings +++ b/NextcloudTalk/en.lproj/Localizable.strings @@ -898,6 +898,9 @@ /* No comment provided by engineer. */ "in" = "in"; +/* No comment provided by engineer. */ +"Include calls in recents" = "Include calls in recents"; + /* Internal signaling used */ "Internal" = "Internal"; From b594c18cfb1e1751dfe0a9168d428d339e8683b6 Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Fri, 12 Apr 2024 12:30:52 +0200 Subject: [PATCH 3/4] Update setting text. Signed-off-by: Ivan Sein --- NextcloudTalk/SettingsTableViewController.swift | 2 +- NextcloudTalk/en.lproj/Localizable.strings | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NextcloudTalk/SettingsTableViewController.swift b/NextcloudTalk/SettingsTableViewController.swift index 85abd17fe..67b6fbdcc 100644 --- a/NextcloudTalk/SettingsTableViewController.swift +++ b/NextcloudTalk/SettingsTableViewController.swift @@ -941,7 +941,7 @@ extension SettingsTableViewController { case ConfigurationSectionOption.kConfigurationSectionOptionRecents.rawValue: cell = UITableViewCell(style: .default, reuseIdentifier: videoConfigurationCellIdentifier) - cell.textLabel?.text = NSLocalizedString("Include calls in recents", comment: "") + cell.textLabel?.text = NSLocalizedString("Include calls in call history", comment: "") cell.setSettingsImage(image: UIImage(systemName: "clock")?.applyingSymbolConfiguration(iconConfiguration)) cell.selectionStyle = .none cell.accessoryView = includeInRecentsSwitch diff --git a/NextcloudTalk/en.lproj/Localizable.strings b/NextcloudTalk/en.lproj/Localizable.strings index 7fb69e58d..32c53ba17 100644 --- a/NextcloudTalk/en.lproj/Localizable.strings +++ b/NextcloudTalk/en.lproj/Localizable.strings @@ -899,7 +899,7 @@ "in" = "in"; /* No comment provided by engineer. */ -"Include calls in recents" = "Include calls in recents"; +"Include calls in call history" = "Include calls in call history"; /* Internal signaling used */ "Internal" = "Internal"; From 520512731a67efdb5f2740c61ac44573a3d61468 Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Fri, 12 Apr 2024 17:38:50 +0200 Subject: [PATCH 4/4] Change setting icon and change provider configuration every time the setting changes. Signed-off-by: Ivan Sein --- NextcloudTalk/CallKitManager.h | 1 + NextcloudTalk/CallKitManager.m | 29 ++++++++++++++----- NextcloudTalk/NCUserDefaults.m | 2 +- .../SettingsTableViewController.swift | 3 +- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/NextcloudTalk/CallKitManager.h b/NextcloudTalk/CallKitManager.h index ea24456f6..294be1a73 100644 --- a/NextcloudTalk/CallKitManager.h +++ b/NextcloudTalk/CallKitManager.h @@ -52,6 +52,7 @@ extern NSString * const CallKitManagerDidFailRequestingCallTransactionNotificati + (instancetype)sharedInstance; + (BOOL)isCallKitAvailable; +- (void)setDefaultProviderConfiguration; - (void)reportIncomingCall:(NSString *)token withDisplayName:(NSString *)displayName forAccountId:(NSString *)accountId; - (void)reportIncomingCallForNonCallKitDevicesWithPushNotification:(NCPushNotification *)pushNotification; - (void)reportIncomingCallForOldAccount; diff --git a/NextcloudTalk/CallKitManager.m b/NextcloudTalk/CallKitManager.m index f3296d114..dd0259a6c 100644 --- a/NextcloudTalk/CallKitManager.m +++ b/NextcloudTalk/CallKitManager.m @@ -100,14 +100,7 @@ + (BOOL)isCallKitAvailable - (CXProvider *)provider { if (!_provider) { - CXProviderConfiguration *configuration = [[CXProviderConfiguration alloc] init]; - configuration.supportsVideo = YES; - configuration.maximumCallGroups = 1; - configuration.maximumCallsPerCallGroup = 1; - configuration.includesCallsInRecents = [NCUserDefaults includeCallsInRecents]; - configuration.supportedHandleTypes = [NSSet setWithObjects:@(CXHandleTypePhoneNumber), @(CXHandleTypeEmailAddress), @(CXHandleTypeGeneric), nil]; - configuration.iconTemplateImageData = UIImagePNGRepresentation([UIImage imageNamed:@"app-logo-callkit"]); - _provider = [[CXProvider alloc] initWithConfiguration:configuration]; + _provider = [[CXProvider alloc] initWithConfiguration:[self defaultProviderConfiguration]]; [_provider setDelegate:self queue:nil]; } return _provider; @@ -135,6 +128,19 @@ - (CXCallUpdate *)defaultCallUpdate return update; } +- (CXProviderConfiguration *)defaultProviderConfiguration +{ + CXProviderConfiguration *configuration = [[CXProviderConfiguration alloc] init]; + configuration.supportsVideo = YES; + configuration.maximumCallGroups = 1; + configuration.maximumCallsPerCallGroup = 1; + configuration.includesCallsInRecents = [NCUserDefaults includeCallsInRecents]; + configuration.supportedHandleTypes = [NSSet setWithObjects:@(CXHandleTypePhoneNumber), @(CXHandleTypeEmailAddress), @(CXHandleTypeGeneric), nil]; + configuration.iconTemplateImageData = UIImagePNGRepresentation([UIImage imageNamed:@"app-logo-callkit"]); + + return configuration; +} + - (CallKitCall *)callForToken:(NSString *)token { for (CallKitCall *call in [_calls allValues]) { @@ -148,6 +154,13 @@ - (CallKitCall *)callForToken:(NSString *)token #pragma mark - Actions +- (void)setDefaultProviderConfiguration +{ + if (_provider) { + [_provider setConfiguration:[self defaultProviderConfiguration]]; + } +} + - (void)reportIncomingCall:(NSString *)token withDisplayName:(NSString *)displayName forAccountId:(NSString *)accountId { BOOL ongoingCalls = _calls.count > 0; diff --git a/NextcloudTalk/NCUserDefaults.m b/NextcloudTalk/NCUserDefaults.m index cd6bac36c..20ab91753 100644 --- a/NextcloudTalk/NCUserDefaults.m +++ b/NextcloudTalk/NCUserDefaults.m @@ -59,7 +59,7 @@ + (void)setIncludeCallsInRecentsEnabled:(BOOL)enabled + (BOOL)includeCallsInRecents { id includeCallsInRecentsObject = [[NSUserDefaults standardUserDefaults] objectForKey:kNCIncludeCallsInRecents]; - if (!includeCallsInRecentsObject) { + if (includeCallsInRecentsObject == nil) { [self setIncludeCallsInRecentsEnabled:YES]; return YES; } diff --git a/NextcloudTalk/SettingsTableViewController.swift b/NextcloudTalk/SettingsTableViewController.swift index 67b6fbdcc..8660b58be 100644 --- a/NextcloudTalk/SettingsTableViewController.swift +++ b/NextcloudTalk/SettingsTableViewController.swift @@ -544,6 +544,7 @@ class SettingsTableViewController: UITableViewController, UITextFieldDelegate, U @objc func includeInRecentsValueChanged(_ sender: Any?) { NCUserDefaults.setIncludeCallsInRecentsEnabled(includeInRecentsSwitch.isOn) + CallKitManager.sharedInstance().setDefaultProviderConfiguration() } // MARK: - Advanced actions @@ -942,7 +943,7 @@ extension SettingsTableViewController { case ConfigurationSectionOption.kConfigurationSectionOptionRecents.rawValue: cell = UITableViewCell(style: .default, reuseIdentifier: videoConfigurationCellIdentifier) cell.textLabel?.text = NSLocalizedString("Include calls in call history", comment: "") - cell.setSettingsImage(image: UIImage(systemName: "clock")?.applyingSymbolConfiguration(iconConfiguration)) + cell.setSettingsImage(image: UIImage(systemName: "clock.arrow.circlepath")?.applyingSymbolConfiguration(iconConfiguration)) cell.selectionStyle = .none cell.accessoryView = includeInRecentsSwitch includeInRecentsSwitch.isOn = NCUserDefaults.includeCallsInRecents()