-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrivacyPolicyAlertOperation.swift
More file actions
81 lines (71 loc) · 2.64 KB
/
Copy pathPrivacyPolicyAlertOperation.swift
File metadata and controls
81 lines (71 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import UIKit
import RKOperations
/// Показывает алерт на старте приложения с политикой, условиями использования и кнопкой принять
///
/// Алерт будет показываться до тех пор, пока не будет нажата кнопка "Принять"
final class PrivacyPolicyAlertOperation: RKOperation, @unchecked Sendable {
private weak var controller: UIViewController?
private let context: Context
private let handler: Handler
init(controller: UIViewController, context: Context, handler: Handler) {
self.controller = controller
self.context = context
self.handler = handler
super.init()
}
override func execute() {
DispatchQueue.main.async { [weak self] in
self?.showAlert()
}
}
}
// MARK: - Context and Handler
extension PrivacyPolicyAlertOperation {
struct Context {
let privacyPolicyURL: URL
let termsOfUseURL: URL
}
struct Handler {
let onPrivacyAccepted: () -> Void
let openURL: (URL) -> Void
}
}
// MARK: - Alert
private extension PrivacyPolicyAlertOperation {
func showAlert() {
let alert = UIAlertController(
title: NSLocalizedString("privacy_alert_title", comment: ""),
message: NSLocalizedString("privacy_alert_message", comment: ""),
preferredStyle: .alert
)
let context = context
alert.addAction(UIAlertAction(
title: NSLocalizedString("privacy_alert_terms_of_use_button", comment: ""),
style: .default,
handler: { [weak self] _ in
guard let self = self else { return }
self.handler.openURL(context.termsOfUseURL)
self.showAlert()
}
))
alert.addAction(UIAlertAction(
title: NSLocalizedString("privacy_alert_privacy_policy_button", comment: ""),
style: .default,
handler: { [weak self] _ in
guard let self = self else { return }
self.handler.openURL(context.privacyPolicyURL)
self.showAlert()
}
))
alert.addAction(UIAlertAction(
title: NSLocalizedString("privacy_alert_accept_button", comment: ""),
style: .default,
handler: { [weak self] _ in
guard let self = self else { return }
self.handler.onPrivacyAccepted()
self.finish()
}
))
controller?.present(alert, animated: true, completion: nil)
}
}