UI: iOS: Tunnels list: Move the "On Demand" label to the right
Having that at the bottom makes it harder for iOS to get the row height correctly. Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
147ac02f0d
commit
64c2fb337d
|
@ -17,7 +17,7 @@
|
||||||
"tunnelsListSelectAllButtonTitle" = "Select All";
|
"tunnelsListSelectAllButtonTitle" = "Select All";
|
||||||
"tunnelsListDeleteButtonTitle" = "Delete";
|
"tunnelsListDeleteButtonTitle" = "Delete";
|
||||||
"tunnelsListSelectedTitle (%d)" = "%d selected";
|
"tunnelsListSelectedTitle (%d)" = "%d selected";
|
||||||
"tunnelsListOnDemandActiveCellSubTitle" = "On-Demand is enabled";
|
"tunnelListCaptionOnDemand" = "On Demand";
|
||||||
|
|
||||||
// Tunnels list menu
|
// Tunnels list menu
|
||||||
|
|
||||||
|
|
|
@ -35,16 +35,18 @@ class TunnelListCell: UITableViewCell {
|
||||||
return nameLabel
|
return nameLabel
|
||||||
}()
|
}()
|
||||||
|
|
||||||
let subTitleLabel: UILabel = {
|
let onDemandLabel: UILabel = {
|
||||||
let subTitleLabel = UILabel()
|
let label = UILabel()
|
||||||
subTitleLabel.font = UIFont.preferredFont(forTextStyle: .subheadline)
|
label.text = ""
|
||||||
|
label.font = UIFont.preferredFont(forTextStyle: .caption2)
|
||||||
|
label.adjustsFontForContentSizeCategory = true
|
||||||
|
label.numberOfLines = 1
|
||||||
if #available(iOS 13.0, *) {
|
if #available(iOS 13.0, *) {
|
||||||
subTitleLabel.textColor = .secondaryLabel
|
label.textColor = .secondaryLabel
|
||||||
} else {
|
} else {
|
||||||
subTitleLabel.textColor = .systemGray
|
label.textColor = .gray
|
||||||
}
|
}
|
||||||
subTitleLabel.adjustsFontForContentSizeCategory = true
|
return label
|
||||||
return subTitleLabel
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
let busyIndicator: UIActivityIndicatorView = {
|
let busyIndicator: UIActivityIndicatorView = {
|
||||||
|
@ -73,38 +75,34 @@ class TunnelListCell: UITableViewCell {
|
||||||
|
|
||||||
accessoryType = .disclosureIndicator
|
accessoryType = .disclosureIndicator
|
||||||
|
|
||||||
for subview in [statusSwitch, busyIndicator, nameLabel, subTitleLabel] {
|
for subview in [statusSwitch, busyIndicator, onDemandLabel, nameLabel] {
|
||||||
subview.translatesAutoresizingMaskIntoConstraints = false
|
subview.translatesAutoresizingMaskIntoConstraints = false
|
||||||
contentView.addSubview(subview)
|
contentView.addSubview(subview)
|
||||||
}
|
}
|
||||||
|
|
||||||
nameLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
nameLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
||||||
|
onDemandLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
||||||
|
|
||||||
let nameLabelBottomConstraint =
|
let nameLabelBottomConstraint =
|
||||||
contentView.layoutMarginsGuide.bottomAnchor.constraint(equalToSystemSpacingBelow: nameLabel.bottomAnchor, multiplier: 1)
|
contentView.layoutMarginsGuide.bottomAnchor.constraint(equalToSystemSpacingBelow: nameLabel.bottomAnchor, multiplier: 1)
|
||||||
nameLabelBottomConstraint.priority = .defaultLow
|
nameLabelBottomConstraint.priority = .defaultLow
|
||||||
self.nameLabelBottomConstraint = nameLabelBottomConstraint
|
|
||||||
|
|
||||||
subTitleLabelBottomConstraint =
|
|
||||||
contentView.layoutMarginsGuide.bottomAnchor.constraint(equalToSystemSpacingBelow: subTitleLabel.bottomAnchor, multiplier: 1)
|
|
||||||
subTitleLabelBottomConstraint?.priority = .defaultLow
|
|
||||||
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
statusSwitch.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
|
statusSwitch.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
|
||||||
statusSwitch.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor),
|
statusSwitch.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor),
|
||||||
statusSwitch.leadingAnchor.constraint(equalToSystemSpacingAfter: busyIndicator.trailingAnchor, multiplier: 1),
|
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.topAnchor.constraint(equalToSystemSpacingBelow: contentView.layoutMarginsGuide.topAnchor, multiplier: 1),
|
||||||
nameLabel.leadingAnchor.constraint(equalToSystemSpacingAfter: contentView.layoutMarginsGuide.leadingAnchor, multiplier: 1),
|
nameLabel.leadingAnchor.constraint(equalToSystemSpacingAfter: contentView.layoutMarginsGuide.leadingAnchor, multiplier: 1),
|
||||||
nameLabel.trailingAnchor.constraint(lessThanOrEqualTo: statusSwitch.leadingAnchor),
|
nameLabel.trailingAnchor.constraint(lessThanOrEqualTo: statusSwitch.leadingAnchor),
|
||||||
nameLabelBottomConstraint,
|
nameLabelBottomConstraint,
|
||||||
|
|
||||||
subTitleLabel.topAnchor.constraint(equalToSystemSpacingBelow: nameLabel.bottomAnchor, multiplier: 0.25),
|
onDemandLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
|
||||||
subTitleLabel.leadingAnchor.constraint(equalToSystemSpacingAfter: contentView.layoutMarginsGuide.leadingAnchor, multiplier: 1),
|
onDemandLabel.leadingAnchor.constraint(equalToSystemSpacingAfter: nameLabel.trailingAnchor, multiplier: 1),
|
||||||
subTitleLabel.trailingAnchor.constraint(lessThanOrEqualTo: statusSwitch.leadingAnchor),
|
|
||||||
|
|
||||||
busyIndicator.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
|
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)
|
statusSwitch.addTarget(self, action: #selector(switchToggled), for: .valueChanged)
|
||||||
|
@ -128,20 +126,6 @@ class TunnelListCell: UITableViewCell {
|
||||||
onSwitchToggled?(statusSwitch.isOn)
|
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) {
|
private func update(from tunnel: TunnelContainer?, animated: Bool) {
|
||||||
guard let tunnel = tunnel else {
|
guard let tunnel = tunnel else {
|
||||||
reset(animated: animated)
|
reset(animated: animated)
|
||||||
|
@ -161,27 +145,23 @@ class TunnelListCell: UITableViewCell {
|
||||||
|
|
||||||
statusSwitch.isUserInteractionEnabled = (status == .inactive || status == .active)
|
statusSwitch.isUserInteractionEnabled = (status == .inactive || status == .active)
|
||||||
|
|
||||||
if tunnel.isActivateOnDemandEnabled {
|
|
||||||
setSubTitleText(tr("tunnelsListOnDemandActiveCellSubTitle"))
|
|
||||||
} else {
|
|
||||||
setSubTitleText(nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
if tunnel.hasOnDemandRules {
|
if tunnel.hasOnDemandRules {
|
||||||
|
onDemandLabel.text = isOnDemandEngaged ? tr("tunnelListCaptionOnDemand") : ""
|
||||||
|
busyIndicator.stopAnimating()
|
||||||
statusSwitch.isUserInteractionEnabled = true
|
statusSwitch.isUserInteractionEnabled = true
|
||||||
} else {
|
} else {
|
||||||
statusSwitch.isUserInteractionEnabled = (status == .inactive || status == .active)
|
onDemandLabel.text = ""
|
||||||
}
|
|
||||||
|
|
||||||
if status == .inactive || status == .active {
|
if status == .inactive || status == .active {
|
||||||
busyIndicator.stopAnimating()
|
busyIndicator.stopAnimating()
|
||||||
} else {
|
} else {
|
||||||
busyIndicator.startAnimating()
|
busyIndicator.startAnimating()
|
||||||
}
|
}
|
||||||
|
statusSwitch.isUserInteractionEnabled = (status == .inactive || status == .active)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func reset(animated: Bool) {
|
private func reset(animated: Bool) {
|
||||||
setSubTitleText(nil)
|
|
||||||
statusSwitch.thumbTintColor = nil
|
statusSwitch.thumbTintColor = nil
|
||||||
statusSwitch.setOn(false, animated: animated)
|
statusSwitch.setOn(false, animated: animated)
|
||||||
statusSwitch.isUserInteractionEnabled = false
|
statusSwitch.isUserInteractionEnabled = false
|
||||||
|
|
Loading…
Reference in New Issue