-
Notifications
You must be signed in to change notification settings - Fork 381
/
Copy pathRevokedDeviceViewController.swift
178 lines (150 loc) · 6.05 KB
/
RevokedDeviceViewController.swift
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//
// RevokedDeviceViewController.swift
// MullvadVPN
//
// Created by pronebird on 07/07/2022.
// Copyright © 2022 Mullvad VPN AB. All rights reserved.
//
import UIKit
class RevokedDeviceViewController: UIViewController, RootContainment {
private lazy var imageView: StatusImageView = {
let statusImageView = StatusImageView(style: .failure)
statusImageView.translatesAutoresizingMaskIntoConstraints = false
return statusImageView
}()
private lazy var titleLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.font = UIFont.systemFont(ofSize: 24, weight: .bold)
titleLabel.numberOfLines = 0
titleLabel.textColor = .white
titleLabel.text = NSLocalizedString(
"TITLE_LABEL",
tableName: "RevokedDevice",
value: "Device is inactive",
comment: ""
)
return titleLabel
}()
private lazy var bodyLabel: UILabel = {
let bodyLabel = UILabel()
bodyLabel.translatesAutoresizingMaskIntoConstraints = false
bodyLabel.font = UIFont.systemFont(ofSize: 17, weight: .semibold)
bodyLabel.numberOfLines = 0
bodyLabel.textColor = .white
bodyLabel.text = NSLocalizedString(
"DESCRIPTION_LABEL",
tableName: "RevokedDevice",
value: "You have removed this device. To connect again, you will need to log back in.",
comment: ""
)
return bodyLabel
}()
private lazy var footerLabel: UILabel = {
let bodyLabel = UILabel()
bodyLabel.translatesAutoresizingMaskIntoConstraints = false
bodyLabel.font = UIFont.systemFont(ofSize: 17, weight: .semibold)
bodyLabel.numberOfLines = 0
bodyLabel.textColor = .white
bodyLabel.text = NSLocalizedString(
"UNBLOCK_INTERNET_LABEL",
tableName: "RevokedDevice",
value: "Going to login will unblock the Internet on this device.",
comment: ""
)
return bodyLabel
}()
private lazy var logoutButton: AppButton = {
let button = AppButton(style: .default)
button.accessibilityIdentifier = .revokedDeviceLoginButton
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle(
NSLocalizedString(
"GOTO_LOGIN_BUTTON_LABEL",
tableName: "RevokedDevice",
value: "Go to login",
comment: ""
),
for: .normal
)
return button
}()
var didFinish: (() -> Void)?
override var preferredStatusBarStyle: UIStatusBarStyle {
.lightContent
}
var preferredHeaderBarPresentation: HeaderBarPresentation {
let tunnelState = interactor.tunnelStatus.state
return HeaderBarPresentation(
style: tunnelState.isSecured ? .secured : .unsecured,
showsDivider: true
)
}
var prefersHeaderBarHidden: Bool {
false
}
private let interactor: RevokedDeviceInteractor
init(interactor: RevokedDeviceInteractor) {
self.interactor = interactor
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
view.accessibilityIdentifier = .revokedDeviceView
view.backgroundColor = .secondaryColor
view.directionalLayoutMargins = UIMetrics.contentLayoutMargins
for subview in [imageView, titleLabel, bodyLabel, footerLabel, logoutButton] {
view.addSubview(subview)
}
logoutButton.addTarget(
self,
action: #selector(didTapLogoutButton(_:)),
for: .touchUpInside
)
NSLayoutConstraint.activate([
imageView.topAnchor.constraint(
equalTo: view.layoutMarginsGuide.topAnchor,
constant: 30
),
imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
titleLabel.topAnchor.constraint(
equalTo: imageView.bottomAnchor,
constant: 30
),
titleLabel.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor),
titleLabel.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor),
bodyLabel.topAnchor.constraint(
equalTo: titleLabel.bottomAnchor,
constant: 16
),
bodyLabel.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor),
bodyLabel.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor),
footerLabel.topAnchor.constraint(
equalTo: bodyLabel.bottomAnchor,
constant: 16
),
footerLabel.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor),
footerLabel.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor),
logoutButton.topAnchor.constraint(greaterThanOrEqualTo: footerLabel.bottomAnchor),
logoutButton.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor),
logoutButton.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor),
logoutButton.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor),
])
interactor.didUpdateTunnelStatus = { [weak self] tunnelStatus in
self?.setNeedsHeaderBarStyleAppearanceUpdate()
self?.updateView(tunnelState: tunnelStatus.state)
}
updateView(tunnelState: interactor.tunnelStatus.state)
}
@objc private func didTapLogoutButton(_ sender: Any?) {
logoutButton.isEnabled = false
didFinish?()
}
private func updateView(tunnelState: TunnelState) {
logoutButton.style = tunnelState.isSecured ? .danger : .default
footerLabel.isHidden = !tunnelState.isSecured
}
}