aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-06 17:05:03 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-06 17:05:03 +0530
commit6c9fc8bcb11701e5ee78d05660b7c9e07021bc9a (patch)
treef7ba7234bd4c24bbdc9ae8ac248fc51eeff798c0 /WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
parentTunnel detail: Refactor out the label scrolling into a separate UI class (diff)
downloadwireguard-apple-6c9fc8bcb11701e5ee78d05660b7c9e07021bc9a.tar.xz
wireguard-apple-6c9fc8bcb11701e5ee78d05660b7c9e07021bc9a.zip
Tunnel edit: A new cell class for the public key field, to make the value scrollable
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift70
1 files changed, 70 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
index 70b40b5..87c2873 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
@@ -61,6 +61,7 @@ class TunnelEditTableViewController: UITableViewController {
self.tableView.allowsSelection = false
self.tableView.register(TunnelEditTableViewKeyValueCell.self, forCellReuseIdentifier: TunnelEditTableViewKeyValueCell.id)
+ self.tableView.register(TunnelEditTableViewReadOnlyKeyValueCell.self, forCellReuseIdentifier: TunnelEditTableViewReadOnlyKeyValueCell.id)
self.tableView.register(TunnelEditTableViewButtonCell.self, forCellReuseIdentifier: TunnelEditTableViewButtonCell.id)
self.tableView.register(TunnelEditTableViewSwitchCell.self, forCellReuseIdentifier: TunnelEditTableViewSwitchCell.id)
}
@@ -185,6 +186,11 @@ extension TunnelEditTableViewController {
}
}
return cell
+ } else if (field == .publicKey) {
+ let cell = tableView.dequeueReusableCell(withIdentifier: TunnelEditTableViewReadOnlyKeyValueCell.id, for: indexPath) as! TunnelEditTableViewReadOnlyKeyValueCell
+ cell.key = field.rawValue
+ cell.value = interfaceData[field]
+ return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: TunnelEditTableViewKeyValueCell.id, for: indexPath) as! TunnelEditTableViewKeyValueCell
// Set key
@@ -524,6 +530,70 @@ extension TunnelEditTableViewKeyValueCell: UITextFieldDelegate {
}
}
+class TunnelEditTableViewReadOnlyKeyValueCell: CopyableLabelTableViewCell {
+ static let id: String = "TunnelEditTableViewReadOnlyKeyValueCell"
+ var key: String {
+ get { return keyLabel.text ?? "" }
+ set(value) {keyLabel.text = value }
+ }
+ var value: String {
+ get { return valueLabel.text }
+ set(value) { valueLabel.text = value }
+ }
+
+ let keyLabel: UILabel
+ let valueLabel: ScrollableLabel
+
+ override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
+ keyLabel = UILabel()
+ valueLabel = ScrollableLabel()
+
+ super.init(style: style, reuseIdentifier: reuseIdentifier)
+
+ keyLabel.textColor = UIColor.gray
+ valueLabel.textColor = UIColor.gray
+
+ contentView.addSubview(keyLabel)
+ keyLabel.translatesAutoresizingMaskIntoConstraints = false
+ keyLabel.textAlignment = .right
+ let widthRatioConstraint = NSLayoutConstraint(item: keyLabel, attribute: .width,
+ relatedBy: .equal,
+ toItem: self, attribute: .width,
+ multiplier: 0.4, constant: 0)
+ // In case the key doesn't fit into 0.4 * width,
+ // so set a CR priority > the 0.4-constraint's priority.
+ widthRatioConstraint.priority = .defaultHigh + 1
+ keyLabel.setContentCompressionResistancePriority(.defaultHigh + 2, for: .horizontal)
+ NSLayoutConstraint.activate([
+ keyLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
+ keyLabel.leftAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leftAnchor),
+ widthRatioConstraint
+ ])
+
+ contentView.addSubview(valueLabel)
+ valueLabel.translatesAutoresizingMaskIntoConstraints = false
+ NSLayoutConstraint.activate([
+ valueLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
+ valueLabel.leftAnchor.constraint(equalTo: keyLabel.rightAnchor, constant: 16),
+ valueLabel.rightAnchor.constraint(equalTo: contentView.layoutMarginsGuide.rightAnchor),
+ ])
+ }
+
+ override var textToCopy: String? {
+ return self.valueLabel.text
+ }
+
+ required init?(coder aDecoder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
+ override func prepareForReuse() {
+ super.prepareForReuse()
+ key = ""
+ value = ""
+ }
+}
+
class TunnelEditTableViewButtonCell: UITableViewCell {
static let id: String = "TunnelEditTableViewButtonCell"
var buttonText: String {