]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
UI: iOS: Tunnels list: Move the "On Demand" label to the right
authorRoopesh Chander <roop@roopc.net>
Sat, 24 Jul 2021 18:03:26 +0000 (23:33 +0530)
committerRoopesh Chander <roop@roopc.net>
Tue, 27 Jul 2021 22:05:05 +0000 (03:35 +0530)
Having that at the bottom makes it harder for iOS to get
the row height correctly.

Signed-off-by: Roopesh Chander <roop@roopc.net>
Sources/WireGuardApp/Base.lproj/Localizable.strings
Sources/WireGuardApp/UI/iOS/View/TunnelListCell.swift

index 0e24ed3c081af28a219e308fe33d23e46fac6e48..8127fe5dcf016fc5b6fc06bb0dde79379c2ede5c 100644 (file)
@@ -17,7 +17,7 @@
 "tunnelsListSelectAllButtonTitle" = "Select All";
 "tunnelsListDeleteButtonTitle" = "Delete";
 "tunnelsListSelectedTitle (%d)" = "%d selected";
-"tunnelsListOnDemandActiveCellSubTitle" = "On-Demand is enabled";
+"tunnelListCaptionOnDemand" = "On Demand";
 
 // Tunnels list menu
 
index 6fc6984dfb5ea695a561b16924c708a04607b926..4dbe97cfa2fc906bac4843aa86e948bef0ea1b88 100644 (file)
@@ -35,16 +35,18 @@ class TunnelListCell: UITableViewCell {
         return nameLabel
     }()
 
-    let subTitleLabel: UILabel = {
-        let subTitleLabel = UILabel()
-        subTitleLabel.font = UIFont.preferredFont(forTextStyle: .subheadline)
+    let onDemandLabel: UILabel = {
+        let label = UILabel()
+        label.text = ""
+        label.font = UIFont.preferredFont(forTextStyle: .caption2)
+        label.adjustsFontForContentSizeCategory = true
+        label.numberOfLines = 1
         if #available(iOS 13.0, *) {
-            subTitleLabel.textColor = .secondaryLabel
+            label.textColor = .secondaryLabel
         } else {
-            subTitleLabel.textColor = .systemGray
+            label.textColor = .gray
         }
-        subTitleLabel.adjustsFontForContentSizeCategory = true
-        return subTitleLabel
+        return label
     }()
 
     let busyIndicator: UIActivityIndicatorView = {
@@ -73,38 +75,34 @@ class TunnelListCell: UITableViewCell {
 
         accessoryType = .disclosureIndicator
 
-        for subview in [statusSwitch, busyIndicator, nameLabel, subTitleLabel] {
+        for subview in [statusSwitch, busyIndicator, onDemandLabel, nameLabel] {
             subview.translatesAutoresizingMaskIntoConstraints = false
             contentView.addSubview(subview)
         }
 
         nameLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
+        onDemandLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
 
         let nameLabelBottomConstraint =
             contentView.layoutMarginsGuide.bottomAnchor.constraint(equalToSystemSpacingBelow: nameLabel.bottomAnchor, multiplier: 1)
         nameLabelBottomConstraint.priority = .defaultLow
-        self.nameLabelBottomConstraint = nameLabelBottomConstraint
-
-        subTitleLabelBottomConstraint =
-            contentView.layoutMarginsGuide.bottomAnchor.constraint(equalToSystemSpacingBelow: subTitleLabel.bottomAnchor, multiplier: 1)
-        subTitleLabelBottomConstraint?.priority = .defaultLow
 
         NSLayoutConstraint.activate([
             statusSwitch.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
             statusSwitch.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor),
             statusSwitch.leadingAnchor.constraint(equalToSystemSpacingAfter: busyIndicator.trailingAnchor, multiplier: 1),
+            statusSwitch.leadingAnchor.constraint(equalToSystemSpacingAfter: onDemandLabel.trailingAnchor, multiplier: 1),
 
             nameLabel.topAnchor.constraint(equalToSystemSpacingBelow: contentView.layoutMarginsGuide.topAnchor, multiplier: 1),
             nameLabel.leadingAnchor.constraint(equalToSystemSpacingAfter: contentView.layoutMarginsGuide.leadingAnchor, multiplier: 1),
             nameLabel.trailingAnchor.constraint(lessThanOrEqualTo: statusSwitch.leadingAnchor),
             nameLabelBottomConstraint,
 
-            subTitleLabel.topAnchor.constraint(equalToSystemSpacingBelow: nameLabel.bottomAnchor, multiplier: 0.25),
-            subTitleLabel.leadingAnchor.constraint(equalToSystemSpacingAfter: contentView.layoutMarginsGuide.leadingAnchor, multiplier: 1),
-            subTitleLabel.trailingAnchor.constraint(lessThanOrEqualTo: statusSwitch.leadingAnchor),
+            onDemandLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
+            onDemandLabel.leadingAnchor.constraint(equalToSystemSpacingAfter: nameLabel.trailingAnchor, multiplier: 1),
 
             busyIndicator.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
-            busyIndicator.leadingAnchor.constraint(equalToSystemSpacingAfter: nameLabel.trailingAnchor, multiplier: 1)
+            busyIndicator.leadingAnchor.constraint(greaterThanOrEqualToSystemSpacingAfter: nameLabel.trailingAnchor, multiplier: 1)
         ])
 
         statusSwitch.addTarget(self, action: #selector(switchToggled), for: .valueChanged)
@@ -128,20 +126,6 @@ class TunnelListCell: UITableViewCell {
         onSwitchToggled?(statusSwitch.isOn)
     }
 
-    private func setSubTitleText(_ string: String?) {
-        if let string = string {
-            subTitleLabel.text = string
-            subTitleLabel.isHidden = false
-            nameLabelBottomConstraint?.isActive = false
-            subTitleLabelBottomConstraint?.isActive = true
-        } else {
-            subTitleLabel.text = nil
-            subTitleLabel.isHidden = true
-            subTitleLabelBottomConstraint?.isActive = false
-            nameLabelBottomConstraint?.isActive = true
-        }
-    }
-
     private func update(from tunnel: TunnelContainer?, animated: Bool) {
         guard let tunnel = tunnel else {
             reset(animated: animated)
@@ -161,27 +145,23 @@ class TunnelListCell: UITableViewCell {
 
         statusSwitch.isUserInteractionEnabled = (status == .inactive || status == .active)
 
-        if tunnel.isActivateOnDemandEnabled {
-            setSubTitleText(tr("tunnelsListOnDemandActiveCellSubTitle"))
-        } else {
-            setSubTitleText(nil)
-        }
-
         if tunnel.hasOnDemandRules {
+            onDemandLabel.text = isOnDemandEngaged ? tr("tunnelListCaptionOnDemand") : ""
+            busyIndicator.stopAnimating()
             statusSwitch.isUserInteractionEnabled = true
         } else {
+            onDemandLabel.text = ""
+            if status == .inactive || status == .active {
+                busyIndicator.stopAnimating()
+            } else {
+                busyIndicator.startAnimating()
+            }
             statusSwitch.isUserInteractionEnabled = (status == .inactive || status == .active)
         }
 
-        if status == .inactive || status == .active {
-            busyIndicator.stopAnimating()
-        } else {
-            busyIndicator.startAnimating()
-        }
     }
 
     private func reset(animated: Bool) {
-        setSubTitleText(nil)
         statusSwitch.thumbTintColor = nil
         statusSwitch.setOn(false, animated: animated)
         statusSwitch.isUserInteractionEnabled = false