Skip to content

Commit

Permalink
Complete (?) info popup in meal view
Browse files Browse the repository at this point in the history
  • Loading branch information
dsnallfot committed Jun 3, 2024
1 parent 599031e commit fc0b2d2
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 16 deletions.
6 changes: 3 additions & 3 deletions LoopFollow/Application/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@
<color key="tintColor" systemColor="labelColor"/>
<imageReference key="image" image="exclamationmark.triangle" catalog="system" symbolScale="medium" renderingMode="hierarchical">
<hierarchicalColors>
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color systemColor="labelColor"/>
<color systemColor="systemRedColor"/>
<color systemColor="systemRedColor"/>
</hierarchicalColors>
Expand Down Expand Up @@ -1515,7 +1515,7 @@
<color key="tintColor" systemColor="labelColor"/>
<imageReference key="image" image="exclamationmark.triangle" catalog="system" symbolScale="medium" renderingMode="hierarchical">
<hierarchicalColors>
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color systemColor="labelColor"/>
<color systemColor="systemRedColor"/>
<color systemColor="systemRedColor"/>
</hierarchicalColors>
Expand Down Expand Up @@ -1887,7 +1887,7 @@
<color key="tintColor" systemColor="labelColor"/>
<imageReference key="image" image="exclamationmark.triangle" catalog="system" symbolScale="medium" renderingMode="hierarchical">
<hierarchicalColors>
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color systemColor="labelColor"/>
<color systemColor="systemRedColor"/>
<color systemColor="systemRedColor"/>
</hierarchicalColors>
Expand Down
15 changes: 13 additions & 2 deletions LoopFollow/Controllers/Nightscout/BGData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import Foundation
import UIKit

var sharedDeltaBG: Int = 0
var sharedLatestBG: String = ""
var sharedLatestDirection: String = ""
var sharedLatestDelta: String = ""

