diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-11-24 12:59:56 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-11-24 12:59:56 +0100 |
| commit | cc41048e50a5d698efa9673de8dbb2c3ea5cbe5d (patch) | |
| tree | e8c58fcf2c9b4c098ec941eee8b01b2597654af2 | |
| parent | c2576a177898ae0afb2898e6fab82a40995368b8 (diff) | |
| parent | d817bdeb10a23d17246081324a734bc96331f766 (diff) | |
| download | mullvadvpn-cc41048e50a5d698efa9673de8dbb2c3ea5cbe5d.tar.xz mullvadvpn-cc41048e50a5d698efa9673de8dbb2c3ea5cbe5d.zip | |
Merge branch 'update-custom-dns-copy'
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 4 | ||||
| -rw-r--r-- | ios/MullvadVPN/NSAttributedString+Markdown.swift | 33 | ||||
| -rw-r--r-- | ios/MullvadVPN/PreferencesDataSource.swift | 51 | ||||
| -rw-r--r-- | ios/MullvadVPN/PreferencesViewModel.swift | 43 | ||||
| -rw-r--r-- | ios/MullvadVPN/en.lproj/Preferences.strings | 15 |
5 files changed, 91 insertions, 55 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index 8ddd24c52d..114e831799 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -107,6 +107,7 @@ 584E96BC240FD4DA00D3334F /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58A1AA8623F43901009F7EA6 /* Location.swift */; }; 584E96BD240FD4DA00D3334F /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58A1AA8623F43901009F7EA6 /* Location.swift */; }; 584E96BE240FD4DB00D3334F /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58A1AA8623F43901009F7EA6 /* Location.swift */; }; + 584EBDBD2747C98F00A0C9FD /* NSAttributedString+Markdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = 584EBDBC2747C98F00A0C9FD /* NSAttributedString+Markdown.swift */; }; 5850366825A47AC700A43E93 /* IPAddressRange+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5850366725A47AC700A43E93 /* IPAddressRange+Codable.swift */; }; 5850367F25A481D800A43E93 /* IPAddressRange+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5850366725A47AC700A43E93 /* IPAddressRange+Codable.swift */; }; 5850368C25A49E2200A43E93 /* PrivateKeyWithMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58C6B35322BB87C4003C19AD /* PrivateKeyWithMetadata.swift */; }; @@ -412,6 +413,7 @@ 584D26C1270C8542004EA533 /* SettingsStaticTextFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsStaticTextFooterView.swift; sourceTree = "<group>"; }; 584D26C3270C855A004EA533 /* PreferencesDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesDataSource.swift; sourceTree = "<group>"; }; 584D26C5270C8741004EA533 /* SettingsDNSTextCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsDNSTextCell.swift; sourceTree = "<group>"; }; + 584EBDBC2747C98F00A0C9FD /* NSAttributedString+Markdown.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+Markdown.swift"; sourceTree = "<group>"; }; 5850366725A47AC700A43E93 /* IPAddressRange+Codable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "IPAddressRange+Codable.swift"; sourceTree = "<group>"; }; 58561C98239A5D1500BD6B5E /* IPEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPEndpoint.swift; sourceTree = "<group>"; }; 5856D13627450A8A00DFD627 /* UIImage+TintColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+TintColor.swift"; sourceTree = "<group>"; }; @@ -865,6 +867,7 @@ 587B753C2666468F00DEF7E9 /* NotificationController.swift */, 587B7535266528A200DEF7E9 /* NotificationManager.swift */, 587B75422669034500DEF7E9 /* Notifications */, + 584EBDBC2747C98F00A0C9FD /* NSAttributedString+Markdown.swift */, 5871FB9F254C26BF0051A0A4 /* NSRegularExpression+IPAddress.swift */, 58CC40EE24A601900019D96E /* ObserverList.swift */, 580EE1FF24B3218800F9D8A1 /* Operations */, @@ -1420,6 +1423,7 @@ 5806766E27048E5600C858CB /* KeychainMatchLimit.swift in Sources */, 58CCA01E2242787B004F3011 /* AccountTextField.swift in Sources */, 584592612639B4A200EF967F /* ConsentContentView.swift in Sources */, + 584EBDBD2747C98F00A0C9FD /* NSAttributedString+Markdown.swift in Sources */, 5875960A26F371FC00BF6711 /* TunnelIPCSession.swift in Sources */, 58FB865E26EA284E00F188BC /* LogFormatting.swift in Sources */, 587AD7CA2342283900E93A53 /* Account.swift in Sources */, diff --git a/ios/MullvadVPN/NSAttributedString+Markdown.swift b/ios/MullvadVPN/NSAttributedString+Markdown.swift new file mode 100644 index 0000000000..af13fb5b95 --- /dev/null +++ b/ios/MullvadVPN/NSAttributedString+Markdown.swift @@ -0,0 +1,33 @@ +// +// NSAttributedString+Markdown.swift +// MullvadVPN +// +// Created by pronebird on 19/11/2021. +// Copyright © 2021 Mullvad VPN AB. All rights reserved. +// + +import UIKit + +extension NSAttributedString { + convenience init(markdownString: String, font: UIFont) { + let attributedString = NSMutableAttributedString() + let components = markdownString.components(separatedBy: "**") + + let fontDescriptor = font.fontDescriptor.withSymbolicTraits(.traitBold) ?? font.fontDescriptor + let boldFont = UIFont(descriptor: fontDescriptor, size: font.pointSize) + + for (index, string) in components.enumerated() { + var attributes = [NSAttributedString.Key: Any]() + + if index % 2 == 0 { + attributes[.font] = font + } else { + attributes[.font] = boldFont + } + + attributedString.append(NSAttributedString(string: string, attributes: attributes)) + } + + self.init(attributedString: attributedString) + } +} diff --git a/ios/MullvadVPN/PreferencesDataSource.swift b/ios/MullvadVPN/PreferencesDataSource.swift index a89c1bc3e8..74c96ba0e5 100644 --- a/ios/MullvadVPN/PreferencesDataSource.swift +++ b/ios/MullvadVPN/PreferencesDataSource.swift @@ -115,6 +115,7 @@ class PreferencesDataSource: NSObject, UITableViewDataSource, UITableViewDelegat let diffResult = oldSnapshot.difference(snapshot) if let tableView = tableView { diffResult.apply(to: tableView, animateDifferences: animated) + reloadCustomDNSFooter() } } else { tableView?.reloadData() @@ -373,27 +374,7 @@ class PreferencesDataSource: NSObject, UITableViewDataSource, UITableViewDelegat self?.setEnableCustomDNS(isOn) } - switch viewModel.customDNSPrecondition { - case .satisfied: - cell.accessibilityHint = nil - - case .emptyDNSDomains: - cell.accessibilityHint = NSLocalizedString( - "CUSTOM_DNS_NO_DNS_ENTRIES_ACCESSIBILITY_HINT", - tableName: "Preferences", - value: "Please add at least one DNS domain to activate this setting.", - comment: "" - ) - - case .conflictsWithOtherSettings: - cell.accessibilityHint = NSLocalizedString( - "CUSTOM_DNS_DISABLE_ADTRACKER_BLOCKING_ACCESSIBILITY_HINT", - tableName: "Preferences", - value: "Disable Block Ads and Block trackers to activate this setting.", - comment: "" - ) - } - + cell.accessibilityHint = viewModel.customDNSPrecondition.localizedDescription(isEditing: isEditing) return cell @@ -565,30 +546,10 @@ class PreferencesDataSource: NSObject, UITableViewDataSource, UITableViewDelegat } private func configureFooterView(_ reusableView: SettingsStaticTextFooterView) { - let footerText: String? - - switch viewModel.customDNSPrecondition { - case .satisfied: - footerText = nil - - case .emptyDNSDomains: - footerText = NSLocalizedString( - "CUSTOM_DNS_NO_DNS_ENTRIES_FOOTNOTE", - tableName: "Preferences", - value: "Please add at least one DNS domain to activate this setting.", - comment: "" - ) - - case .conflictsWithOtherSettings: - footerText = NSLocalizedString( - "CUSTOM_DNS_DISABLE_ADTRACKER_BLOCKING_FOOTNOTE", - tableName: "Preferences", - value: "Disable Block Ads and Block trackers to activate this setting.", - comment: "" - ) - } - - reusableView.titleLabel.text = footerText + let font = reusableView.titleLabel.font ?? UIFont.systemFont(ofSize: UIFont.systemFontSize) + + reusableView.titleLabel.attributedText = viewModel.customDNSPrecondition + .attributedLocalizedDescription(isEditing: isEditing, preferredFont: font) } } diff --git a/ios/MullvadVPN/PreferencesViewModel.swift b/ios/MullvadVPN/PreferencesViewModel.swift index b7733b1d2e..de4fdaba81 100644 --- a/ios/MullvadVPN/PreferencesViewModel.swift +++ b/ios/MullvadVPN/PreferencesViewModel.swift @@ -6,7 +6,7 @@ // Copyright © 2021 Mullvad VPN AB. All rights reserved. // -import Foundation +import UIKit enum CustomDNSPrecondition { /// Custom DNS can be enabled @@ -17,6 +17,47 @@ enum CustomDNSPrecondition { /// No valid DNS server entries. case emptyDNSDomains + + /// Returns localized description explaining how to enable Custom DNS. + func localizedDescription(isEditing: Bool) -> String? { + return attributedLocalizedDescription( + isEditing: isEditing, + preferredFont: UIFont.systemFont(ofSize: UIFont.systemFontSize) + )?.string + } + + /// Returns attributed localized description explaining how to enable Custom DNS. + func attributedLocalizedDescription(isEditing: Bool, preferredFont: UIFont) -> NSAttributedString? { + switch self { + case .satisfied: + return nil + + case .emptyDNSDomains: + if isEditing { + return NSAttributedString(markdownString: NSLocalizedString( + "CUSTOM_DNS_NO_DNS_ENTRIES_EDITING_ON_FOOTNOTE", + tableName: "Preferences", + value: "To enable this setting, add at least one server.", + comment: "Foot note displayed if there are no DNS entries and table view is in editing mode." + ), font: preferredFont) + } else { + return NSAttributedString(markdownString: NSLocalizedString( + "CUSTOM_DNS_NO_DNS_ENTRIES_EDITING_OFF_FOOTNOTE", + tableName: "Preferences", + value: "Tap **Edit** to add at least one DNS server.", + comment: "Foot note displayed if there are no DNS entries, but table view is not in editing mode." + ), font: preferredFont) + } + + case .conflictsWithOtherSettings: + return NSAttributedString(markdownString: NSLocalizedString( + "CUSTOM_DNS_DISABLE_ADTRACKER_BLOCKING_FOOTNOTE", + tableName: "Preferences", + value: "Disable **Block ads** and **Block trackers** to activate this setting.", + comment: "Foot note displayed when custom DNS cannot be enabled, because ad/tracker blockers features should be disabled first." + ), font: preferredFont) + } + } } struct DNSServerEntry: Equatable, Hashable { diff --git a/ios/MullvadVPN/en.lproj/Preferences.strings b/ios/MullvadVPN/en.lproj/Preferences.strings index 74e87385d1..30be83d034 100644 --- a/ios/MullvadVPN/en.lproj/Preferences.strings +++ b/ios/MullvadVPN/en.lproj/Preferences.strings @@ -10,17 +10,14 @@ /* No comment provided by engineer. */ "CUSTOM_DNS_CELL_LABEL" = "Use custom DNS"; -/* No comment provided by engineer. */ -"CUSTOM_DNS_DISABLE_ADTRACKER_BLOCKING_ACCESSIBILITY_HINT" = "Disable Block Ads and Block trackers to activate this setting."; +/* Foot note displayed when custom DNS cannot be enabled, because ad/tracker blockers features should be disabled first. */ +"CUSTOM_DNS_DISABLE_ADTRACKER_BLOCKING_FOOTNOTE" = "Disable **Block ads** and **Block trackers** to activate this setting."; -/* No comment provided by engineer. */ -"CUSTOM_DNS_DISABLE_ADTRACKER_BLOCKING_FOOTNOTE" = "Disable Block Ads and Block trackers to activate this setting."; +/* Foot note displayed if there are no DNS entries, but table view is not in editing mode. */ +"CUSTOM_DNS_NO_DNS_ENTRIES_EDITING_OFF_FOOTNOTE" = "Tap **Edit** to add at least one DNS server."; -/* No comment provided by engineer. */ -"CUSTOM_DNS_NO_DNS_ENTRIES_ACCESSIBILITY_HINT" = "Please add at least one DNS domain to activate this setting."; - -/* No comment provided by engineer. */ -"CUSTOM_DNS_NO_DNS_ENTRIES_FOOTNOTE" = "Please add at least one DNS domain to activate this setting."; +/* Foot note displayed if there are no DNS entries and table view is in editing mode. */ +"CUSTOM_DNS_NO_DNS_ENTRIES_EDITING_ON_FOOTNOTE" = "To enable this setting, add at least one server."; /* Navigation title */ "NAVIGATION_TITLE" = "Preferences"; |
