2020-01-28 20:09:51 +00:00
|
|
|
/*
|
2020-01-28 21:05:11 +00:00
|
|
|
Copyright 2020 New Vector Ltd
|
2020-01-28 20:09:51 +00:00
|
|
|
|
|
|
|
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 "SecurityViewController.h"
|
|
|
|
|
|
|
|
#import <MatrixKit/MatrixKit.h>
|
|
|
|
|
|
|
|
#import <OLMKit/OLMKit.h>
|
|
|
|
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
#import "AvatarGenerator.h"
|
|
|
|
|
|
|
|
#import "ThemeService.h"
|
|
|
|
|
|
|
|
#import "Riot-Swift.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
SETTINGS_SECTION_DEVICES_INDEX,
|
2020-01-28 20:09:51 +00:00
|
|
|
SETTINGS_SECTION_CRYPTOGRAPHY_INDEX,
|
|
|
|
SETTINGS_SECTION_KEYBACKUP_INDEX,
|
|
|
|
SETTINGS_SECTION_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CRYPTOGRAPHY_INFO_INDEX = 0,
|
|
|
|
CRYPTOGRAPHY_BLACKLIST_UNVERIFIED_DEVICES_INDEX,
|
|
|
|
CRYPTOGRAPHY_EXPORT_INDEX,
|
|
|
|
CRYPTOGRAPHY_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
DEVICES_DESCRIPTION_INDEX = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-01-28 21:36:50 +00:00
|
|
|
@interface SecurityViewController () <
|
|
|
|
MXKDataSourceDelegate,
|
|
|
|
MXKDeviceViewDelegate,
|
2020-01-28 20:09:51 +00:00
|
|
|
SettingsKeyBackupTableViewSectionDelegate,
|
|
|
|
MXKEncryptionInfoViewDelegate,
|
|
|
|
KeyBackupSetupCoordinatorBridgePresenterDelegate,
|
|
|
|
KeyBackupRecoverCoordinatorBridgePresenterDelegate,
|
2020-01-28 21:36:50 +00:00
|
|
|
UIDocumentInteractionControllerDelegate>
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
|
|
|
// Current alert (if any).
|
|
|
|
UIAlertController *currentAlert;
|
|
|
|
|
|
|
|
// Devices
|
|
|
|
NSMutableArray<MXDevice *> *devicesArray;
|
|
|
|
DeviceView *deviceView;
|
|
|
|
|
|
|
|
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
|
|
|
|
id kAppDelegateDidTapStatusBarNotificationObserver;
|
|
|
|
|
|
|
|
// Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change.
|
|
|
|
id kThemeServiceDidChangeThemeNotificationObserver;
|
|
|
|
|
|
|
|
// The view used to export e2e keys
|
|
|
|
MXKEncryptionKeysExportView *exportView;
|
|
|
|
|
|
|
|
// The document interaction Controller used to export e2e keys
|
|
|
|
UIDocumentInteractionController *documentInteractionController;
|
|
|
|
NSURL *keyExportsFile;
|
|
|
|
NSTimer *keyExportsFileDeletionTimer;
|
|
|
|
|
|
|
|
// The current pushed view controller
|
|
|
|
UIViewController *pushedViewController;
|
|
|
|
|
|
|
|
SettingsKeyBackupTableViewSection *keyBackupSection;
|
|
|
|
KeyBackupSetupCoordinatorBridgePresenter *keyBackupSetupCoordinatorBridgePresenter;
|
|
|
|
KeyBackupRecoverCoordinatorBridgePresenter *keyBackupRecoverCoordinatorBridgePresenter;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SecurityViewController
|
|
|
|
|
|
|
|
#pragma mark - Setup & Teardown
|
|
|
|
|
|
|
|
+ (SecurityViewController*)instantiateWithMatrixSession:(MXSession*)matrixSession
|
|
|
|
{
|
|
|
|
SecurityViewController* viewController = [[UIStoryboard storyboardWithName:@"Security" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
|
|
|
|
[viewController addMatrixSession:matrixSession];
|
|
|
|
return viewController;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - View life cycle
|
|
|
|
|
|
|
|
- (void)finalizeInit
|
|
|
|
{
|
|
|
|
[super finalizeInit];
|
|
|
|
|
|
|
|
// Setup `MXKViewControllerHandling` properties
|
|
|
|
self.enableBarTintColorStatusChange = NO;
|
|
|
|
self.rageShakeManager = [RageShakeManager sharedManager];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view, typically from a nib.
|
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
self.navigationItem.title = NSLocalizedStringFromTable(@"security_title", @"Vector", nil);
|
2020-01-28 20:09:51 +00:00
|
|
|
|
|
|
|
// Remove back bar button title when pushing a view controller
|
|
|
|
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
[self.tableView registerClass:MXKTableViewCellWithLabelAndSwitch.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier]];
|
|
|
|
[self.tableView registerNib:MXKTableViewCellWithTextView.nib forCellReuseIdentifier:[MXKTableViewCellWithTextView defaultReuseIdentifier]];
|
|
|
|
|
|
|
|
// Enable self sizing cells
|
|
|
|
self.tableView.rowHeight = UITableViewAutomaticDimension;
|
|
|
|
self.tableView.estimatedRowHeight = 50;
|
|
|
|
|
|
|
|
if (self.mainSession.crypto.backup)
|
|
|
|
{
|
|
|
|
MXDeviceInfo *deviceInfo = [self.mainSession.crypto.deviceList storedDevice:self.mainSession.matrixRestClient.credentials.userId
|
|
|
|
deviceId:self.mainSession.matrixRestClient.credentials.deviceId];
|
|
|
|
|
|
|
|
if (deviceInfo)
|
|
|
|
{
|
|
|
|
keyBackupSection = [[SettingsKeyBackupTableViewSection alloc] initWithKeyBackup:self.mainSession.crypto.backup userDevice:deviceInfo];
|
|
|
|
keyBackupSection.delegate = self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Observe user interface theme change.
|
|
|
|
kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
|
|
|
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
|
|
|
|
}];
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)userInterfaceThemeDidChange
|
|
|
|
{
|
|
|
|
[ThemeService.shared.theme applyStyleOnNavigationBar:self.navigationController.navigationBar];
|
|
|
|
|
|
|
|
self.activityIndicator.backgroundColor = ThemeService.shared.theme.overlayBackgroundColor;
|
|
|
|
|
|
|
|
// Check the table view style to select its bg color.
|
|
|
|
self.tableView.backgroundColor = ((self.tableView.style == UITableViewStylePlain) ? ThemeService.shared.theme.backgroundColor : ThemeService.shared.theme.headerBackgroundColor);
|
|
|
|
self.view.backgroundColor = self.tableView.backgroundColor;
|
|
|
|
self.tableView.separatorColor = ThemeService.shared.theme.lineBreakColor;
|
|
|
|
|
|
|
|
if (self.tableView.dataSource)
|
|
|
|
{
|
|
|
|
[self refreshSettings];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIStatusBarStyle)preferredStatusBarStyle
|
|
|
|
{
|
|
|
|
return ThemeService.shared.theme.statusBarStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didReceiveMemoryWarning
|
|
|
|
{
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
// Dispose of any resources that can be recreated.
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)destroy
|
|
|
|
{
|
|
|
|
// Release the potential pushed view controller
|
|
|
|
[self releasePushedViewController];
|
|
|
|
|
|
|
|
if (documentInteractionController)
|
|
|
|
{
|
|
|
|
[documentInteractionController dismissPreviewAnimated:NO];
|
|
|
|
[documentInteractionController dismissMenuAnimated:NO];
|
|
|
|
documentInteractionController = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kThemeServiceDidChangeThemeNotificationObserver)
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:kThemeServiceDidChangeThemeNotificationObserver];
|
|
|
|
kThemeServiceDidChangeThemeNotificationObserver = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyBackupSetupCoordinatorBridgePresenter = nil;
|
|
|
|
keyBackupRecoverCoordinatorBridgePresenter = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)onMatrixSessionStateDidChange:(NSNotification *)notif
|
|
|
|
{
|
|
|
|
MXSession *mxSession = notif.object;
|
|
|
|
|
|
|
|
// Check whether the concerned session is a new one which is not already associated with this view controller.
|
|
|
|
if (mxSession.state == MXSessionStateInitialised && [self.mxSessions indexOfObject:mxSession] != NSNotFound)
|
|
|
|
{
|
|
|
|
// Store this new session
|
|
|
|
[self addMatrixSession:mxSession];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[super onMatrixSessionStateDidChange:notif];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
|
|
// Screen tracking
|
|
|
|
[[Analytics sharedInstance] trackScreen:@"Settings"];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// Release the potential pushed view controller
|
|
|
|
[self releasePushedViewController];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// Refresh display
|
|
|
|
[self refreshSettings];
|
|
|
|
|
|
|
|
// Refresh the current device information in parallel
|
|
|
|
[self loadCurrentDeviceInformation];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// Refresh devices in parallel
|
|
|
|
[self loadDevices];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// Observe kAppDelegateDidTapStatusBarNotificationObserver.
|
|
|
|
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
[self.tableView setContentOffset:CGPointMake(-self.tableView.mxk_adjustedContentInset.left, -self.tableView.mxk_adjustedContentInset.top) animated:YES];
|
|
|
|
|
2020-01-28 21:36:50 +00:00
|
|
|
}];
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
|
|
|
|
if (currentAlert)
|
|
|
|
{
|
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
currentAlert = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kAppDelegateDidTapStatusBarNotificationObserver)
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:kAppDelegateDidTapStatusBarNotificationObserver];
|
|
|
|
kAppDelegateDidTapStatusBarNotificationObserver = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Internal methods
|
|
|
|
|
|
|
|
- (void)pushViewController:(UIViewController*)viewController
|
|
|
|
{
|
|
|
|
// Keep ref on pushed view controller
|
|
|
|
pushedViewController = viewController;
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// Hide back button title
|
|
|
|
self.navigationItem.backBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
[self.navigationController pushViewController:viewController animated:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)releasePushedViewController
|
|
|
|
{
|
|
|
|
if (pushedViewController)
|
|
|
|
{
|
|
|
|
if ([pushedViewController isKindOfClass:[UINavigationController class]])
|
|
|
|
{
|
|
|
|
UINavigationController *navigationController = (UINavigationController*)pushedViewController;
|
|
|
|
for (id subViewController in navigationController.viewControllers)
|
|
|
|
{
|
|
|
|
if ([subViewController respondsToSelector:@selector(destroy)])
|
|
|
|
{
|
|
|
|
[subViewController destroy];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ([pushedViewController respondsToSelector:@selector(destroy)])
|
|
|
|
{
|
|
|
|
[(id)pushedViewController destroy];
|
|
|
|
}
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
pushedViewController = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)reset
|
|
|
|
{
|
|
|
|
// Remove observers
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
if (deviceView)
|
|
|
|
{
|
|
|
|
[deviceView removeFromSuperview];
|
|
|
|
deviceView = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadCurrentDeviceInformation
|
|
|
|
{
|
|
|
|
// Refresh the current device information
|
|
|
|
MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject;
|
|
|
|
[account loadDeviceInformation:^{
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// Refresh all the table (A slide down animation is observed when we limit the refresh to the concerned section).
|
|
|
|
// Note: The use of 'reloadData' handles the case where the account has been logged out.
|
|
|
|
[self refreshSettings];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
} failure:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSAttributedString*)cryptographyInformation
|
|
|
|
{
|
|
|
|
// TODO Handle multi accounts
|
|
|
|
MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject;
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// Crypto information
|
|
|
|
NSMutableAttributedString *cryptoInformationString = [[NSMutableAttributedString alloc]
|
|
|
|
initWithString:NSLocalizedStringFromTable(@"settings_crypto_device_name", @"Vector", nil)
|
|
|
|
attributes:@{NSForegroundColorAttributeName : ThemeService.shared.theme.textPrimaryColor,
|
|
|
|
NSFontAttributeName: [UIFont systemFontOfSize:17]}];
|
|
|
|
[cryptoInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
|
|
|
initWithString:account.device.displayName ? account.device.displayName : @""
|
|
|
|
attributes:@{NSForegroundColorAttributeName : ThemeService.shared.theme.textPrimaryColor,
|
|
|
|
NSFontAttributeName: [UIFont systemFontOfSize:17]}]];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
[cryptoInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
|
|
|
initWithString:NSLocalizedStringFromTable(@"settings_crypto_device_id", @"Vector", nil)
|
|
|
|
attributes:@{NSForegroundColorAttributeName : ThemeService.shared.theme.textPrimaryColor,
|
|
|
|
NSFontAttributeName: [UIFont systemFontOfSize:17]}]];
|
|
|
|
[cryptoInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
|
|
|
initWithString:account.device.deviceId ? account.device.deviceId : @""
|
|
|
|
attributes:@{NSForegroundColorAttributeName : ThemeService.shared.theme.textPrimaryColor,
|
|
|
|
NSFontAttributeName: [UIFont systemFontOfSize:17]}]];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
[cryptoInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
|
|
|
initWithString:NSLocalizedStringFromTable(@"settings_crypto_device_key", @"Vector", nil)
|
|
|
|
attributes:@{NSForegroundColorAttributeName : ThemeService.shared.theme.textPrimaryColor,
|
|
|
|
NSFontAttributeName: [UIFont systemFontOfSize:17]}]];
|
|
|
|
NSString *fingerprint = account.mxSession.crypto.deviceEd25519Key;
|
|
|
|
if (fingerprint)
|
|
|
|
{
|
|
|
|
fingerprint = [MXTools addWhiteSpacesToString:fingerprint every:4];
|
|
|
|
}
|
|
|
|
[cryptoInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
|
|
|
initWithString:fingerprint ? fingerprint : @""
|
|
|
|
attributes:@{NSForegroundColorAttributeName : ThemeService.shared.theme.textPrimaryColor,
|
|
|
|
NSFontAttributeName: [UIFont boldSystemFontOfSize:17]}]];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
return cryptoInformationString;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadDevices
|
|
|
|
{
|
|
|
|
// Refresh the account devices list
|
|
|
|
MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject;
|
2020-01-28 21:36:50 +00:00
|
|
|
|
|
|
|
MXWeakify(self);
|
2020-01-28 20:09:51 +00:00
|
|
|
[account.mxRestClient devices:^(NSArray<MXDevice *> *devices) {
|
2020-01-28 21:36:50 +00:00
|
|
|
MXStrongifyAndReturnIfNil(self);
|
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
if (devices)
|
|
|
|
{
|
2020-01-28 21:36:50 +00:00
|
|
|
self->devicesArray = [NSMutableArray arrayWithArray:devices];
|
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// Sort devices according to the last seen date.
|
|
|
|
NSComparator comparator = ^NSComparisonResult(MXDevice *deviceA, MXDevice *deviceB) {
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
if (deviceA.lastSeenTs > deviceB.lastSeenTs)
|
|
|
|
{
|
|
|
|
return NSOrderedAscending;
|
|
|
|
}
|
|
|
|
if (deviceA.lastSeenTs < deviceB.lastSeenTs)
|
|
|
|
{
|
|
|
|
return NSOrderedDescending;
|
|
|
|
}
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
return NSOrderedSame;
|
|
|
|
};
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// Sort devices list
|
2020-01-28 21:36:50 +00:00
|
|
|
[self->devicesArray sortUsingComparator:comparator];
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-28 21:36:50 +00:00
|
|
|
self->devicesArray = nil;
|
2020-01-28 20:09:51 +00:00
|
|
|
|
|
|
|
}
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// Refresh all the table (A slide down animation is observed when we limit the refresh to the concerned section).
|
|
|
|
// Note: The use of 'reloadData' handles the case where the account has been logged out.
|
|
|
|
[self refreshSettings];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
} failure:^(NSError *error) {
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// Display the data that has been loaded last time
|
|
|
|
// Note: The use of 'reloadData' handles the case where the account has been logged out.
|
|
|
|
[self refreshSettings];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showDeviceDetails:(MXDevice *)device
|
|
|
|
{
|
|
|
|
deviceView = [[DeviceView alloc] initWithDevice:device andMatrixSession:self.mainSession];
|
|
|
|
deviceView.delegate = self;
|
|
|
|
|
|
|
|
// Add the view and define edge constraints
|
|
|
|
[self.tableView.superview addSubview:deviceView];
|
|
|
|
[self.tableView.superview bringSubviewToFront:deviceView];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:deviceView
|
|
|
|
attribute:NSLayoutAttributeTop
|
|
|
|
relatedBy:NSLayoutRelationEqual
|
|
|
|
toItem:self.tableView
|
|
|
|
attribute:NSLayoutAttributeTop
|
|
|
|
multiplier:1.0f
|
|
|
|
constant:0.0f];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:deviceView
|
|
|
|
attribute:NSLayoutAttributeLeft
|
|
|
|
relatedBy:NSLayoutRelationEqual
|
|
|
|
toItem:self.tableView
|
|
|
|
attribute:NSLayoutAttributeLeft
|
|
|
|
multiplier:1.0f
|
|
|
|
constant:0.0f];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:deviceView
|
|
|
|
attribute:NSLayoutAttributeWidth
|
|
|
|
relatedBy:NSLayoutRelationEqual
|
|
|
|
toItem:self.tableView
|
|
|
|
attribute:NSLayoutAttributeWidth
|
|
|
|
multiplier:1.0f
|
|
|
|
constant:0.0f];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:deviceView
|
|
|
|
attribute:NSLayoutAttributeHeight
|
|
|
|
relatedBy:NSLayoutRelationEqual
|
|
|
|
toItem:self.tableView
|
|
|
|
attribute:NSLayoutAttributeHeight
|
|
|
|
multiplier:1.0f
|
|
|
|
constant:0.0f];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
[NSLayoutConstraint activateConstraints:@[topConstraint, leftConstraint, widthConstraint, heightConstraint]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)deviceView:(DeviceView*)theDeviceView presentAlertController:(UIAlertController *)alert
|
|
|
|
{
|
|
|
|
[self presentViewController:alert animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dismissDeviceView:(MXKDeviceView *)theDeviceView didUpdate:(BOOL)isUpdated
|
|
|
|
{
|
|
|
|
[deviceView removeFromSuperview];
|
|
|
|
deviceView = nil;
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
if (isUpdated)
|
|
|
|
{
|
|
|
|
[self loadDevices];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)refreshSettings
|
|
|
|
{
|
|
|
|
// Trigger a full table reloadData
|
|
|
|
[self.tableView reloadData];
|
|
|
|
}
|
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
- (void)requestAccountPasswordWithTitle:(NSString*)title message:(NSString*)message onComplete:(void (^)(NSString *password))onComplete
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
2020-01-28 20:09:51 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
// Prompt the user before deleting the device.
|
|
|
|
currentAlert = [UIAlertController alertControllerWithTitle:title
|
|
|
|
message:message
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
2020-01-28 20:09:51 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
[currentAlert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
|
|
|
|
textField.secureTextEntry = YES;
|
|
|
|
textField.placeholder = nil;
|
|
|
|
textField.keyboardType = UIKeyboardTypeDefault;
|
|
|
|
}];
|
2020-01-28 20:09:51 +00:00
|
|
|
|
|
|
|
MXWeakify(self);
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action)
|
|
|
|
{
|
|
|
|
MXStrongifyAndReturnIfNil(self);
|
|
|
|
self->currentAlert = nil;
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"continue"]
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
MXStrongifyAndReturnIfNil(self);
|
|
|
|
|
|
|
|
UITextField *textField = [self->currentAlert textFields].firstObject;
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
onComplete(textField.text);
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[self presentViewController:currentAlert animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Segues
|
|
|
|
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
|
|
|
|
{
|
|
|
|
// Keep ref on destinationViewController
|
|
|
|
[super prepareForSegue:segue sender:sender];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// FIXME add night mode
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - UITableView data source
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
|
|
{
|
|
|
|
return SETTINGS_SECTION_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
|
{
|
|
|
|
NSInteger count = 0;
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
if (section == SETTINGS_SECTION_DEVICES_INDEX)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
|
|
|
count = devicesArray.count;
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
// For some description (DEVICES_DESCRIPTION_INDEX)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (section == SETTINGS_SECTION_CRYPTOGRAPHY_INDEX)
|
|
|
|
{
|
|
|
|
// Check whether this section is visible.
|
|
|
|
if (self.mainSession.crypto)
|
|
|
|
{
|
|
|
|
count = CRYPTOGRAPHY_COUNT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (section == SETTINGS_SECTION_KEYBACKUP_INDEX)
|
|
|
|
{
|
|
|
|
// Check whether this section is visible.
|
|
|
|
if (self.mainSession.crypto)
|
|
|
|
{
|
|
|
|
count = keyBackupSection.numberOfRows;
|
|
|
|
}
|
|
|
|
}
|
2020-01-28 21:05:11 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (MXKTableViewCellWithLabelAndSwitch*)getLabelAndSwitchCell:(UITableView*)tableview forIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
MXKTableViewCellWithLabelAndSwitch *cell = [tableview dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier] forIndexPath:indexPath];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
cell.mxkLabelLeadingConstraint.constant = cell.separatorInset.left;
|
|
|
|
cell.mxkSwitchTrailingConstraint.constant = 15;
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
cell.mxkLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
[cell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// Force layout before reusing a cell (fix switch displayed outside the screen)
|
|
|
|
[cell layoutIfNeeded];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (MXKTableViewCell*)getDefaultTableViewCell:(UITableView*)tableView
|
|
|
|
{
|
|
|
|
MXKTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCell defaultReuseIdentifier]];
|
|
|
|
if (!cell)
|
|
|
|
{
|
|
|
|
cell = [[MXKTableViewCell alloc] init];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleDefault;
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
cell.accessoryType = UITableViewCellAccessoryNone;
|
|
|
|
cell.accessoryView = nil;
|
|
|
|
}
|
|
|
|
cell.textLabel.accessibilityIdentifier = nil;
|
|
|
|
cell.textLabel.font = [UIFont systemFontOfSize:17];
|
|
|
|
cell.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
|
|
|
cell.contentView.backgroundColor = UIColor.clearColor;
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (MXKTableViewCellWithTextView*)textViewCellForTableView:(UITableView*)tableView atIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
MXKTableViewCellWithTextView *textViewCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithTextView defaultReuseIdentifier] forIndexPath:indexPath];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
textViewCell.mxkTextView.textColor = ThemeService.shared.theme.textPrimaryColor;
|
|
|
|
textViewCell.mxkTextView.font = [UIFont systemFontOfSize:17];
|
|
|
|
textViewCell.mxkTextView.backgroundColor = [UIColor clearColor];
|
|
|
|
textViewCell.mxkTextViewLeadingConstraint.constant = tableView.separatorInset.left;
|
|
|
|
textViewCell.mxkTextViewTrailingConstraint.constant = tableView.separatorInset.right;
|
|
|
|
textViewCell.mxkTextView.accessibilityIdentifier = nil;
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
return textViewCell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
NSInteger section = indexPath.section;
|
|
|
|
NSInteger row = indexPath.row;
|
|
|
|
|
|
|
|
// set the cell to a default value to avoid application crashes
|
|
|
|
UITableViewCell *cell = [[UITableViewCell alloc] init];
|
|
|
|
cell.backgroundColor = [UIColor redColor];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
// check if there is a valid session
|
|
|
|
if (([AppDelegate theDelegate].mxSessions.count == 0) || ([MXKAccountManager sharedManager].activeAccounts.count == 0))
|
|
|
|
{
|
|
|
|
// else use a default cell
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-01-28 21:36:50 +00:00
|
|
|
MXSession* session = self.mainSession;
|
2020-01-28 21:05:11 +00:00
|
|
|
if (section == SETTINGS_SECTION_DEVICES_INDEX)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
if (row == DEVICES_DESCRIPTION_INDEX)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
MXKTableViewCell *descriptionCell = [self getDefaultTableViewCell:tableView];
|
|
|
|
descriptionCell.textLabel.text = NSLocalizedStringFromTable(@"settings_devices_description", @"Vector", nil);
|
|
|
|
descriptionCell.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
|
|
|
descriptionCell.textLabel.font = [UIFont systemFontOfSize:15];
|
|
|
|
descriptionCell.textLabel.numberOfLines = 0;
|
|
|
|
descriptionCell.contentView.backgroundColor = ThemeService.shared.theme.headerBackgroundColor;
|
|
|
|
descriptionCell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
|
|
|
|
cell = descriptionCell;
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
NSUInteger deviceIndex = row - 1;
|
|
|
|
|
|
|
|
MXKTableViewCell *deviceCell = [self getDefaultTableViewCell:tableView];
|
|
|
|
if (deviceIndex < devicesArray.count)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
NSString *name = devicesArray[deviceIndex].displayName;
|
|
|
|
NSString *deviceId = devicesArray[deviceIndex].deviceId;
|
|
|
|
deviceCell.textLabel.text = (name.length ? [NSString stringWithFormat:@"%@ (%@)", name, deviceId] : [NSString stringWithFormat:@"(%@)", deviceId]);
|
|
|
|
deviceCell.textLabel.numberOfLines = 0;
|
|
|
|
|
|
|
|
if ([deviceId isEqualToString:self.mainSession.matrixRestClient.credentials.deviceId])
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
deviceCell.textLabel.font = [UIFont boldSystemFontOfSize:17];
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-28 21:05:11 +00:00
|
|
|
|
|
|
|
cell = deviceCell;
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
2020-01-28 21:05:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else if (section == SETTINGS_SECTION_CRYPTOGRAPHY_INDEX)
|
|
|
|
{
|
|
|
|
if (row == CRYPTOGRAPHY_INFO_INDEX)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
MXKTableViewCellWithTextView *cryptoCell = [self textViewCellForTableView:tableView atIndexPath:indexPath];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
cryptoCell.mxkTextView.attributedText = [self cryptographyInformation];
|
|
|
|
|
|
|
|
cell = cryptoCell;
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
2020-01-28 21:05:11 +00:00
|
|
|
else if (row == CRYPTOGRAPHY_BLACKLIST_UNVERIFIED_DEVICES_INDEX)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
2020-01-28 20:09:51 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_crypto_blacklist_unverified_devices", @"Vector", nil);
|
2020-01-28 21:36:50 +00:00
|
|
|
labelAndSwitchCell.mxkSwitch.on = session.crypto.globalBlacklistUnverifiedDevices;
|
2020-01-28 21:05:11 +00:00
|
|
|
labelAndSwitchCell.mxkSwitch.onTintColor = ThemeService.shared.theme.tintColor;
|
|
|
|
labelAndSwitchCell.mxkSwitch.enabled = YES;
|
|
|
|
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleBlacklistUnverifiedDevices:) forControlEvents:UIControlEventTouchUpInside];
|
2020-01-28 20:09:51 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
cell = labelAndSwitchCell;
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
2020-01-28 21:05:11 +00:00
|
|
|
else if (row == CRYPTOGRAPHY_EXPORT_INDEX)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
MXKTableViewCellWithButton *exportKeysBtnCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithButton defaultReuseIdentifier]];
|
|
|
|
if (!exportKeysBtnCell)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
exportKeysBtnCell = [[MXKTableViewCellWithButton alloc] init];
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
// Fix https://github.com/vector-im/riot-ios/issues/1354
|
|
|
|
exportKeysBtnCell.mxkButton.titleLabel.text = nil;
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
2020-01-28 21:05:11 +00:00
|
|
|
|
|
|
|
NSString *btnTitle = NSLocalizedStringFromTable(@"settings_crypto_export", @"Vector", nil);
|
|
|
|
[exportKeysBtnCell.mxkButton setTitle:btnTitle forState:UIControlStateNormal];
|
|
|
|
[exportKeysBtnCell.mxkButton setTitle:btnTitle forState:UIControlStateHighlighted];
|
|
|
|
[exportKeysBtnCell.mxkButton setTintColor:ThemeService.shared.theme.tintColor];
|
|
|
|
exportKeysBtnCell.mxkButton.titleLabel.font = [UIFont systemFontOfSize:17];
|
|
|
|
|
|
|
|
[exportKeysBtnCell.mxkButton removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
[exportKeysBtnCell.mxkButton addTarget:self action:@selector(exportEncryptionKeys:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
exportKeysBtnCell.mxkButton.accessibilityIdentifier = nil;
|
|
|
|
|
|
|
|
cell = exportKeysBtnCell;
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
2020-01-28 21:05:11 +00:00
|
|
|
}
|
|
|
|
else if (section == SETTINGS_SECTION_KEYBACKUP_INDEX)
|
|
|
|
{
|
|
|
|
cell = [keyBackupSection cellForRowAtRow:row];
|
|
|
|
}
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
|
|
|
{
|
|
|
|
if (section == SETTINGS_SECTION_DEVICES_INDEX)
|
|
|
|
{
|
|
|
|
// Check whether this section is visible
|
|
|
|
if (devicesArray.count > 0)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
return NSLocalizedStringFromTable(@"settings_devices", @"Vector", nil);
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
2020-01-28 21:05:11 +00:00
|
|
|
}
|
|
|
|
else if (section == SETTINGS_SECTION_CRYPTOGRAPHY_INDEX)
|
|
|
|
{
|
|
|
|
// Check whether this section is visible
|
|
|
|
if (self.mainSession.crypto)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
return NSLocalizedStringFromTable(@"settings_cryptography", @"Vector", nil);
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-28 21:05:11 +00:00
|
|
|
else if (section == SETTINGS_SECTION_KEYBACKUP_INDEX)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
// Check whether this section is visible
|
|
|
|
if (self.mainSession.crypto)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
return NSLocalizedStringFromTable(@"settings_key_backup", @"Vector", nil);
|
|
|
|
}
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
return nil;
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
if ([view isKindOfClass:UITableViewHeaderFooterView.class])
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
// Customize label style
|
|
|
|
UITableViewHeaderFooterView *tableViewHeaderFooterView = (UITableViewHeaderFooterView*)view;
|
|
|
|
tableViewHeaderFooterView.textLabel.textColor = ThemeService.shared.theme.textPrimaryColor;
|
|
|
|
tableViewHeaderFooterView.textLabel.font = [UIFont systemFontOfSize:15];
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
#pragma mark - UITableView delegate
|
2020-01-28 20:09:51 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
cell.backgroundColor = ThemeService.shared.theme.backgroundColor;
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
if (cell.selectionStyle != UITableViewCellSelectionStyleNone)
|
2020-01-28 21:36:50 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
// Update the selected background view
|
|
|
|
if (ThemeService.shared.theme.selectedBackgroundColor)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
cell.selectedBackgroundView = [[UIView alloc] init];
|
|
|
|
cell.selectedBackgroundView.backgroundColor = ThemeService.shared.theme.selectedBackgroundColor;
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
2020-01-28 21:05:11 +00:00
|
|
|
else
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
if (tableView.style == UITableViewStylePlain)
|
|
|
|
{
|
|
|
|
cell.selectedBackgroundView = nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cell.selectedBackgroundView.backgroundColor = nil;
|
|
|
|
}
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
2020-01-28 21:05:11 +00:00
|
|
|
}
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
return 24;
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
return 24;
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
if (self.tableView == tableView)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
NSInteger section = indexPath.section;
|
|
|
|
NSInteger row = indexPath.row;
|
|
|
|
|
|
|
|
if (section == SETTINGS_SECTION_DEVICES_INDEX)
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
if (row > DEVICES_DESCRIPTION_INDEX)
|
|
|
|
{
|
|
|
|
NSUInteger deviceIndex = row - 1;
|
|
|
|
if (deviceIndex < devicesArray.count)
|
|
|
|
{
|
|
|
|
[self showDeviceDetails:devicesArray[deviceIndex]];
|
|
|
|
}
|
|
|
|
}
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 21:36:50 +00:00
|
|
|
#pragma mark - UIDocumentInteractionControllerDelegate
|
|
|
|
|
|
|
|
- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application
|
|
|
|
{
|
|
|
|
// If iOS wants to call this method, this is the right time to remove the file
|
|
|
|
[self deleteKeyExportFile];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
|
|
|
|
{
|
|
|
|
documentInteractionController = nil;
|
|
|
|
}
|
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
#pragma mark - actions
|
2020-01-28 20:09:51 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
- (void)exportEncryptionKeys:(UITapGestureRecognizer *)recognizer
|
2020-01-28 20:09:51 +00:00
|
|
|
{
|
2020-01-28 21:05:11 +00:00
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
2020-01-28 20:09:51 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
exportView = [[MXKEncryptionKeysExportView alloc] initWithMatrixSession:self.mainSession];
|
|
|
|
currentAlert = exportView.alertController;
|
2020-01-28 20:09:51 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
// Use a temporary file for the export
|
|
|
|
keyExportsFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"riot-keys.txt"]];
|
2020-01-28 20:09:51 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
// Make sure the file is empty
|
|
|
|
[self deleteKeyExportFile];
|
2020-01-28 20:09:51 +00:00
|
|
|
|
2020-01-28 21:05:11 +00:00
|
|
|
// Show the export dialog
|
2020-01-28 21:36:50 +00:00
|
|
|
MXWeakify(self);
|
2020-01-28 21:05:11 +00:00
|
|
|
[exportView showInViewController:self toExportKeysToFile:keyExportsFile onComplete:^(BOOL success) {
|
2020-01-28 21:36:50 +00:00
|
|
|
MXStrongifyAndReturnIfNil(self);
|
|
|
|
|
|
|
|
self->currentAlert = nil;
|
|
|
|
self->exportView = nil;
|
2020-01-28 21:05:11 +00:00
|
|
|
|
2020-01-28 21:36:50 +00:00
|
|
|
if (success)
|
2020-01-28 21:05:11 +00:00
|
|
|
{
|
2020-01-28 21:36:50 +00:00
|
|
|
// Let another app handling this file
|
|
|
|
self->documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:self->keyExportsFile];
|
|
|
|
[self->documentInteractionController setDelegate:self];
|
2020-01-28 21:05:11 +00:00
|
|
|
|
2020-01-28 21:36:50 +00:00
|
|
|
if ([self->documentInteractionController presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES])
|
2020-01-28 21:05:11 +00:00
|
|
|
{
|
2020-01-28 21:36:50 +00:00
|
|
|
// We want to delete the temp keys file after it has been processed by the other app.
|
|
|
|
// We use [UIDocumentInteractionControllerDelegate didEndSendingToApplication] for that
|
|
|
|
// but it is not reliable for all cases (see http://stackoverflow.com/a/21867096).
|
|
|
|
// So, arm a timer to auto delete the file after 10mins.
|
|
|
|
self->keyExportsFileDeletionTimer = [NSTimer scheduledTimerWithTimeInterval:600 target:self selector:@selector(deleteKeyExportFile) userInfo:self repeats:NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self->documentInteractionController = nil;
|
|
|
|
[self deleteKeyExportFile];
|
2020-01-28 21:05:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)deleteKeyExportFile
|
|
|
|
{
|
|
|
|
// Cancel the deletion timer if it is still here
|
|
|
|
if (keyExportsFileDeletionTimer)
|
|
|
|
{
|
|
|
|
[keyExportsFileDeletionTimer invalidate];
|
|
|
|
keyExportsFileDeletionTimer = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
// And delete the file
|
|
|
|
if (keyExportsFile && [[NSFileManager defaultManager] fileExistsAtPath:keyExportsFile.path])
|
|
|
|
{
|
|
|
|
[[NSFileManager defaultManager] removeItemAtPath:keyExportsFile.path error:nil];
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 21:36:50 +00:00
|
|
|
- (void)toggleBlacklistUnverifiedDevices:(id)sender
|
|
|
|
{
|
|
|
|
UISwitch *switchButton = (UISwitch*)sender;
|
2020-01-28 21:05:11 +00:00
|
|
|
|
2020-01-28 21:36:50 +00:00
|
|
|
self.mainSession.crypto.globalBlacklistUnverifiedDevices = switchButton.on;
|
2020-01-28 21:05:11 +00:00
|
|
|
|
2020-01-28 21:36:50 +00:00
|
|
|
[self.tableView reloadData];
|
2020-01-28 20:09:51 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 21:36:50 +00:00
|
|
|
|
|
|
|
#pragma mark - MXKDataSourceDelegate
|
2020-01-28 20:09:51 +00:00
|
|
|
|
|
|
|
- (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes
|
|
|
|
{
|
|
|
|
// Group data has been updated. Do a simple full reload
|
|
|
|
[self refreshSettings];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - SettingsKeyBackupTableViewSectionDelegate
|
|
|
|
|
|
|
|
- (void)settingsKeyBackupTableViewSectionDidUpdate:(SettingsKeyBackupTableViewSection *)settingsKeyBackupTableViewSection
|
|
|
|
{
|
|
|
|
[self.tableView reloadData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (MXKTableViewCellWithTextView *)settingsKeyBackupTableViewSection:(SettingsKeyBackupTableViewSection *)settingsKeyBackupTableViewSection textCellForRow:(NSInteger)textCellForRow
|
|
|
|
{
|
|
|
|
return [self textViewCellForTableView:self.tableView atIndexPath:[NSIndexPath indexPathForRow:textCellForRow inSection:SETTINGS_SECTION_KEYBACKUP_INDEX]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (MXKTableViewCellWithButton *)settingsKeyBackupTableViewSection:(SettingsKeyBackupTableViewSection *)settingsKeyBackupTableViewSection buttonCellForRow:(NSInteger)buttonCellForRow
|
|
|
|
{
|
|
|
|
MXKTableViewCellWithButton *cell = [self.tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithButton defaultReuseIdentifier]];
|
|
|
|
|
|
|
|
if (!cell)
|
|
|
|
{
|
|
|
|
cell = [[MXKTableViewCellWithButton alloc] init];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Fix https://github.com/vector-im/riot-ios/issues/1354
|
|
|
|
cell.mxkButton.titleLabel.text = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell.mxkButton.titleLabel.font = [UIFont systemFontOfSize:17];
|
|
|
|
[cell.mxkButton setTintColor:ThemeService.shared.theme.tintColor];
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)settingsKeyBackupTableViewSectionShowKeyBackupSetup:(SettingsKeyBackupTableViewSection *)settingsKeyBackupTableViewSection
|
|
|
|
{
|
|
|
|
[self showKeyBackupSetupFromSignOutFlow:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)settingsKeyBackup:(SettingsKeyBackupTableViewSection *)settingsKeyBackupTableViewSection showKeyBackupRecover:(MXKeyBackupVersion *)keyBackupVersion
|
|
|
|
{
|
|
|
|
[self showKeyBackupRecover:keyBackupVersion];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)settingsKeyBackup:(SettingsKeyBackupTableViewSection *)settingsKeyBackupTableViewSection showKeyBackupDeleteConfirm:(MXKeyBackupVersion *)keyBackupVersion
|
|
|
|
{
|
|
|
|
MXWeakify(self);
|
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
|
|
|
|
currentAlert =
|
|
|
|
[UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"settings_key_backup_delete_confirmation_prompt_title", @"Vector", nil)
|
|
|
|
message:NSLocalizedStringFromTable(@"settings_key_backup_delete_confirmation_prompt_msg", @"Vector", nil)
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"]
|
|
|
|
style:UIAlertActionStyleCancel
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
MXStrongifyAndReturnIfNil(self);
|
|
|
|
self->currentAlert = nil;
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"settings_key_backup_button_delete", @"Vector", nil)
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
MXStrongifyAndReturnIfNil(self);
|
|
|
|
self->currentAlert = nil;
|
|
|
|
|
|
|
|
[self->keyBackupSection deleteWithKeyBackupVersion:keyBackupVersion];
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[currentAlert mxk_setAccessibilityIdentifier: @"SettingsVCDeleteKeyBackup"];
|
|
|
|
[self presentViewController:currentAlert animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)settingsKeyBackup:(SettingsKeyBackupTableViewSection *)settingsKeyBackupTableViewSection showActivityIndicator:(BOOL)show
|
|
|
|
{
|
|
|
|
if (show)
|
|
|
|
{
|
|
|
|
[self startActivityIndicator];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self stopActivityIndicator];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)settingsKeyBackup:(SettingsKeyBackupTableViewSection *)settingsKeyBackupTableViewSection showError:(NSError *)error
|
|
|
|
{
|
|
|
|
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - KeyBackupRecoverCoordinatorBridgePresenter
|
|
|
|
|
|
|
|
- (void)showKeyBackupSetupFromSignOutFlow:(BOOL)showFromSignOutFlow
|
|
|
|
{
|
|
|
|
keyBackupSetupCoordinatorBridgePresenter = [[KeyBackupSetupCoordinatorBridgePresenter alloc] initWithSession:self.mainSession];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
[keyBackupSetupCoordinatorBridgePresenter presentFrom:self
|
|
|
|
isStartedFromSignOut:showFromSignOutFlow
|
|
|
|
animated:true];
|
2020-01-28 21:36:50 +00:00
|
|
|
|
2020-01-28 20:09:51 +00:00
|
|
|
keyBackupSetupCoordinatorBridgePresenter.delegate = self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyBackupSetupCoordinatorBridgePresenterDelegateDidCancel:(KeyBackupSetupCoordinatorBridgePresenter *)bridgePresenter {
|
|
|
|
[keyBackupSetupCoordinatorBridgePresenter dismissWithAnimated:true];
|
|
|
|
keyBackupSetupCoordinatorBridgePresenter = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyBackupSetupCoordinatorBridgePresenterDelegateDidSetupRecoveryKey:(KeyBackupSetupCoordinatorBridgePresenter *)bridgePresenter {
|
|
|
|
[keyBackupSetupCoordinatorBridgePresenter dismissWithAnimated:true];
|
|
|
|
keyBackupSetupCoordinatorBridgePresenter = nil;
|
|
|
|
|
|
|
|
[keyBackupSection reload];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - KeyBackupRecoverCoordinatorBridgePresenter
|
|
|
|
|
|
|
|
- (void)showKeyBackupRecover:(MXKeyBackupVersion*)keyBackupVersion
|
|
|
|
{
|
|
|
|
keyBackupRecoverCoordinatorBridgePresenter = [[KeyBackupRecoverCoordinatorBridgePresenter alloc] initWithSession:self.mainSession keyBackupVersion:keyBackupVersion];
|
|
|
|
|
|
|
|
[keyBackupRecoverCoordinatorBridgePresenter presentFrom:self animated:true];
|
|
|
|
keyBackupRecoverCoordinatorBridgePresenter.delegate = self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyBackupRecoverCoordinatorBridgePresenterDidCancel:(KeyBackupRecoverCoordinatorBridgePresenter *)bridgePresenter {
|
|
|
|
[keyBackupRecoverCoordinatorBridgePresenter dismissWithAnimated:true];
|
|
|
|
keyBackupRecoverCoordinatorBridgePresenter = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyBackupRecoverCoordinatorBridgePresenterDidRecover:(KeyBackupRecoverCoordinatorBridgePresenter *)bridgePresenter {
|
|
|
|
[keyBackupRecoverCoordinatorBridgePresenter dismissWithAnimated:true];
|
|
|
|
keyBackupRecoverCoordinatorBridgePresenter = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|