forked from zhiphe/Potatso-iOS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConfigGroupCell.swift
168 lines (148 loc) · 5.84 KB
/
ConfigGroupCell.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
//
// ConifgGroupCell.swift
// Potatso
//
// Created by LEI on 4/4/16.
// Copyright © 2016 TouchingApp. All rights reserved.
//
import UIKit
import Cartography
import PotatsoModel
import PotatsoLibrary
class ConfigGroupCell: UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
loadView()
preservesSuperviewLayoutMargins = false
layoutMargins = UIEdgeInsetsZero
separatorInset = UIEdgeInsetsZero
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func config(group: ConfigurationGroup, hintColor: UIColor) {
nameLabel.text = group.name
proxyHintLabel.text = "Proxy".localized()
proxyLabel.text = group.proxies.first?.name ?? "None".localized()
ruleSetsHintLabel.text = "Rule Set".localized()
let desc = group.ruleSets.map { (set) -> String in
return set.name
}.joinWithSeparator(", ")
ruleSetsLabel.text = group.ruleSets.count > 0 ? "\(desc)" : "none".localized()
leftColorHintView.backgroundColor = hintColor
statusLabel.hidden = true
if group.isDefault && Manager.sharedManager.vpnStatus == .On {
statusLabel.hidden = false
}
}
func loadView() {
selectionStyle = .None
backgroundColor = UIColor.clearColor()
contentView.addSubview(backgroundWrapper)
backgroundWrapper.addSubview(leftColorHintView)
backgroundWrapper.addSubview(statusLabel)
backgroundWrapper.addSubview(nameLabel)
backgroundWrapper.addSubview(proxyHintLabel)
backgroundWrapper.addSubview(proxyLabel)
backgroundWrapper.addSubview(ruleSetsHintLabel)
backgroundWrapper.addSubview(ruleSetsLabel)
setupLayout()
}
func setupLayout() {
constrain(backgroundWrapper, contentView) { backgroundWrapper, contentView in
backgroundWrapper.edges == contentView.edges
}
constrain(leftColorHintView, backgroundWrapper) { leftColorHintView, backgroundWrapper in
leftColorHintView.leading == backgroundWrapper.leading
leftColorHintView.top == backgroundWrapper.top
leftColorHintView.bottom == backgroundWrapper.bottom
leftColorHintView.width == 3
}
constrain(nameLabel, statusLabel, backgroundWrapper) { nameLabel, statusLabel, backgroundWrapper in
statusLabel.centerY == nameLabel.centerY
statusLabel.trailing == backgroundWrapper.trailing - 15
statusLabel.width == 80
statusLabel.height == 20
}
constrain(nameLabel, proxyHintLabel, proxyLabel, backgroundWrapper) { nameLabel, proxyHintLabel, proxyLabel, backgroundWrapper in
nameLabel.leading == backgroundWrapper.leading + 20
nameLabel.top == backgroundWrapper.top + 15
nameLabel.width <= backgroundWrapper.width - 120
proxyHintLabel.leading == nameLabel.leading
proxyHintLabel.top == nameLabel.bottom + 15
proxyHintLabel.width <= backgroundWrapper.width/2 - 40
proxyLabel.leading == nameLabel.leading
proxyLabel.top == proxyHintLabel.bottom + 3
proxyLabel.width <= backgroundWrapper.width/2 - 40
}
constrain(proxyHintLabel, ruleSetsHintLabel, backgroundWrapper) { proxyHintLabel, ruleSetsHintLabel, backgroundWrapper in
ruleSetsHintLabel.leading == backgroundWrapper.centerX
ruleSetsHintLabel.top == proxyHintLabel.top
ruleSetsHintLabel.width == proxyHintLabel.width
}
constrain(proxyLabel, ruleSetsLabel, backgroundWrapper) { proxyLabel, ruleSetsLabel, backgroundWrapper in
ruleSetsLabel.leading == backgroundWrapper.centerX
ruleSetsLabel.top == proxyLabel.top
ruleSetsLabel.width == proxyLabel.width
}
}
lazy var nameLabel: UILabel = {
let v = UILabel()
v.textColor = Color.TextPrimary
v.font = UIFont.boldSystemFontOfSize(18)
v.adjustsFontSizeToFitWidth = true
v.minimumScaleFactor = 0.8
return v
}()
lazy var proxyHintLabel: UILabel = {
let v = UILabel()
v.textColor = Color.TextHint
v.font = UIFont.systemFontOfSize(12)
return v
}()
lazy var proxyLabel: UILabel = {
let v = UILabel()
v.textColor = Color.TextSecond
v.font = UIFont.systemFontOfSize(15)
v.adjustsFontSizeToFitWidth = true
v.minimumScaleFactor = 0.8
return v
}()
lazy var ruleSetsHintLabel: UILabel = {
let v = UILabel()
v.textColor = Color.TextHint
v.font = UIFont.systemFontOfSize(12)
return v
}()
lazy var ruleSetsLabel: UILabel = {
let v = UILabel()
v.textColor = Color.TextSecond
v.font = UIFont.systemFontOfSize(15)
v.adjustsFontSizeToFitWidth = true
v.minimumScaleFactor = 0.8
return v
}()
lazy var statusLabel: UILabel = {
let v = UILabel()
v.text = "Connected".localized()
v.font = UIFont.systemFontOfSize(10)
v.textColor = UIColor.whiteColor()
v.layer.cornerRadius = 10
v.layer.masksToBounds = true
v.backgroundColor = "1ABC9C".color
v.textAlignment = .Center
v.adjustsFontSizeToFitWidth = true
v.minimumScaleFactor = 0.8
return v
}()
lazy var leftColorHintView: UIView = {
let v = UIView()
v.backgroundColor = "3498DB".color
return v
}()
lazy var backgroundWrapper: UIView = {
let v = UIView()
v.backgroundColor = UIColor.whiteColor()
return v
}()
}