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
|
//
// AccountContentView.swift
// MullvadVPN
//
// Created by pronebird on 08/07/2021.
// Copyright © 2021 Mullvad VPN AB. All rights reserved.
//
import UIKit
class AccountContentView: UIView {
let purchaseButton: InAppPurchaseButton = {
let button = InAppPurchaseButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.accessibilityIdentifier = "PurchaseButton"
return button
}()
let restorePurchasesButton: AppButton = {
let button = AppButton(style: .default)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle(NSLocalizedString(
"RESTORE_PURCHASES_BUTTON_TITLE",
tableName: "Account",
value: "Restore purchases",
comment: ""
), for: .normal)
return button
}()
let redeemVoucherButton: AppButton = {
let button = AppButton(style: .success)
button.translatesAutoresizingMaskIntoConstraints = false
button.accessibilityIdentifier = "redeemVoucherButton"
button.setTitle(NSLocalizedString(
"REDEEM_VOUCHER_BUTTON_TITLE",
tableName: "Account",
value: "Redeem voucher",
comment: ""
), for: .normal)
return button
}()
let logoutButton: AppButton = {
let button = AppButton(style: .danger)
button.translatesAutoresizingMaskIntoConstraints = false
button.accessibilityIdentifier = "LogoutButton"
button.setTitle(NSLocalizedString(
"LOGOUT_BUTTON_TITLE",
tableName: "Account",
value: "Log out",
comment: ""
), for: .normal)
return button
}()
let deleteButton: AppButton = {
let button = AppButton(style: .danger)
button.translatesAutoresizingMaskIntoConstraints = false
button.accessibilityIdentifier = "DeleteButton"
button.setTitle(NSLocalizedString(
"DELETE_BUTTON_TITLE",
tableName: "Account",
value: "Delete account",
comment: ""
), for: .normal)
return button
}()
let accountDeviceRow: AccountDeviceRow = {
let view = AccountDeviceRow()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
let accountTokenRowView: AccountNumberRow = {
let view = AccountNumberRow()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
let accountExpiryRowView: AccountExpiryRow = {
let view = AccountExpiryRow()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
lazy var contentStackView: UIStackView = {
let stackView =
UIStackView(arrangedSubviews: [
accountDeviceRow,
accountTokenRowView,
accountExpiryRowView,
])
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.spacing = UIMetrics.padding8
return stackView
}()
lazy var buttonStackView: UIStackView = {
var arrangedSubviews = [UIView]()
#if DEBUG
arrangedSubviews.append(redeemVoucherButton)
#endif
arrangedSubviews.append(contentsOf: [
purchaseButton,
restorePurchasesButton,
logoutButton,
deleteButton,
])
let stackView = UIStackView(arrangedSubviews: arrangedSubviews)
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.spacing = UIMetrics.padding16
stackView.setCustomSpacing(UIMetrics.interButtonSpacing, after: restorePurchasesButton)
return stackView
}()
override init(frame: CGRect) {
super.init(frame: frame)
directionalLayoutMargins = UIMetrics.contentLayoutMargins
addConstrainedSubviews([contentStackView, buttonStackView]) {
contentStackView.pinEdgesToSuperviewMargins(.all().excluding(.bottom))
buttonStackView.topAnchor.constraint(
greaterThanOrEqualTo: contentStackView.bottomAnchor,
constant: UIMetrics.TableView.sectionSpacing
)
buttonStackView.pinEdgesToSuperviewMargins(.all().excluding(.top))
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
|