Skip to content

Commit e8abd99

Browse files
committed
Align Not Looping display threshold with the alarm if it is enabled
1 parent b1bec48 commit e8abd99

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

LoopFollow/Controllers/Nightscout/DeviceStatus.swift

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,47 @@ extension MainViewController {
3939
}
4040

4141
func evaluateNotLooping() {
42-
if let statusStackView = LoopStatusLabel.superview as? UIStackView {
43-
if ((TimeInterval(Date().timeIntervalSince1970) - UserDefaultsRepository.alertLastLoopTime.value) / 60) > 15 {
44-
IsNotLooping = true
45-
// Change the distribution to 'fill' to allow manual resizing of arranged subviews
46-
statusStackView.distribution = .fill
47-
48-
// Hide PredictionLabel and expand LoopStatusLabel to fill the entire stack view
49-
PredictionLabel.isHidden = true
50-
LoopStatusLabel.frame = CGRect(x: 0, y: 0, width: statusStackView.frame.width, height: statusStackView.frame.height)
51-
52-
// Update LoopStatusLabel's properties to display Not Looping
53-
LoopStatusLabel.textAlignment = .center
54-
LoopStatusLabel.text = "⚠️ Not Looping!"
55-
LoopStatusLabel.textColor = UIColor.systemYellow
56-
LoopStatusLabel.font = UIFont.boldSystemFont(ofSize: 18)
57-
42+
guard let statusStackView = LoopStatusLabel.superview as? UIStackView else { return }
43+
44+
let now = TimeInterval(Date().timeIntervalSince1970)
45+
let lastLoopTime = UserDefaultsRepository.alertLastLoopTime.value
46+
let isAlarmEnabled = UserDefaultsRepository.alertNotLoopingActive.value
47+
let nonLoopingTimeThreshold: TimeInterval
48+
49+
if isAlarmEnabled {
50+
nonLoopingTimeThreshold = Double(UserDefaultsRepository.alertNotLooping.value * 60)
51+
} else {
52+
nonLoopingTimeThreshold = 15 * 60
53+
}
54+
55+
if IsNightscoutEnabled(), (now - lastLoopTime) >= nonLoopingTimeThreshold, lastLoopTime > 0 {
56+
IsNotLooping = true
57+
statusStackView.distribution = .fill
58+
59+
PredictionLabel.isHidden = true
60+
LoopStatusLabel.frame = CGRect(x: 0, y: 0, width: statusStackView.frame.width, height: statusStackView.frame.height)
61+
62+
LoopStatusLabel.textAlignment = .center
63+
LoopStatusLabel.text = "⚠️ Not Looping!"
64+
LoopStatusLabel.textColor = UIColor.systemYellow
65+
LoopStatusLabel.font = UIFont.boldSystemFont(ofSize: 18)
66+
67+
} else {
68+
IsNotLooping = false
69+
statusStackView.distribution = .fillEqually
70+
PredictionLabel.isHidden = false
71+
72+
LoopStatusLabel.textAlignment = .right
73+
LoopStatusLabel.font = UIFont.systemFont(ofSize: 17)
74+
75+
if UserDefaultsRepository.forceDarkMode.value {
76+
LoopStatusLabel.textColor = UIColor.white
5877
} else {
59-
IsNotLooping = false
60-
// Restore the original distribution and visibility of labels
61-
statusStackView.distribution = .fillEqually
62-
PredictionLabel.isHidden = false
63-
64-
// Reset LoopStatusLabel's properties
65-
LoopStatusLabel.textAlignment = .right
66-
LoopStatusLabel.font = UIFont.systemFont(ofSize: 17)
67-
68-
if UserDefaultsRepository.forceDarkMode.value {
69-
LoopStatusLabel.textColor = UIColor.white
70-
} else {
71-
LoopStatusLabel.textColor = UIColor.black
72-
}
78+
LoopStatusLabel.textColor = UIColor.black
7379
}
7480
}
7581
}
76-
82+
7783
// NS Device Status Response Processor
7884
func updateDeviceStatusDisplay(jsonDeviceStatus: [[String:AnyObject]]) {
7985
infoManager.clearInfoData(types: [.iob, .cob, .override, .battery, .pump, .target, .isf, .carbRatio, .updated, .recBolus, .tdd])

0 commit comments

Comments
 (0)