Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(widgets): update downlink and battery widgets #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DronelinkCoreUI/BatteryWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
27 changes: 27 additions & 0 deletions DronelinkCoreUI/DownlinkWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ target 'DronelinkCoreUI' do
pod 'Agrume', '~> 5.6.10'
pod 'IQKeyboardManager', '~> 6.5.6'
pod 'MarqueeLabel', '~> 4.0.5'
end
end