From e04f0da90ff97dbf6d5892447fc4cf0ef83de286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sn=C3=A4llfot?= <72826201+dsnallfot@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:50:25 +0200 Subject: [PATCH] Ivar dev (#92) * fix toggles for dyn cr on/off in info table and dyn cr on/off in bolus calc * offset all highlights (tooltip) center -80p on y-axis * align highlights (tooltips) at bottom of chart * Animated info popup remote meal - Move use dyn cr toggle from advanced settings to info table settings * curtain down/up popup animation --- .../Controllers/Nightscout/DeviceStatus.swift | 15 +++++-- .../AdvancedSettingsViewController.swift | 1 + .../InfoDisplaySettingsViewController.swift | 9 +++++ .../ViewControllers/MealViewController.swift | 39 +++++++++++++------ .../RemoteSettingsViewController.swift | 8 ++++ LoopFollow/repository/UserDefaults.swift | 2 + .../Charts/Renderers/LineChartRenderer.swift | 34 ++++++++-------- 7 files changed, 75 insertions(+), 33 deletions(-) diff --git a/LoopFollow/Controllers/Nightscout/DeviceStatus.swift b/LoopFollow/Controllers/Nightscout/DeviceStatus.swift index d5dc4832..72f0410d 100644 --- a/LoopFollow/Controllers/Nightscout/DeviceStatus.swift +++ b/LoopFollow/Controllers/Nightscout/DeviceStatus.swift @@ -330,12 +330,21 @@ extension MainViewController { sharedRawCRValue = CR.description let sharedProfileCRValue = round((Double(sharedSensValue) * (Double(sharedRawCRValue) ?? 0.0)) * 10) / 10.0 let formattedCR = String(format:"%.1f", sharedProfileCRValue) - let CR = formattedCR + //let CR = formattedCR //let CRString = formattedCR //Auggie !! Only applyies if using dynamic CR let CRString = "\(sharedProfileCRValue) ⇢ \(sharedRawCRValue) g/E" - tableData[15].value = CRString - sharedCRValue = String(format:"%.1f", sharedProfileCRValue) + if UserDefaultsRepository.useDynCr.value { + tableData[15].value = CRString + if UserDefaultsRepository.useDynCrInBolusCalc.value { + sharedCRValue = sharedRawCRValue + } else { + sharedCRValue = formattedCR + } + } else { + tableData[15].value = "\(sharedRawCRValue) g/E" + sharedCRValue = sharedRawCRValue + } //Daniel prev version /*tableData[15].value = String(format:"%.1f", CR) + " g/E" diff --git a/LoopFollow/ViewControllers/AdvancedSettingsViewController.swift b/LoopFollow/ViewControllers/AdvancedSettingsViewController.swift index f646159c..86ba5ec4 100644 --- a/LoopFollow/ViewControllers/AdvancedSettingsViewController.swift +++ b/LoopFollow/ViewControllers/AdvancedSettingsViewController.swift @@ -83,6 +83,7 @@ class AdvancedSettingsViewController: FormViewController { guard let value = row.value else { return } UserDefaultsRepository.showDetails.value = value } + <<< StepperRow("bgUpdateDelay") { row in row.title = "BG Update Delay (Sec)" row.cell.stepper.stepValue = 1 diff --git a/LoopFollow/ViewControllers/InfoDisplaySettingsViewController.swift b/LoopFollow/ViewControllers/InfoDisplaySettingsViewController.swift index abb5488d..5552361b 100644 --- a/LoopFollow/ViewControllers/InfoDisplaySettingsViewController.swift +++ b/LoopFollow/ViewControllers/InfoDisplaySettingsViewController.swift @@ -37,6 +37,14 @@ class InfoDisplaySettingsViewController: FormViewController { UserDefaultsRepository.hideInfoTable.value = value } + <<< SwitchRow("useDynCr"){ row in + row.title = "Use Dynamic CR" + row.value = UserDefaultsRepository.useDynCr.value + }.onChange { [weak self] row in + guard let value = row.value else { return } + UserDefaultsRepository.useDynCr.value = value + } + +++ MultivaluedSection(multivaluedOptions: .Reorder, header: "Information Display Settings", footer: "Välj och sortera ordning på önskad information") { // TODO: add the other display values @@ -72,6 +80,7 @@ class InfoDisplaySettingsViewController: FormViewController { } } + +++ ButtonRow() { $0.title = "DONE" }.onCellSelection { (row, arg) in diff --git a/LoopFollow/ViewControllers/MealViewController.swift b/LoopFollow/ViewControllers/MealViewController.swift index 2ce001e0..727599aa 100644 --- a/LoopFollow/ViewControllers/MealViewController.swift +++ b/LoopFollow/ViewControllers/MealViewController.swift @@ -182,12 +182,13 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab // Add the popup view to the main view view.addSubview(popupView) - // Set up constraints for the popup view + // Set up initial constraints for the popup view + let initialTopConstraint = popupView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: -255) NSLayoutConstraint.activate([ popupView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 10), popupView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -10), - popupView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 10), - popupView.heightAnchor.constraint(equalToConstant: 250) + initialTopConstraint, + popupView.heightAnchor.constraint(equalToConstant: 255) ]) // Add content to the popup view @@ -207,7 +208,7 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab stackView.bottomAnchor.constraint(equalTo: popupView.bottomAnchor, constant: -20) ]) - // Daniel: Add metrics to the popup + // Add metrics to the popup let metrics = ["BG", "Autosens", "ISF", "IOB", "COB", "Behov insulin", "Behov kolhydrater", "Min-Max BG", "Prognos BG"] let latestBGString = (sharedLatestBG + " " + sharedLatestDirection + " (" + sharedLatestDelta + ")") let values = [ @@ -232,7 +233,7 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab let label = UILabel() label.text = metric label.textAlignment = .left - label.font = UIFont.systemFont(ofSize: 14) // Set font size to 14 + label.font = UIFont.systemFont(ofSize: 15) // Set font size to 14 let spacer = UIView() spacer.translatesAutoresizingMaskIntoConstraints = false @@ -241,7 +242,7 @@ 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 + valueLabel.font = UIFont.systemFont(ofSize: 15) // Set font size to 14 rowStackView.addArrangedSubview(label) rowStackView.addArrangedSubview(spacer) @@ -265,19 +266,33 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab // Store the popup view self.popupView = popupView + // Animate the popup view + view.layoutIfNeeded() + UIView.animate(withDuration: 0.3, animations: { + initialTopConstraint.constant = 10 + self.view.layoutIfNeeded() + }) + // Add tap gesture recognizer to dismiss the popup view let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissPopupView)) view.addGestureRecognizer(tapGesture) } } - - - @objc func dismissPopupView() { - popupView?.removeFromSuperview() - popupView = nil - } + @objc func dismissPopupView() { + if let popupView = self.popupView { + // Animate the popup view to move up + UIView.animate(withDuration: 0.3, animations: { + popupView.frame.origin.y = -255 + self.view.layoutIfNeeded() + }) { _ in + // Remove the popup view from the superview + popupView.removeFromSuperview() + self.popupView = nil + } + } + } func setupDatePickerLimits() { let now = Date() diff --git a/LoopFollow/ViewControllers/RemoteSettingsViewController.swift b/LoopFollow/ViewControllers/RemoteSettingsViewController.swift index 733f6d13..3f9bda04 100644 --- a/LoopFollow/ViewControllers/RemoteSettingsViewController.swift +++ b/LoopFollow/ViewControllers/RemoteSettingsViewController.swift @@ -304,6 +304,14 @@ class RemoteSettingsViewController: FormViewController { self?.reloadForm() } + <<< SwitchRow("useDynCrInBolusCalc"){ row in + row.title = "Use Dyn CR in Bolus Calc" + row.value = UserDefaultsRepository.useDynCrInBolusCalc.value + }.onChange { [weak self] row in + guard let value = row.value else { return } + UserDefaultsRepository.useDynCrInBolusCalc.value = value + } + +++ Section(header: "Guardrails and security", footer: "") <<< StepperRow("maxCarbs") { row in diff --git a/LoopFollow/repository/UserDefaults.swift b/LoopFollow/repository/UserDefaults.swift index cc028017..9a924160 100644 --- a/LoopFollow/repository/UserDefaults.swift +++ b/LoopFollow/repository/UserDefaults.swift @@ -118,6 +118,7 @@ class UserDefaultsRepository { static let bgUpdateDelay = UserDefaultsValue(key: "bgUpdateDelay", default: 10) static let downloadDays = UserDefaultsValue(key: "downloadDays", default: 1) static let showDetails = UserDefaultsValue(key: "showDetails", default: true) + static let useDynCr = UserDefaultsValue(key: "useDynCr", default: false) // Watch Calendar Settings @@ -481,6 +482,7 @@ class UserDefaultsRepository { static let hideRemoteBolus = UserDefaultsValue(key: "hideRemoteBolus", default: true) static let hideRemoteCustomActions = UserDefaultsValue(key: "hideCustomActions", default: true) static let hideBolusCalc = UserDefaultsValue(key: "hideBolusCalc", default: true) + static let useDynCrInBolusCalc = UserDefaultsValue(key: "useDynCrInBolusCalc", default: false) //Remote guardrails static let maxCarbs = UserDefaultsValue(key: "maxCarbs", default: 30) diff --git a/Pods/Charts/Source/Charts/Renderers/LineChartRenderer.swift b/Pods/Charts/Source/Charts/Renderers/LineChartRenderer.swift index 0598bf6e..20e58347 100644 --- a/Pods/Charts/Source/Charts/Renderers/LineChartRenderer.swift +++ b/Pods/Charts/Source/Charts/Renderers/LineChartRenderer.swift @@ -764,8 +764,7 @@ open class LineChartRenderer: LineRadarRenderer accessibilityPostLayoutChangedNotification() } - open override func drawHighlighted(context: CGContext, indices: [Highlight]) - { + open override func drawHighlighted(context: CGContext, indices: [Highlight]) { guard let dataProvider = dataProvider, let lineData = dataProvider.lineData @@ -773,47 +772,42 @@ open class LineChartRenderer: LineRadarRenderer let chartXMax = dataProvider.chartXMax + // Calculate the center y-coordinate of the chart + let centerY = viewPortHandler.contentCenter.y + context.saveGState() - for high in indices - { + for high in indices { guard let set = lineData[high.dataSetIndex] as? LineChartDataSetProtocol, set.isHighlightEnabled else { continue } guard let e = set.entryForXValue(high.x, closestToY: high.y) else { continue } - if !isInBoundsX(entry: e, dataSet: set) - { + if !isInBoundsX(entry: e, dataSet: set) { continue } context.setStrokeColor(set.highlightColor.cgColor) context.setLineWidth(set.highlightLineWidth) - if set.highlightLineDashLengths != nil - { + if set.highlightLineDashLengths != nil { context.setLineDash(phase: set.highlightLineDashPhase, lengths: set.highlightLineDashLengths!) - } - else - { + } else { context.setLineDash(phase: 0.0, lengths: []) } let x = e.x // get the x-position let y = e.y * Double(animator.phaseY) - if x > chartXMax * animator.phaseX - { + if x > chartXMax * animator.phaseX { continue } let trans = dataProvider.getTransformer(forAxis: set.axisDependency) - let pt = trans.pixelForValues(x: x, y: y) - /*var pt = trans.pixelForValues(x: x, y: y) - - // Offset the highlighted point 20 points down - pt.y += 20*/ + var pt = trans.pixelForValues(x: x, y: y) + // Adjust the y-coordinate to the center of the chart and offset 50 points down + pt.y = centerY + 90 high.setDraw(pt: pt) @@ -825,6 +819,10 @@ open class LineChartRenderer: LineRadarRenderer } + + + + func drawGradientLine(context: CGContext, dataSet: LineChartDataSetProtocol, spline: CGPath, matrix: CGAffineTransform) { guard let gradientPositions = dataSet.gradientPositions else