mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 09:02:44 +02:00
Move string formatting to Tools.
Revert contacts tracking from MatrixKit. Final tweaks before PR.
This commit is contained in:
@@ -121,7 +121,3 @@ extension AnalyticsPromptType: Identifiable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension NSAttributedString.Key {
|
||||
static let analyticsPromptTermsTextLink = NSAttributedString.Key("TermsTextLink")
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ class AnalyticsPromptViewModel: AnalyticsPromptViewModelType {
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
let termsURL: URL
|
||||
|
||||
// MARK: Public
|
||||
|
||||
@@ -37,7 +39,8 @@ class AnalyticsPromptViewModel: AnalyticsPromptViewModelType {
|
||||
// MARK: - Setup
|
||||
|
||||
/// Initialize a view model with the specified prompt type and app display name.
|
||||
init(promptType: AnalyticsPromptType, strings: AnalyticsPromptStringsProtocol) {
|
||||
init(promptType: AnalyticsPromptType, strings: AnalyticsPromptStringsProtocol, termsURL: URL) {
|
||||
self.termsURL = termsURL
|
||||
super.init(initialViewState: AnalyticsPromptViewState(promptType: promptType, strings: strings))
|
||||
}
|
||||
|
||||
@@ -70,7 +73,6 @@ class AnalyticsPromptViewModel: AnalyticsPromptViewModelType {
|
||||
|
||||
/// Open the service terms link.
|
||||
private func openTermsURL() {
|
||||
guard let url = URL(string: "https://element.io/cookie-policy") else { return }
|
||||
UIApplication.shared.open(url)
|
||||
UIApplication.shared.open(termsURL)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ final class AnalyticsPromptCoordinator: Coordinator {
|
||||
promptType = .newUser(termsString: strings.termsNewUser)
|
||||
}
|
||||
|
||||
let viewModel = AnalyticsPromptViewModel(promptType: promptType, strings: strings)
|
||||
let viewModel = AnalyticsPromptViewModel(promptType: promptType, strings: strings, termsURL: BuildSettings.analyticsTermsURL)
|
||||
|
||||
let view = AnalyticsPrompt(viewModel: viewModel.context)
|
||||
_analyticsPromptViewModel = viewModel
|
||||
|
||||
@@ -20,52 +20,14 @@ import DTCoreText
|
||||
struct AnalyticsPromptStrings: AnalyticsPromptStringsProtocol {
|
||||
let appDisplayName = AppInfo.current.displayName
|
||||
|
||||
let point1: NSAttributedString
|
||||
let point2: NSAttributedString
|
||||
let point1 = Tools.attributedString(fromHTML: VectorL10n.analyticsPromptPoint1, withAllowedTags: ["b", "p"])
|
||||
let point2 = Tools.attributedString(fromHTML: VectorL10n.analyticsPromptPoint2, withAllowedTags: ["b", "p"])
|
||||
|
||||
let termsNewUser: NSAttributedString
|
||||
let termsUpgrade: NSAttributedString
|
||||
|
||||
init() {
|
||||
self.point1 = Self.parse(VectorL10n.analyticsPromptPoint1)
|
||||
self.point2 = Self.parse(VectorL10n.analyticsPromptPoint2)
|
||||
|
||||
self.termsNewUser = Self.attach(VectorL10n.analyticsPromptTermsLinkNewUser,
|
||||
to: VectorL10n.analyticsPromptTermsNewUser("%@"))
|
||||
self.termsUpgrade = Self.attach(VectorL10n.analyticsPromptTermsLinkUpgrade,
|
||||
to: VectorL10n.analyticsPromptTermsUpgrade("%@"))
|
||||
}
|
||||
|
||||
static func parse(_ htmlString: String) -> NSAttributedString {
|
||||
// Do some sanitisation before finalizing the string
|
||||
// let sanitizeCallback: DTHTMLAttributedStringBuilderWillFlushCallback = { element in
|
||||
// element?.sanitize(with: ["b"], bodyFont: .systemFont(ofSize: UIFont.systemFontSize), imageHandler: nil)
|
||||
// print("Hello")
|
||||
// }
|
||||
|
||||
let options: [String: Any] = [
|
||||
DTUseiOS6Attributes: true, // Enable it to be able to display the attributed string in a UITextView
|
||||
DTDefaultLinkDecoration: false,
|
||||
// DTWillFlushBlockCallBack: sanitizeCallback
|
||||
]
|
||||
|
||||
guard let attributedString = NSAttributedString(htmlData: htmlString.data(using: .utf8),
|
||||
options: options,
|
||||
documentAttributes: nil) else {
|
||||
return NSAttributedString(string: htmlString)
|
||||
}
|
||||
|
||||
return MXKTools.removeDTCoreTextArtifacts(attributedString)
|
||||
}
|
||||
|
||||
static func attach(_ link: String, to terms: String) -> NSAttributedString {
|
||||
let baseString = NSMutableAttributedString(string: terms)
|
||||
let linkRange = (baseString.string as NSString).range(of: "%@")
|
||||
let formattedLink = NSAttributedString(string: VectorL10n.analyticsPromptTermsLinkNewUser,
|
||||
attributes: [.analyticsPromptTermsTextLink: true])
|
||||
baseString.replaceCharacters(in: linkRange, with: formattedLink)
|
||||
|
||||
return baseString
|
||||
}
|
||||
let termsNewUser = Tools.format(VectorL10n.analyticsPromptTermsNewUser("%@"),
|
||||
with: VectorL10n.analyticsPromptTermsLinkNewUser,
|
||||
using: BuildSettings.analyticsTermsURL)
|
||||
let termsUpgrade = Tools.format(VectorL10n.analyticsPromptTermsUpgrade("%@"),
|
||||
with: VectorL10n.analyticsPromptTermsLinkUpgrade,
|
||||
using: BuildSettings.analyticsTermsURL)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@ enum MockAnalyticsPromptScreenState: MockScreenState, CaseIterable {
|
||||
promptType = analyticsPromptType
|
||||
}
|
||||
let viewModel = AnalyticsPromptViewModel(promptType: promptType,
|
||||
strings: MockAnalyticsPromptStrings())
|
||||
strings: MockAnalyticsPromptStrings(),
|
||||
termsURL: URL(string: "https://element.io/cookie-policy")!)
|
||||
|
||||
return (
|
||||
[promptType, viewModel],
|
||||
|
||||
@@ -40,12 +40,12 @@ struct MockAnalyticsPromptStrings: AnalyticsPromptStringsProtocol {
|
||||
self.point2 = point2
|
||||
|
||||
let termsNewUser = NSMutableAttributedString(string: "You can read all our terms ")
|
||||
termsNewUser.append(NSAttributedString(string: "here", attributes: [.analyticsPromptTermsTextLink: true]))
|
||||
termsNewUser.append(NSAttributedString(string: "here", attributes: [.link: URL(string: "https://element.io/cookie-policy")!]))
|
||||
termsNewUser.append(NSAttributedString(string: "."))
|
||||
self.termsNewUser = termsNewUser
|
||||
|
||||
let termsUpgrade = NSMutableAttributedString(string: "Read all our terms ")
|
||||
termsUpgrade.append(NSAttributedString(string: "here", attributes: [.analyticsPromptTermsTextLink: true]))
|
||||
termsUpgrade.append(NSAttributedString(string: "here", attributes: [.link: URL(string: "https://element.io/cookie-policy")!]))
|
||||
termsUpgrade.append(NSAttributedString(string: ". Is that OK?"))
|
||||
self.termsUpgrade = termsUpgrade
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ struct AnalyticsPromptTermsText: View {
|
||||
let string = attributedString.string as NSString
|
||||
|
||||
attributedString.enumerateAttributes(in: range, options: []) { attributes, range, stop in
|
||||
let isLink = attributes.keys.contains(.analyticsPromptTermsTextLink)
|
||||
let isLink = attributes.keys.contains(.link)
|
||||
components.append(StringComponent(string: string.substring(with: range), isLink: isLink))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user