forked from LoopKit/Loop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasalRateHUDView.swift
More file actions
69 lines (53 loc) · 2.16 KB
/
BasalRateHUDView.swift
File metadata and controls
69 lines (53 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// BasalRateHUDView.swift
// Naterade
//
// Created by Nathan Racklyeft on 5/1/16.
// Copyright © 2016 Nathan Racklyeft. All rights reserved.
//
import UIKit
import LoopKitUI
public final class BasalRateHUDView: BaseHUDView {
override public var orderPriority: HUDViewOrderPriority {
return 3
}
@IBOutlet private weak var basalStateView: BasalStateView!
@IBOutlet private weak var basalRateLabel: UILabel! {
didSet {
basalRateLabel?.text = String(format: basalRateFormatString, "–")
basalRateLabel?.textColor = .secondaryLabel
accessibilityValue = LocalizedString("Unknown", comment: "Accessibility value for an unknown value")
}
}
public override func tintColorDidChange() {
super.tintColorDidChange()
}
private lazy var basalRateFormatString = LocalizedString("%@ U", comment: "The format string describing the basal rate.")
public func setNetBasalRate(_ rate: Double, percent: Double, at date: Date) {
let time = timeFormatter.string(from: date)
caption?.text = time
if let rateString = decimalFormatter.string(from: rate) {
basalRateLabel?.text = String(format: basalRateFormatString, rateString)
accessibilityValue = String(format: LocalizedString("%1$@ units per hour at %2$@", comment: "Accessibility format string describing the basal rate. (1: localized basal rate value)(2: last updated time)"), rateString, time)
} else {
basalRateLabel?.text = nil
accessibilityValue = nil
}
basalStateView.netBasalPercent = percent
}
private lazy var decimalFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.minimumFractionDigits = 1
formatter.minimumIntegerDigits = 1
formatter.positiveFormat = "+0.0##"
formatter.negativeFormat = "-0.0##"
return formatter
}()
private lazy var timeFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .none
formatter.timeStyle = .short
return formatter
}()
}