Skip to content

Commit bf3c12a

Browse files
authored
Merge pull request #280 from loopandlearn/not-looping
Add UI update for 'Not Looping' status indication
2 parents 09a00af + 6e099df commit bf3c12a

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

LoopFollow/Controllers/Alarms.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ extension MainViewController {
349349
if (UserDefaultsRepository.alertNotLoopingUseLimits.value
350350
&& (
351351
(Float(currentBG) >= UserDefaultsRepository.alertNotLoopingUpperLimit.value
352-
&& Float(currentBG) <= UserDefaultsRepository.alertNotLoopingLowerLimit.value) ||
352+
|| Float(currentBG) <= UserDefaultsRepository.alertNotLoopingLowerLimit.value) ||
353353
// Ignore Limits if BG reading is older than non looping time
354354
(Double(now - currentBGTime) >= Double(UserDefaultsRepository.alertNotLooping.value * 60))
355355
) ||

LoopFollow/Controllers/Nightscout/DeviceStatus.swift

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,43 @@ extension MainViewController {
4646
self.startDeviceStatusTimer(time: 10)
4747
}
4848
}
49+
50+
func evaluateNotLooping(lastLoopTime: TimeInterval) {
51+
if let statusStackView = LoopStatusLabel.superview as? UIStackView {
52+
if ((TimeInterval(Date().timeIntervalSince1970) - lastLoopTime) / 60) > 15 {
53+
IsNotLooping = true
54+
// Change the distribution to 'fill' to allow manual resizing of arranged subviews
55+
statusStackView.distribution = .fill
56+
57+
// Hide PredictionLabel and expand LoopStatusLabel to fill the entire stack view
58+
PredictionLabel.isHidden = true
59+
LoopStatusLabel.frame = CGRect(x: 0, y: 0, width: statusStackView.frame.width, height: statusStackView.frame.height)
60+
61+
// Update LoopStatusLabel's properties to display Not Looping
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+
// Restore the original distribution and visibility of labels
70+
statusStackView.distribution = .fillEqually
71+
PredictionLabel.isHidden = false
72+
73+
// Reset LoopStatusLabel's properties
74+
LoopStatusLabel.textAlignment = .right
75+
LoopStatusLabel.font = UIFont.systemFont(ofSize: 17)
76+
77+
if UserDefaultsRepository.forceDarkMode.value {
78+
LoopStatusLabel.textColor = UIColor.white
79+
} else {
80+
LoopStatusLabel.textColor = UIColor.black
81+
}
82+
}
83+
}
84+
latestLoopTime = lastLoopTime
85+
}
4986

5087
// NS Device Status Response Processor
5188
func updateDeviceStatusDisplay(jsonDeviceStatus: [[String:AnyObject]]) {
@@ -171,12 +208,8 @@ extension MainViewController {
171208
}
172209

173210
}
174-
175-
if ((TimeInterval(Date().timeIntervalSince1970) - lastLoopTime) / 60) > 15 {
176-
LoopStatusLabel.text = ""
177-
latestLoopStatusString = ""
178-
}
179-
latestLoopTime = lastLoopTime
211+
212+
evaluateNotLooping(lastLoopTime: lastLoopTime)
180213
} // end lastLoopTime
181214
} // end lastLoop Record
182215

@@ -305,11 +338,8 @@ extension MainViewController {
305338
}
306339

307340
}
308-
if ((TimeInterval(Date().timeIntervalSince1970) - lastLoopTime) / 60) > 15 {
309-
LoopStatusLabel.text = ""
310-
latestLoopStatusString = ""
311-
}
312-
latestLoopTime = lastLoopTime
341+
342+
evaluateNotLooping(lastLoopTime: lastLoopTime)
313343
}
314344
}
315345

LoopFollow/ViewControllers/AlarmViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ class AlarmViewController: FormViewController {
17851785
UserDefaultsRepository.alertNotLoopingUseLimits.value = value
17861786
}
17871787
<<< StepperRow("alertNotLoopingLowerLimit") { row in
1788-
row.title = "Below BG"
1788+
row.title = "If Below BG"
17891789
row.cell.stepper.stepValue = 1
17901790
row.cell.stepper.minimumValue = 50
17911791
row.cell.stepper.maximumValue = 200
@@ -1800,7 +1800,7 @@ class AlarmViewController: FormViewController {
18001800
UserDefaultsRepository.alertNotLoopingLowerLimit.value = Float(value)
18011801
}
18021802
<<< StepperRow("alertNotLoopingUpperLimit") { row in
1803-
row.title = "Above BG"
1803+
row.title = "If Above BG"
18041804
row.cell.stepper.stepValue = 1
18051805
row.cell.stepper.minimumValue = 100
18061806
row.cell.stepper.maximumValue = 300

LoopFollow/ViewControllers/MainViewController.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
149149
var lastSpeechTime: Date?
150150

151151
var autoScrollPauseUntil: Date? = nil
152+
153+
var IsNotLooping = false
152154

153155
override func viewDidLoad() {
154156
super.viewDidLoad()
@@ -449,7 +451,12 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
449451
}
450452

451453
LoopStatusLabel.isHidden = isHidden
452-
PredictionLabel.isHidden = isHidden
454+
if IsNotLooping {
455+
PredictionLabel.isHidden = true
456+
}
457+
else {
458+
PredictionLabel.isHidden = isHidden
459+
}
453460
infoTable.isHidden = isHidden
454461

455462
if UserDefaultsRepository.hideInfoTable.value {

0 commit comments

Comments
 (0)