extension MainViewController {
// Dex Share Web Call
Expand Down Expand Up @@ -233,7 +235,6 @@ extension MainViewController {
let latestBG = entries[latestEntryIndex].sgv
let priorBG = entries[latestEntryIndex - 1].sgv
let deltaBG = latestBG - priorBG
sharedDeltaBG = deltaBG
let lastBGTime = entries[latestEntryIndex].date

let deltaTime = (TimeInterval(Date().timeIntervalSince1970) - lastBGTime) / 60
Expand All @@ -250,27 +251,37 @@ extension MainViewController {

// Set BGText with the latest BG value
self.BGText.text = bgUnits.toDisplayUnits(String(latestBG)).replacingOccurrences(of: ",", with: ".")
//Daniel: Added for visualization in remote meal info popup
sharedLatestBG = bgUnits.toDisplayUnits(String(latestBG)).replacingOccurrences(of: ",", with: ".")
snoozerBG = bgUnits.toDisplayUnits(String(latestBG)).replacingOccurrences(of: ",", with: ".")
self.setBGTextColor()

// Direction handling
if let directionBG = entries[latestEntryIndex].direction {
self.DirectionText.text = self.bgDirectionGraphic(directionBG)
//Daniel: Added for visualization in remote meal info popup
sharedLatestDirection = self.bgDirectionGraphic(directionBG)
snoozerDirection = self.bgDirectionGraphic(directionBG)
self.latestDirectionString = self.bgDirectionGraphic(directionBG)
} else {
self.DirectionText.text = ""
//Daniel: Added for visualization in remote meal info popup
sharedLatestDirection = ""
snoozerDirection = ""
self.latestDirectionString = ""
}

// Delta handling
if deltaBG < 0 {
self.DeltaText.text = bgUnits.toDisplayUnits(String(deltaBG)).replacingOccurrences(of: ",", with: ".")
//Daniel: Added for visualization in remote meal info popup
sharedLatestDelta = bgUnits.toDisplayUnits(String(deltaBG)).replacingOccurrences(of: ",", with: ".")
snoozerDelta = bgUnits.toDisplayUnits(String(deltaBG)).replacingOccurrences(of: ",", with: ".")
self.latestDeltaString = String(deltaBG).replacingOccurrences(of: ",", with: ".")
} else {
self.DeltaText.text = "+" + bgUnits.toDisplayUnits(String(deltaBG)).replacingOccurrences(of: ",", with: ".")
//Daniel: Added for visualization in remote meal info popup
sharedLatestDelta = "+" + bgUnits.toDisplayUnits(String(deltaBG)).replacingOccurrences(of: ",", with: ".")
snoozerDelta = "+" + bgUnits.toDisplayUnits(String(deltaBG)).replacingOccurrences(of: ",", with: ".")
self.latestDeltaString = "+" + String(deltaBG).replacingOccurrences(of: ",", with: ".")
}
Expand Down
12 changes: 12 additions & 0 deletions LoopFollow/Controllers/Nightscout/DeviceStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var sharedLatestISF: String = ""
var sharedLatestSens: String = ""
var sharedLatestCarbReq: String = ""
var sharedLatestInsulinReq: String = ""
var sharedLatestMinMax: String = ""
var sharedLatestEvBG: String = ""
var sharedMinGuardBG: Double = 0.0
//var sharedInsulinReq: Double = 0.0
var sharedLastSMBUnits: Double = 0.0
Expand Down Expand Up @@ -519,6 +521,10 @@ extension MainViewController {

let eventualBGStringValue = String(describing: eventualBGValue)
let formattedBGString = bgUnits.toDisplayUnits(eventualBGStringValue).replacingOccurrences(of: ",", with: ".")
//Daniel: Added for visualization in remote meal info popup
latestEvBG = formattedBGString + " mmol/L"
sharedLatestEvBG = latestEvBG


if eventualBGFloatValue >= UserDefaultsRepository.highLine.value {
PredictionLabel.text = " Prognos ⇢ \(formattedBGString)"
Expand All @@ -543,8 +549,14 @@ extension MainViewController {
let formattedPredMax = bgUnits.toDisplayUnits(String(predMax)).replacingOccurrences(of: ",", with: ".")
tableData[9].value = "\(formattedPredMin)-\(formattedPredMax) mmol/L"
//updatePredictionGraph(color: predictioncolor)
//Daniel: Added for visualization in remote meal info popup
latestMinMax = "\(formattedPredMin)-\(formattedPredMax) mmol/L"
sharedLatestMinMax = latestMinMax
} else {
tableData[9].value = "N/A"
//Daniel: Added for visualization in remote meal info popup
latestMinMax = "N/A"
sharedLatestMinMax = latestMinMax
}
}

Expand Down
2 changes: 2 additions & 0 deletions LoopFollow/ViewControllers/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
var latestCarbReq = ""
var latestSens = ""
var latestISF = ""
var latestMinMax = ""
var latestEvBG = ""
var latestBasal = ""
var basalNow = ""
var latestPumpVolume: Double = 50.0
Expand Down
45 changes: 34 additions & 11 deletions LoopFollow/ViewControllers/MealViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
print("CR: \(formattedCR) g/E")


print("Latest Autosens: \(sharedLatestSens)") // Just print for now. To use as info in bolusrecommendation later on
print("Latest ISF: \(sharedLatestISF)") // Just print for now. To use as info in bolusrecommendation later on
print("Latest IOB: \(sharedLatestIOB)") // Just print for now. To use as info in bolusrecommendation later on
print("Latest COB: \(sharedLatestCOB)") // Just print for now. To use as info in bolusrecommendation later on
print("Latest InsulinReq: \(sharedLatestInsulinReq)") // Just print for now. To use as info in bolusrecommendation later on
print("Latest CarbReq: \(sharedLatestCarbReq)") // Just print for now. To use as info in bolusrecommendation later on
//print("Latest Autosens: \(sharedLatestSens)") // Just print for now. To use as info in bolusrecommendation later on
//print("Latest ISF: \(sharedLatestISF)") // Just print for now. To use as info in bolusrecommendation later on
//print("Latest IOB: \(sharedLatestIOB)") // Just print for now. To use as info in bolusrecommendation later on
//print("Latest COB: \(sharedLatestCOB)") // Just print for now. To use as info in bolusrecommendation later on
//print("Latest InsulinReq: \(sharedLatestInsulinReq)") // Just print for now. To use as info in bolusrecommendation later on
//print("Latest CarbReq: \(sharedLatestCarbReq)") // Just print for now. To use as info in bolusrecommendation later on
//print("Delta: \(Double(sharedDeltaBG) * 0.0555) mmol/L") // Just print for now. To use as info in bolusrecommendation later on

print("BG: \(sharedLatestBG) mmol/L")// Just print for now. To use as info in bolusrecommendation later on
print("BG: \(sharedLatestDirection)")// Just print for now. To use as info in bolusrecommendation later on
print("BG: \(sharedLatestDelta) mmol/L")// Just print for now. To use as info in bolusrecommendation later on


//MinGuardBG & Low Threshold
Expand Down Expand Up @@ -190,7 +194,7 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
stackView.axis = .vertical
stackView.alignment = .fill
stackView.distribution = .equalSpacing
stackView.spacing = 10
stackView.spacing = 2
stackView.translatesAutoresizingMaskIntoConstraints = false
popupView.addSubview(stackView)

Expand All @@ -203,26 +207,31 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
])

// Daniel: Add metrics to the popup
let metrics = ["Autosens", "ISF", "IOB", "COB", "Behov insulin", "Behov kolhydrater"]
let metrics = ["BG", "Autosens", "ISF", "IOB", "COB", "Behov insulin", "Behov kolhydrater", "Min-Max BG", "Prognos BG"]
let latestBGString = (sharedLatestBG + " " + sharedLatestDirection + " (" + sharedLatestDelta + ")")
let values = [
latestBGString,
sharedLatestSens,
sharedLatestISF,
sharedLatestIOB,
sharedLatestCOB,
sharedLatestInsulinReq,
sharedLatestCarbReq
sharedLatestCarbReq,
sharedLatestMinMax,
sharedLatestEvBG
]

for (index, metric) in metrics.enumerated() {
let rowStackView = UIStackView()
rowStackView.axis = .horizontal
rowStackView.alignment = .center
rowStackView.distribution = .fill
rowStackView.spacing = 10
rowStackView.spacing = 2

let label = UILabel()
label.text = metric
label.textAlignment = .left
label.font = UIFont.systemFont(ofSize: 14) // Set font size to 14

let spacer = UIView()
spacer.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -231,15 +240,27 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
let valueLabel = UILabel()
valueLabel.text = values[index]
valueLabel.textAlignment = .right
valueLabel.font = UIFont.systemFont(ofSize: 14) // Set font size to 14

rowStackView.addArrangedSubview(label)
rowStackView.addArrangedSubview(spacer)
rowStackView.addArrangedSubview(valueLabel)

stackView.addArrangedSubview(rowStackView)

// Add a divider line between rows, except after the last row
if index < metrics.count - 1 {
let divider = UIView()
divider.backgroundColor = UIColor.darkGray
divider.translatesAutoresizingMaskIntoConstraints = false
stackView.addArrangedSubview(divider)

NSLayoutConstraint.activate([
divider.heightAnchor.constraint(equalToConstant: 1)
])
}
}


// Store the popup view
self.popupView = popupView

Expand All @@ -249,6 +270,8 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
}
}




@objc func dismissPopupView() {
popupView?.removeFromSuperview()
Expand Down

0 comments on commit fc0b2d2

Please sign in to comment.