-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathAccountContentView.swift
119 lines (104 loc) · 3.47 KB
/
AccountContentView.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
//
// 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.accessibilityIdentifier = .purchaseButton
return button
}()
let redeemVoucherButton: AppButton = {
let button = AppButton(style: .success)
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.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.accessibilityIdentifier = .deleteButton
button.setTitle(NSLocalizedString(
"DELETE_BUTTON_TITLE",
tableName: "Account",
value: "Delete account",
comment: ""
), for: .normal)
return button
}()
let accountDeviceRow: AccountDeviceRow = {
AccountDeviceRow()
}()
let accountTokenRowView: AccountNumberRow = {
AccountNumberRow()
}()
let accountExpiryRowView: AccountExpiryRow = {
AccountExpiryRow()
}()
let restorePurchasesView: RestorePurchasesView = {
RestorePurchasesView()
}()
lazy var contentStackView: UIStackView = {
let stackView =
UIStackView(arrangedSubviews: [
accountDeviceRow,
accountTokenRowView,
accountExpiryRowView,
restorePurchasesView,
])
stackView.axis = .vertical
stackView.spacing = UIMetrics.padding24
stackView.setCustomSpacing(UIMetrics.padding8, after: accountExpiryRowView)
return stackView
}()
lazy var buttonStackView: UIStackView = {
var arrangedSubviews = [UIView]()
#if DEBUG
arrangedSubviews.append(redeemVoucherButton)
#endif
arrangedSubviews.append(contentsOf: [
purchaseButton,
logoutButton,
deleteButton,
])
let stackView = UIStackView(arrangedSubviews: arrangedSubviews)
stackView.axis = .vertical
stackView.spacing = UIMetrics.padding16
return stackView
}()
override init(frame: CGRect) {
super.init(frame: frame)
directionalLayoutMargins = UIMetrics.contentLayoutMargins
accessibilityIdentifier = .accountView
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")
}
}