forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReservoirVolumeHUDView.swift
More file actions
77 lines (60 loc) · 2.23 KB
/
ReservoirVolumeHUDView.swift
File metadata and controls
77 lines (60 loc) · 2.23 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
70
71
72
73
74
75
76
77
//
// ReservoirVolumeHUDView.swift
// Naterade
//
// Created by Nathan Racklyeft on 5/2/16.
// Copyright © 2016 Nathan Racklyeft. All rights reserved.
//
import UIKit
public final class ReservoirVolumeHUDView: LevelHUDView, NibLoadable {
override public var orderPriority: HUDViewOrderPriority {
return 4
}
@IBOutlet private weak var volumeLabel: UILabel!
public class func instantiate() -> ReservoirVolumeHUDView {
return nib().instantiate(withOwner: nil, options: nil)[0] as! ReservoirVolumeHUDView
}
override public func awakeFromNib() {
super.awakeFromNib()
volumeLabel.isHidden = true
}
override public func levelDidChange() {
super.levelDidChange()
switch level {
case .none:
volumeLabel.isHidden = true
case let x? where x > 0.25:
volumeLabel.isHidden = true
case let x? where x > 0.10:
volumeLabel.textColor = tintColor
volumeLabel.isHidden = false
default:
volumeLabel.textColor = tintColor
volumeLabel.isHidden = false
}
}
private lazy var timeFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .none
formatter.timeStyle = .short
return formatter
}()
private lazy var numberFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.maximumFractionDigits = 0
return formatter
}()
public func setReservoirVolume(volume: Double, at date: Date) {
if let units = numberFormatter.string(from: volume) {
volumeLabel.text = String(format: LocalizedString("%@U", comment: "Format string for reservoir volume. (1: The localized volume)"), units)
let time = timeFormatter.string(from: date)
caption?.text = time
accessibilityValue = String(format: LocalizedString("%1$@ units remaining at %2$@", comment: "Accessibility format string for (1: localized volume)(2: time)"), units, time)
}
}
public override func tintColorDidChange() {
super.tintColorDidChange()
volumeLabel.textColor = tintColor
}
}