SecurityViewController: Makes table content easier to customize.

This commit is contained in:
SBiOSoftWhare
2020-09-28 14:25:21 +02:00
parent 3338284e94
commit 3f978af1ea

View File

@@ -97,7 +97,8 @@ KeyBackupRecoverCoordinatorBridgePresenterDelegate,
UIDocumentInteractionControllerDelegate,
SecretsRecoveryCoordinatorBridgePresenterDelegate,
SecureBackupSetupCoordinatorBridgePresenterDelegate,
SetPinCoordinatorBridgePresenterDelegate>
SetPinCoordinatorBridgePresenterDelegate,
TableViewSectionsDelegate>
{
// Current alert (if any).
UIAlertController *currentAlert;
@@ -131,6 +132,7 @@ SetPinCoordinatorBridgePresenterDelegate>
SecretsRecoveryCoordinatorBridgePresenter *secretsRecoveryCoordinatorBridgePresenter;
}
@property (nonatomic, strong) TableViewSections *tableViewSections;
@property (nonatomic) BOOL isLoadingDevices;
@property (nonatomic, strong) MXKeyBackupVersion *currentkeyBackupVersion;
@property (nonatomic, strong) SecureBackupSetupCoordinatorBridgePresenter *secureBackupSetupCoordinatorBridgePresenter;
@@ -201,6 +203,11 @@ SetPinCoordinatorBridgePresenterDelegate>
}];
[self userInterfaceThemeDidChange];
self.tableViewSections = [TableViewSections new];
self.tableViewSections.delegate = self;
[self updateSections];
}
- (void)userInterfaceThemeDidChange
@@ -290,6 +297,105 @@ SetPinCoordinatorBridgePresenterDelegate>
#pragma mark - Internal methods
- (void)updateSections
{
NSMutableArray<Section*> *sections = [NSMutableArray array];
// Pin code section
Section *pinCodeSection = [Section sectionWithTag:SECTION_PIN_CODE];
// Header title
NSString *pinCodeSectionHeaderTitleFormat = NSLocalizedStringFromTable(@"pin_protection_settings_section_header_x", @"Vector", nil);
NSString *pinCodeSectionHeaderTitle = [NSString stringWithFormat:pinCodeSectionHeaderTitleFormat, [PinCodePreferences shared].localizedBiometricsName];
pinCodeSection.headerTitle = pinCodeSectionHeaderTitle;
// Rows
[pinCodeSection addRowWithTag:PIN_CODE_SETTING];
[pinCodeSection addRowWithTag:PIN_CODE_DESCRIPTION];
if (![PinCodePreferences shared].isBiometricsAvailable)
{
[pinCodeSection addRowWithTag:PIN_CODE_BIOMETRICS];
}
[sections addObject:pinCodeSection];
// Crypto sessions section
Section *sessionsSection = [Section sectionWithTag:SECTION_CRYPTO_SESSIONS];
sessionsSection.headerTitle = NSLocalizedStringFromTable(@"security_settings_crypto_sessions", @"Vector", nil);
NSUInteger sessionsSectionRowsCount;
if (self.showLoadingDevicesInformation)
{
sessionsSectionRowsCount = 2;
} else {
sessionsSectionRowsCount = devicesArray.count + 1;
}
[sessionsSection addRowsWithCount:sessionsSectionRowsCount];
[sections addObject:sessionsSection];
// Secure backup
Section *secureBackupSection = [Section sectionWithTag:SECTION_SECURE_BACKUP];
secureBackupSection.headerTitle = NSLocalizedStringFromTable(@"security_settings_secure_backup", @"Vector", nil);
[secureBackupSection addRowsWithCount:[self numberOfRowsInSecureBackupSection]];
[sections addObject:secureBackupSection];
// Cryptograhpy
Section *cryptograhpySection = [Section sectionWithTag:SECTION_CRYPTOGRAPHY];
cryptograhpySection.headerTitle = NSLocalizedStringFromTable(@"security_settings_cryptography", @"Vector", nil);
[cryptograhpySection addRowsWithCount:CRYPTOGRAPHY_COUNT];
[sections addObject:cryptograhpySection];
#ifdef CROSS_SIGNING_AND_BACKUP_DEV
// Cross-Signing
Section *crossSigningSection = [Section sectionWithTag:SECTION_CROSSSIGNING];
crossSigningSection.headerTitle = NSLocalizedStringFromTable(@"security_settings_crosssigning", @"Vector", nil);
[crossSigningSection addRowsWithCount:[self numberOfRowsInCrossSigningSection]];
[sections addObject:crossSigningSection];
// Keybackup
Section *keybackupSection = [Section sectionWithTag:SECTION_KEYBACKUP];
keybackupSection.headerTitle = NSLocalizedStringFromTable(@"security_settings_backup", @"Vector", nil);
[keybackupSection addRowsWithCount:[self keyBackupSection.numberOfRows]];
[sections addObject:keybackupSection];
#endif
// Advanced
Section *advancedSection = [Section sectionWithTag:SECTION_ADVANCED];
advancedSection.headerTitle = NSLocalizedStringFromTable(@"security_settings_advanced", @"Vector", nil);
[advancedSection addRowWithTag:ADVANCED_BLACKLIST_UNVERIFIED_DEVICES];
[advancedSection addRowWithTag:ADVANCED_BLACKLIST_UNVERIFIED_DEVICES_DESCRIPTION];
[sections addObject:advancedSection];
// Update sections
self.tableViewSections.sections = sections;
}
- (BOOL)showLoadingDevicesInformation
{
return self.isLoadingDevices && devicesArray.count == 0;
@@ -448,8 +554,8 @@ SetPinCoordinatorBridgePresenterDelegate>
{
[self refreshSecureBackupSectionData];
// Trigger a full table reloadData
[self.tableView reloadData];
// Update table view sections and trigger a tableView reloadData
[self updateSections];
}
@@ -931,53 +1037,13 @@ SetPinCoordinatorBridgePresenterDelegate>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return SECTION_COUNT;
return self.tableViewSections.sections.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger count = 0;
switch (section)
{
case SECTION_PIN_CODE:
count = PIN_CODE_COUNT;
if (![PinCodePreferences shared].isBiometricsAvailable)
{
count -= 1;
}
break;
case SECTION_CRYPTO_SESSIONS:
if (self.showLoadingDevicesInformation)
{
count = 2;
}
else
{
count = devicesArray.count + 1;
}
break;
case SECTION_SECURE_BACKUP:
count = [self numberOfRowsInSecureBackupSection];
break;
#ifdef CROSS_SIGNING_AND_BACKUP_DEV
case SECTION_KEYBACKUP:
count = keyBackupSection.numberOfRows;
break;
case SECTION_CROSSSIGNING:
count = [self numberOfRowsInCrossSigningSection];
break;
#endif
case SECTION_CRYPTOGRAPHY:
count = CRYPTOGRAPHY_COUNT;
break;
case SECTION_ADVANCED:
count = ADVANCED_COUNT;
break;
}
return count;
Section *tableSection = [self.tableViewSections sectionAtIndex:section];
return tableSection.rows.count;
}
- (MXKTableViewCellWithLabelAndSwitch*)getLabelAndSwitchCell:(UITableView*)tableview forIndexPath:(NSIndexPath *)indexPath
@@ -1131,8 +1197,9 @@ SetPinCoordinatorBridgePresenterDelegate>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger section = indexPath.section;
NSInteger row = indexPath.row;
NSIndexPath *tagsIndexPath = [self.tableViewSections tagsIndexPathFromTableViewIndexPath:indexPath];
NSInteger section = tagsIndexPath.section;
NSInteger row = tagsIndexPath.row;
// set the cell to a default value to avoid application crashes
UITableViewCell *cell = [[UITableViewCell alloc] init];
@@ -1356,30 +1423,8 @@ SetPinCoordinatorBridgePresenterDelegate>
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
switch (section)
{
case SECTION_PIN_CODE:
{
NSString *format = NSLocalizedStringFromTable(@"pin_protection_settings_section_header_x", @"Vector", nil);
return [NSString stringWithFormat:format, [PinCodePreferences shared].localizedBiometricsName];
}
case SECTION_CRYPTO_SESSIONS:
return NSLocalizedStringFromTable(@"security_settings_crypto_sessions", @"Vector", nil);
case SECTION_SECURE_BACKUP:
return NSLocalizedStringFromTable(@"security_settings_secure_backup", @"Vector", nil);
#ifdef CROSS_SIGNING_AND_BACKUP_DEV
case SECTION_KEYBACKUP:
return NSLocalizedStringFromTable(@"security_settings_backup", @"Vector", nil);
case SECTION_CROSSSIGNING:
return NSLocalizedStringFromTable(@"security_settings_crosssigning", @"Vector", nil);
#endif
case SECTION_CRYPTOGRAPHY:
return NSLocalizedStringFromTable(@"security_settings_cryptography", @"Vector", nil);
case SECTION_ADVANCED:
return NSLocalizedStringFromTable(@"security_settings_advanced", @"Vector", nil);
}
return nil;
Section *tableSection = [self.tableViewSections sectionAtIndex:section];
return tableSection.headerTitle;
}
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
@@ -1440,8 +1485,9 @@ SetPinCoordinatorBridgePresenterDelegate>
{
if (self.tableView == tableView)
{
NSInteger section = indexPath.section;
NSInteger row = indexPath.row;
NSIndexPath *tagsIndexPath = [self.tableViewSections tagsIndexPathFromTableViewIndexPath:indexPath];
NSInteger section = tagsIndexPath.section;
NSInteger row = tagsIndexPath.row;
if (section == SECTION_CRYPTO_SESSIONS)
{
@@ -1618,13 +1664,14 @@ SetPinCoordinatorBridgePresenterDelegate>
- (MXKTableViewCellWithTextView *)settingsKeyBackupTableViewSection:(SettingsKeyBackupTableViewSection *)settingsKeyBackupTableViewSection textCellForRow:(NSInteger)textCellForRow
{
return [self textViewCellForTableView:self.tableView atIndexPath:[NSIndexPath indexPathForRow:textCellForRow inSection:SECTION_KEYBACKUP]];
NSIndexPath *indexPath = [self.tableViewSections exactIndexPathForRowTag:textCellForRow sectionTag:SECTION_KEYBACKUP];
return [self textViewCellForTableView:self.tableView atIndexPath:indexPath];
}
- (MXKTableViewCellWithButton *)settingsKeyBackupTableViewSection:(SettingsKeyBackupTableViewSection *)settingsKeyBackupTableViewSection buttonCellForRow:(NSInteger)buttonCellForRow
{
return [self buttonCellForTableView:self.tableView
atIndexPath:[NSIndexPath indexPathForRow:buttonCellForRow inSection:SECTION_KEYBACKUP]] ;
NSIndexPath *indexPath = [self.tableViewSections exactIndexPathForRowTag:buttonCellForRow sectionTag:SECTION_KEYBACKUP];
return [self buttonCellForTableView:self.tableView atIndexPath:indexPath];
}
- (void)settingsKeyBackupTableViewSectionShowKeyBackupSetup:(SettingsKeyBackupTableViewSection *)settingsKeyBackupTableViewSection
@@ -1821,4 +1868,11 @@ SetPinCoordinatorBridgePresenterDelegate>
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - TableViewSectionsDelegate
- (void)tableViewSectionsDidUpdateSections:(TableViewSections *)sections
{
[self.tableView reloadData];
}
@end