diff --git a/DronelinkCoreUI/BatteryWidget.swift b/DronelinkCoreUI/BatteryWidget.swift index 4bb997b..03a7460 100644 --- a/DronelinkCoreUI/BatteryWidget.swift +++ b/DronelinkCoreUI/BatteryWidget.swift @@ -38,7 +38,7 @@ public class BatteryWidget: UpdatableWidget { label.font = UIFont.systemFont(ofSize: 16, weight: .bold) view.addSubview(label) label.snp.makeConstraints { [weak self] make in - make.left.equalTo(imageView.snp.right) + make.left.equalTo(imageView.snp.right).offset(5) make.top.equalToSuperview() make.right.equalToSuperview() make.bottom.equalToSuperview() diff --git a/DronelinkCoreUI/DownlinkWidget.swift b/DronelinkCoreUI/DownlinkWidget.swift index ad40d5d..1d24680 100644 --- a/DronelinkCoreUI/DownlinkWidget.swift +++ b/DronelinkCoreUI/DownlinkWidget.swift @@ -11,14 +11,41 @@ import UIKit import DronelinkCore public class DownlinkWidget: SignalWidget { + + public var channel: UInt = 0 + + public var levelLabel: UILabel? + public override func viewDidLoad() { super.viewDidLoad() iconImageView.image = DronelinkUI.loadImage(named: "downLinkIcon")?.withRenderingMode(.alwaysTemplate) iconImageView.tintColor = .white + if let levelLabel = levelLabel { + view.addSubview(levelLabel) + levelLabel.textColor = .white + levelLabel.font = UIFont.systemFont(ofSize: 16, weight: .bold) + levelImageView.isHidden = true + levelLabel.snp.makeConstraints { [weak self] make in + make.left.equalTo(iconImageView.snp.right).offset(5) + make.top.equalToSuperview() + make.width.equalTo(view.snp.height) + make.bottom.equalToSuperview() + } + } } @objc public override func update() { super.update() + + if let levelLabel = levelLabel { + guard let batteryPercent = session?.remoteControllerState(channel: self.channel)?.value.batteryPercent else { + levelLabel.text = "na".localized + return + } + levelLabel.text = Dronelink.shared.format(formatter: "percent", value: batteryPercent) + return + } + updateSignal(signalValue: session?.state?.value.downlinkSignalStrength ?? 0) } } diff --git a/Podfile b/Podfile index 7e2340a..b99ce49 100644 --- a/Podfile +++ b/Podfile @@ -21,4 +21,4 @@ target 'DronelinkCoreUI' do pod 'Agrume', '~> 5.6.10' pod 'IQKeyboardManager', '~> 6.5.6' pod 'MarqueeLabel', '~> 4.0.5' -end \ No newline at end of file +end