From 05d750539b91eff582ff6a789fcdcab73bb5f7bb Mon Sep 17 00:00:00 2001 From: Eric Kuck Date: Thu, 13 Dec 2018 12:58:50 -0600 Subject: Reorganized ViewControllers (split out UIViews and UITableViewCells into their own classes) All swiftlint warnings except one fixed up Signed-off-by: Eric Kuck --- .../TunnelDetailActivateOnDemandCell.swift | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 WireGuard/WireGuard/UI/iOS/TunnelDetail/TunnelDetailActivateOnDemandCell.swift (limited to 'WireGuard/WireGuard/UI/iOS/TunnelDetail/TunnelDetailActivateOnDemandCell.swift') diff --git a/WireGuard/WireGuard/UI/iOS/TunnelDetail/TunnelDetailActivateOnDemandCell.swift b/WireGuard/WireGuard/UI/iOS/TunnelDetail/TunnelDetailActivateOnDemandCell.swift new file mode 100644 index 0000000..9507c45 --- /dev/null +++ b/WireGuard/WireGuard/UI/iOS/TunnelDetail/TunnelDetailActivateOnDemandCell.swift @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: MIT +// Copyright © 2018 WireGuard LLC. All Rights Reserved. + +import UIKit + +class TunnelDetailActivateOnDemandCell: UITableViewCell { + var tunnel: TunnelContainer? { + didSet(value) { + update(from: tunnel?.activateOnDemandSetting()) + onDemandStatusObservervationToken = tunnel?.observe(\.isActivateOnDemandEnabled) { [weak self] tunnel, _ in + self?.update(from: tunnel.activateOnDemandSetting()) + } + } + } + + var onDemandStatusObservervationToken: AnyObject? + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: .value1, reuseIdentifier: reuseIdentifier) + textLabel?.text = "Activate on demand" + textLabel?.font = UIFont.preferredFont(forTextStyle: .body) + textLabel?.adjustsFontForContentSizeCategory = true + detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .body) + detailTextLabel?.adjustsFontForContentSizeCategory = true + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func update(from activateOnDemandSetting: ActivateOnDemandSetting?) { + detailTextLabel?.text = TunnelViewModel.activateOnDemandDetailText(for: activateOnDemandSetting) + } + + override func prepareForReuse() { + super.prepareForReuse() + textLabel?.text = "Activate on demand" + detailTextLabel?.text = "" + } +} -- cgit v1.2.3-59-g8ed1b