From 0514b0bddc43c4e9d6fcc8aaf3d9f132f7d7d231 Mon Sep 17 00:00:00 2001 From: Doug Date: Wed, 20 Oct 2021 19:29:23 +0100 Subject: [PATCH] Address Steve's comments. --- Riot/Managers/AppInfo/AppVersion.swift | 2 +- Riot/Modules/Common/Models/Section.swift | 15 +++++++++++- .../SectionFooters/SectionFooterView.swift | 21 ++++++++++------ .../SettingsDiscoveryTableViewSection.swift | 6 ++--- .../Security/SecurityViewController.m | 2 +- .../Modules/Settings/SettingsViewController.m | 24 +++++++++++++++---- 6 files changed, 51 insertions(+), 19 deletions(-) diff --git a/Riot/Managers/AppInfo/AppVersion.swift b/Riot/Managers/AppInfo/AppVersion.swift index dc75e5994..ff7e25080 100644 --- a/Riot/Managers/AppInfo/AppVersion.swift +++ b/Riot/Managers/AppInfo/AppVersion.swift @@ -96,7 +96,7 @@ final class AppVersion: NSObject { } override var description: String { - return "\(bundleShortVersion) (\(bundleVersion))" + return "\(bundleShortVersion)(\(bundleVersion))" } // MARK: - Private diff --git a/Riot/Modules/Common/Models/Section.swift b/Riot/Modules/Common/Models/Section.swift index c9cae8131..8b7131208 100644 --- a/Riot/Modules/Common/Models/Section.swift +++ b/Riot/Modules/Common/Models/Section.swift @@ -21,9 +21,22 @@ final class Section: NSObject { let tag: Int var rows: [Row] - var headerTitle: String? + var attributedHeaderTitle: NSAttributedString? var attributedFooterTitle: NSAttributedString? + var headerTitle: String? { + get { + attributedHeaderTitle?.string + } + set { + guard let newValue = newValue else { + attributedHeaderTitle = nil + return + } + + attributedHeaderTitle = NSAttributedString(string: newValue) + } + } var footerTitle: String? { get { attributedFooterTitle?.string diff --git a/Riot/Modules/Common/SectionFooters/SectionFooterView.swift b/Riot/Modules/Common/SectionFooters/SectionFooterView.swift index 21ac03c7a..92c36e88c 100644 --- a/Riot/Modules/Common/SectionFooters/SectionFooterView.swift +++ b/Riot/Modules/Common/SectionFooters/SectionFooterView.swift @@ -34,19 +34,15 @@ class SectionFooterView: UITableViewHeaderFooterView, NibLoadable, Themable { UINib(nibName: String(describing: self), bundle: Bundle(for: self)) } + /// The amount to inset the footer label on its leading side, relative to the safe area insets. var leadingInset: CGFloat { get { footerLabelLeadingConstraint.constant } set { footerLabelLeadingConstraint.constant = newValue } } - // Expose `footerLabel` as the default label property. - override var textLabel: UILabel? { - footerLabel - } - /// The text label added in the xib file. Using our own label was necessary due to the behaviour - /// on iOS 12-14 where any customisation to the text label would be wiped out after being set - /// in `tableView:viewForFooterInSection`. This behaviour is fixed in iOS 15. + /// on iOS 12-14 where any customisation to the existing text label is wiped out after being + /// set in `tableView:viewForFooterInSection`. This behaviour is fixed in iOS 15. @IBOutlet private weak var footerLabel: UILabel! /// The label's leading constraint, relative to the safe area insets. @IBOutlet private weak var footerLabelLeadingConstraint: NSLayoutConstraint! @@ -66,4 +62,15 @@ class SectionFooterView: UITableViewHeaderFooterView, NibLoadable, Themable { footerLabel.font = theme.fonts.subheadline footerLabel.numberOfLines = 0 } + + /// Update the footer with new text. + func update(withText text: String) { + footerLabel.text = text + } + + /// Update the footer with attributed text. Be sure to call this after calling `update(theme:)` + /// otherwise any color or font attributes will be wiped out by the theme. + func update(withAttributedText attributedText: NSAttributedString) { + footerLabel.attributedText = attributedText + } } diff --git a/Riot/Modules/Settings/Discovery/SettingsDiscoveryTableViewSection.swift b/Riot/Modules/Settings/Discovery/SettingsDiscoveryTableViewSection.swift index 187f53c8c..64e96878f 100644 --- a/Riot/Modules/Settings/Discovery/SettingsDiscoveryTableViewSection.swift +++ b/Riot/Modules/Settings/Discovery/SettingsDiscoveryTableViewSection.swift @@ -216,12 +216,10 @@ private enum DiscoverySectionRows { } private func threePidsManagementInfoAttributedString() -> NSAttributedString { - let attributedInfoString = NSMutableAttributedString(string: VectorL10n.settingsDiscoveryThreePidsManagementInformationPart1, - attributes: [:]) + let attributedInfoString = NSMutableAttributedString(string: VectorL10n.settingsDiscoveryThreePidsManagementInformationPart1) attributedInfoString.append(NSAttributedString(string: VectorL10n.settingsDiscoveryThreePidsManagementInformationPart2, attributes: [.foregroundColor: self.theme.tintColor])) - attributedInfoString.append(NSAttributedString(string: VectorL10n.settingsDiscoveryThreePidsManagementInformationPart3, - attributes: [:])) + attributedInfoString.append(NSAttributedString(string: VectorL10n.settingsDiscoveryThreePidsManagementInformationPart3)) return attributedInfoString } } diff --git a/Riot/Modules/Settings/Security/SecurityViewController.m b/Riot/Modules/Settings/Security/SecurityViewController.m index 5e479e534..fce6d5c9b 100644 --- a/Riot/Modules/Settings/Security/SecurityViewController.m +++ b/Riot/Modules/Settings/Security/SecurityViewController.m @@ -1314,7 +1314,7 @@ TableViewSectionsDelegate> SectionFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:SectionFooterView.defaultReuseIdentifier]; [view updateWithTheme:ThemeService.shared.theme]; view.leadingInset = tableView.vc_separatorInset.left; - view.textLabel.text = footerTitle; + [view updateWithText:footerTitle]; return view; } diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index 458eb48da..0a5acf57c 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -279,6 +279,7 @@ TableViewSectionsDelegate> set automatically when calling `prepareIdentityServiceAndPresentTermsWithSession:checkingAccessForContactsOnAccept` */ @property (nonatomic) BOOL serviceTermsModalShouldCheckAccessForContactsOnAccept; +@property (nonatomic) BOOL isPreparingIdentityService; @property (nonatomic, strong) ServiceTermsModalCoordinatorBridgePresenter *serviceTermsModalCoordinatorBridgePresenter; @end @@ -541,8 +542,9 @@ TableViewSectionsDelegate> if (BuildSettings.settingsScreenShowAdvancedSettings) { - sectionAbout.footerTitle = [NSString stringWithFormat:@"Element %@ / Olm %@\n%@\n%@", - AppInfo.current.appVersion.description, + sectionAbout.footerTitle = [NSString stringWithFormat:@"Element %@ (%@) / Olm %@\n%@\n%@", + AppInfo.current.appVersion.bundleShortVersion, + AppInfo.current.appVersion.bundleVersion, [OLMKit versionString], [MatrixKitL10n settingsConfigUserId:account.mxCredentials.userId], [MatrixKitL10n settingsConfigHomeServer:account.mxCredentials.homeServer]]; @@ -2443,7 +2445,7 @@ TableViewSectionsDelegate> SectionFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:SectionFooterView.defaultReuseIdentifier]; [view updateWithTheme:ThemeService.shared.theme]; view.leadingInset = tableView.vc_separatorInset.left; - view.textLabel.attributedText = attributedFooterTitle; + [view updateWithAttributedText:attributedFooterTitle]; if (section == SECTION_TAG_USER_SETTINGS) { @@ -4393,6 +4395,12 @@ TableViewSectionsDelegate> - (void)prepareIdentityServiceAndPresentTermsWithSession:(MXSession *)session checkingAccessForContactsOnAccept:(BOOL)checkAccessForContacts { + if (self.isPreparingIdentityService) + { + return; + } + + self.isPreparingIdentityService = YES; self.serviceTermsModalShouldCheckAccessForContactsOnAccept = checkAccessForContacts; MXWeakify(self); @@ -4405,6 +4413,7 @@ TableViewSectionsDelegate> MXStrongifyAndReturnIfNil(self); [self stopActivityIndicator]; + self.isPreparingIdentityService = NO; // Present the terms of the identity server. [self presentIdentityServerTermsWithSession:session baseURL:baseURL andAccessToken:accessToken]; @@ -4412,6 +4421,7 @@ TableViewSectionsDelegate> MXStrongifyAndReturnIfNil(self); [self stopActivityIndicator]; + self.isPreparingIdentityService = NO; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:VectorL10n.findYourContactsIdentityServiceError message:nil @@ -4468,8 +4478,9 @@ TableViewSectionsDelegate> - (void)serviceTermsModalCoordinatorBridgePresenterDelegateDidDecline:(ServiceTermsModalCoordinatorBridgePresenter * _Nonnull)coordinatorBridgePresenter session:(MXSession *)session { - // Disable the contacts toggle as the terms weren't accepted. + // Terms weren't accepted: disable contacts toggle and refresh discovery [self updateSections]; + [self.settingsDiscoveryTableViewSection reload]; [coordinatorBridgePresenter dismissWithAnimated:YES completion:nil]; self.serviceTermsModalCoordinatorBridgePresenter = nil; @@ -4477,7 +4488,10 @@ TableViewSectionsDelegate> - (void)serviceTermsModalCoordinatorBridgePresenterDelegateDidClose:(ServiceTermsModalCoordinatorBridgePresenter * _Nonnull)coordinatorBridgePresenter { - [self updateSections]; // Disables the contacts toggle as the terms weren't accepted. + // Terms weren't accepted: disable contacts toggle and refresh discovery + [self updateSections]; + [self.settingsDiscoveryTableViewSection reload]; + self.serviceTermsModalCoordinatorBridgePresenter = nil; }