Skip to content

Commit

Permalink
Align Not Looping display threshold with the alarm if it is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorkert committed Jan 31, 2025
1 parent b1bec48 commit e8abd99
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions LoopFollow/Controllers/Nightscout/DeviceStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,47 @@ extension MainViewController {
}

func evaluateNotLooping() {
if let statusStackView = LoopStatusLabel.superview as? UIStackView {
if ((TimeInterval(Date().timeIntervalSince1970) - UserDefaultsRepository.alertLastLoopTime.value) / 60) > 15 {
IsNotLooping = true
// Change the distribution to 'fill' to allow manual resizing of arranged subviews
statusStackView.distribution = .fill

// Hide PredictionLabel and expand LoopStatusLabel to fill the entire stack view
PredictionLabel.isHidden = true
LoopStatusLabel.frame = CGRect(x: 0, y: 0, width: statusStackView.frame.width, height: statusStackView.frame.height)

// Update LoopStatusLabel's properties to display Not Looping
LoopStatusLabel.textAlignment = .center
LoopStatusLabel.text = "⚠️ Not Looping!"
LoopStatusLabel.textColor = UIColor.systemYellow
LoopStatusLabel.font = UIFont.boldSystemFont(ofSize: 18)

guard let statusStackView = LoopStatusLabel.superview as? UIStackView else { return }

let now = TimeInterval(Date().timeIntervalSince1970)
let lastLoopTime = UserDefaultsRepository.alertLastLoopTime.value
let isAlarmEnabled = UserDefaultsRepository.alertNotLoopingActive.value
let nonLoopingTimeThreshold: TimeInterval

if isAlarmEnabled {
nonLoopingTimeThreshold = Double(UserDefaultsRepository.alertNotLooping.value * 60)
} else {
nonLoopingTimeThreshold = 15 * 60
}

if IsNightscoutEnabled(), (now - lastLoopTime) >= nonLoopingTimeThreshold, lastLoopTime > 0 {
IsNotLooping = true
statusStackView.distribution = .fill

PredictionLabel.isHidden = true
LoopStatusLabel.frame = CGRect(x: 0, y: 0, width: statusStackView.frame.width, height: statusStackView.frame.height)

LoopStatusLabel.textAlignment = .center
LoopStatusLabel.text = "⚠️ Not Looping!"
LoopStatusLabel.textColor = UIColor.systemYellow
LoopStatusLabel.font = UIFont.boldSystemFont(ofSize: 18)

} else {
IsNotLooping = false
statusStackView.distribution = .fillEqually
PredictionLabel.isHidden = false

LoopStatusLabel.textAlignment = .right
LoopStatusLabel.font = UIFont.systemFont(ofSize: 17)

if UserDefaultsRepository.forceDarkMode.value {
LoopStatusLabel.textColor = UIColor.white
} else {
IsNotLooping = false
// Restore the original distribution and visibility of labels
statusStackView.distribution = .fillEqually
PredictionLabel.isHidden = false

// Reset LoopStatusLabel's properties
LoopStatusLabel.textAlignment = .right
LoopStatusLabel.font = UIFont.systemFont(ofSize: 17)

if UserDefaultsRepository.forceDarkMode.value {
LoopStatusLabel.textColor = UIColor.white
} else {
LoopStatusLabel.textColor = UIColor.black
}
LoopStatusLabel.textColor = UIColor.black
}
}
}

// NS Device Status Response Processor
func updateDeviceStatusDisplay(jsonDeviceStatus: [[String:AnyObject]]) {
infoManager.clearInfoData(types: [.iob, .cob, .override, .battery, .pump, .target, .isf, .carbRatio, .updated, .recBolus, .tdd])
Expand Down

0 comments on commit e8abd99

Please sign in to comment.