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
|
//
// OutOfTimeContentView.swift
// MullvadVPN
//
// Created by Andreas Lif on 2022-07-26.
// Copyright © 2022 Mullvad VPN AB. All rights reserved.
//
import Foundation
import UIKit
class OutOfTimeContentView: UIView {
let statusActivityView: StatusActivityView = {
let statusActivityView = StatusActivityView(state: .failure)
statusActivityView.translatesAutoresizingMaskIntoConstraints = false
return statusActivityView
}()
private lazy var titleLabel: UILabel = {
let label = UILabel()
label.text = NSLocalizedString(
"OUT_OF_TIME_TITLE",
tableName: "OutOfTime",
value: "Out of time",
comment: ""
)
label.font = UIFont.systemFont(ofSize: 32)
label.textColor = .white
return label
}()
private lazy var bodyLabel: UILabel = {
let label = UILabel()
label.textColor = .white
label.numberOfLines = 0
return label
}()
lazy var disconnectButton: AppButton = {
let button = AppButton(style: .danger)
button.translatesAutoresizingMaskIntoConstraints = false
button.alpha = 0
let localizedString = NSLocalizedString(
"OUT_OF_TIME_DISCONNECT_BUTTON",
tableName: "OutOfTime",
value: "Disconnect",
comment: ""
)
button.setTitle(localizedString, for: .normal)
return button
}()
lazy var purchaseButton: InAppPurchaseButton = {
let button = InAppPurchaseButton()
button.translatesAutoresizingMaskIntoConstraints = false
let localizedString = NSLocalizedString(
"OUT_OF_TIME_PURCHASE_BUTTON",
tableName: "OutOfTime",
value: "Add 30 days time",
comment: ""
)
button.setTitle(localizedString, for: .normal)
return button
}()
lazy var restoreButton: AppButton = {
let button = AppButton(style: .default)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle(NSLocalizedString(
"RESTORE_PURCHASES_BUTTON_TITLE",
tableName: "OutOfTime",
value: "Restore purchases",
comment: ""
), for: .normal)
return button
}()
private lazy var topStackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [statusActivityView, titleLabel, bodyLabel])
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.spacing = UIMetrics.TableView.sectionSpacing
return stackView
}()
private lazy var bottomStackView: UIStackView = {
let stackView = UIStackView(
arrangedSubviews: [disconnectButton, purchaseButton, restoreButton]
)
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.spacing = UIMetrics.TableView.sectionSpacing
return stackView
}()
override init(frame: CGRect) {
super.init(frame: frame)
translatesAutoresizingMaskIntoConstraints = false
backgroundColor = .secondaryColor
directionalLayoutMargins = UIMetrics.contentLayoutMargins
setUpSubviews()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func enableDisconnectButton(_ enabled: Bool, animated: Bool) {
disconnectButton.isEnabled = enabled
UIView.animate(withDuration: animated ? 0.25 : 0) {
self.disconnectButton.alpha = enabled ? 1 : 0
}
}
// MARK: - Private Functions
func setUpSubviews() {
addSubview(topStackView)
addSubview(bottomStackView)
configureConstraints()
}
func configureConstraints() {
NSLayoutConstraint.activate([
topStackView.centerYAnchor.constraint(equalTo: centerYAnchor, constant: -20),
topStackView.leadingAnchor.constraint(
equalTo: layoutMarginsGuide.leadingAnchor
),
topStackView.trailingAnchor.constraint(
equalTo: layoutMarginsGuide.trailingAnchor
),
bottomStackView.leadingAnchor.constraint(
equalTo: layoutMarginsGuide.leadingAnchor
),
bottomStackView.trailingAnchor.constraint(
equalTo: layoutMarginsGuide.trailingAnchor
),
bottomStackView.bottomAnchor.constraint(
equalTo: layoutMarginsGuide.bottomAnchor
),
])
}
func setBodyLabelText(_ text: String) {
bodyLabel.attributedText = NSAttributedString(
markdownString: text,
options: MarkdownStylingOptions(font: .systemFont(ofSize: 17))
)
}
}
|