Skip to content

Commit

Permalink
First draft - Info popup in remote meal view
Browse files Browse the repository at this point in the history
  • Loading branch information
dsnallfot committed Jun 3, 2024
1 parent d0e9dae commit 0fd6882
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 8 deletions.
45 changes: 37 additions & 8 deletions LoopFollow/Application/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="49e-Tb-3d3">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="49e-Tb-3d3">
<device id="retina5_9" orientation="portrait" appearance="dark"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<capability name="Image references" minToolsVersion="12.0"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
Expand Down Expand Up @@ -1069,7 +1069,7 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<datePicker contentMode="scaleToFill" contentHorizontalAlignment="trailing" contentVerticalAlignment="center" datePickerMode="dateAndTime" minuteInterval="1" translatesAutoresizingMaskIntoConstraints="NO" id="7FO-85-4bA">
<datePicker contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="trailing" contentVerticalAlignment="center" datePickerMode="dateAndTime" minuteInterval="1" translatesAutoresizingMaskIntoConstraints="NO" id="7FO-85-4bA">
<rect key="frame" x="120" y="0.0" width="199" height="40.333333333333336"/>
</datePicker>
</subviews>
Expand Down Expand Up @@ -1125,11 +1125,38 @@
</textField>
</subviews>
</stackView>
<stackView opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="CDP-F4-WHL" userLabel="Min BG stack">
<rect key="frame" x="97" y="0.0" width="123" height="34.333333333333336"/>
<stackView opaque="NO" contentMode="scaleToFill" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="nSt-G5-Nz6" userLabel="Info Stack">
<rect key="frame" x="119" y="0.0" width="78.666666666666686" height="34.333333333333336"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" translatesAutoresizingMaskIntoConstraints="NO" id="HZ8-j6-oni">
<rect key="frame" x="0.0" y="0.99999999999999645" width="19.666666666666668" height="33"/>
<color key="tintColor" systemColor="labelColor"/>
<imageReference key="image" image="info.circle" catalog="system" symbolScale="medium" renderingMode="hierarchical">
<hierarchicalColors>
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color name="Insulin"/>
<color name="Insulin"/>
</hierarchicalColors>
</imageReference>
</imageView>
<textField opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="247" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="Info" textAlignment="natural" adjustsFontSizeToFit="NO" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="cZy-p0-ZOc">
<rect key="frame" x="27.666666666666657" y="0.0" width="51" height="34.333333333333336"/>
<accessibility key="accessibilityConfiguration">
<accessibilityTraits key="traits" notEnabled="YES"/>
</accessibility>
<constraints>
<constraint firstAttribute="width" constant="51" id="GLG-EZ-cC7"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
</stackView>
<stackView hidden="YES" opaque="NO" contentMode="scaleToFill" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="CDP-F4-WHL" userLabel="Min BG stack">
<rect key="frame" x="201.66666666666666" y="0.0" width="101.99999999999997" height="34.333333333333336"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" translatesAutoresizingMaskIntoConstraints="NO" id="aE4-eh-QsG">
<rect key="frame" x="0.0" y="1.3333333333333321" width="21" height="31.999999999999996"/>
<rect key="frame" x="0.0" y="1.3333333333333321" width="0.0" height="31.999999999999996"/>
<color key="tintColor" systemColor="labelColor"/>
<imageReference key="image" image="exclamationmark.triangle" catalog="system" symbolScale="medium" renderingMode="hierarchical">
<hierarchicalColors>
Expand All @@ -1140,7 +1167,7 @@
</imageReference>
</imageView>
<textField opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="247" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="Min BG:" textAlignment="natural" adjustsFontSizeToFit="NO" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="ImY-AS-MmW">
<rect key="frame" x="29" y="0.0" width="51" height="34.333333333333336"/>
<rect key="frame" x="8" y="0.0" width="51" height="34.333333333333336"/>
<accessibility key="accessibilityConfiguration">
<accessibilityTraits key="traits" notEnabled="YES"/>
</accessibility>
Expand All @@ -1151,7 +1178,7 @@
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="--" adjustsFontSizeToFit="NO" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="hgY-IM-3vx">
<rect key="frame" x="88" y="0.0" width="35" height="34.333333333333336"/>
<rect key="frame" x="67.000000000000028" y="0.0" width="35" height="34.333333333333336"/>
<accessibility key="accessibilityConfiguration">
<accessibilityTraits key="traits" notEnabled="YES"/>
</accessibility>
Expand Down Expand Up @@ -1337,6 +1364,7 @@
<outlet property="fatEntryField" destination="ic7-Xb-WJk" id="1SU-6r-qtW"/>
<outlet property="fatGrams" destination="ic7-Xb-WJk" id="pYE-nL-A3C"/>
<outlet property="fatLabel" destination="iun-NK-l8K" id="zwa-zC-vox"/>
<outlet property="infoStack" destination="nSt-G5-Nz6" id="gUD-LW-v3g"/>
<outlet property="mealDateTime" destination="7FO-85-4bA" id="CxN-2I-3NI"/>
<outlet property="mealNotes" destination="nEW-4g-bv5" id="0sT-1i-gc6"/>
<outlet property="mealNotesLabel" destination="RDn-3Y-aqP" id="Oy1-1w-S1g"/>
Expand Down Expand Up @@ -1972,6 +2000,7 @@
<image name="gearshape" catalog="system" width="128" height="123"/>
<image name="gearshape.fill" catalog="system" width="128" height="123"/>
<image name="house" catalog="system" width="128" height="104"/>
<image name="info.circle" catalog="system" width="128" height="123"/>
<image name="list.bullet.clipboard" catalog="system" width="98" height="128"/>
<image name="person.fill" catalog="system" width="128" height="120"/>
<image name="plus.app" catalog="system" width="128" height="114"/>
Expand Down
104 changes: 104 additions & 0 deletions LoopFollow/ViewControllers/MealViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
@IBOutlet weak var minBGStack: UIStackView!
@IBOutlet weak var bolusStack: UIStackView!
@IBOutlet weak var plusSign: UIImageView!
@IBOutlet weak var infoStack: UIStackView!

var CR: Decimal = 0.0
var minGuardBG: Decimal = 0.0
Expand All @@ -51,6 +52,8 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
var isButtonDisabled = false // Property to track if the button is currently disabled
var isBolusEntryFieldPopulated = false

var popupView: UIView?

override func viewDidLoad() {
super.viewDidLoad()
if UserDefaultsRepository.forceDarkMode.value {
Expand All @@ -73,6 +76,14 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
// Add tap gesture recognizers to labels
addGestureRecognizers()

// Add tap gesture recognizer to minBGStack
let minBGStackTap = UITapGestureRecognizer(target: self, action: #selector(minBGStackTapped))
minBGStack.addGestureRecognizer(minBGStackTap)

// Add tap gesture recognizer to infoStack
let infoStackTap = UITapGestureRecognizer(target: self, action: #selector(minBGStackTapped))
infoStack.addGestureRecognizer(infoStackTap)

//Bolus calculation preperations

//Carb ratio
Expand Down Expand Up @@ -117,9 +128,11 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
if minGuardBG < lowThreshold && minGuardBG != 0 {
// Show Min BG stack
minBGStack.isHidden = false
infoStack.isHidden = true
} else {
// Hide Min BG stack
minBGStack.isHidden = true
infoStack.isHidden = false
}

// Add tap gesture recognizer to bolusStack
Expand All @@ -137,6 +150,97 @@ class MealViewController: UIViewController, UITextFieldDelegate, TwilioRequestab
}
}

@objc func minBGStackTapped() {
togglePopupView()
}

func togglePopupView() {
if popupView == nil {
showPopupView()
} else {
dismissPopupView()
}
}

func showPopupView() {
if popupView == nil {
// Create a new UIView for the popup
let popupView = UIView()
popupView.backgroundColor = UIColor.secondarySystemBackground.withAlphaComponent(1.0)
popupView.layer.cornerRadius = 10
popupView.translatesAutoresizingMaskIntoConstraints = false

// Add the popup view to the main view
view.addSubview(popupView)

// Set up constraints for the popup view
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)
])

// Add content to the popup view
let stackView = UIStackView()
stackView.axis = .vertical
stackView.alignment = .fill
stackView.distribution = .equalSpacing
stackView.spacing = 10
stackView.translatesAutoresizingMaskIntoConstraints = false
popupView.addSubview(stackView)

// Add stack view constraints
NSLayoutConstraint.activate([
stackView.leadingAnchor.constraint(equalTo: popupView.leadingAnchor, constant: 20),
stackView.trailingAnchor.constraint(equalTo: popupView.trailingAnchor, constant: -20),
stackView.topAnchor.constraint(equalTo: popupView.topAnchor, constant: 20),
stackView.bottomAnchor.constraint(equalTo: popupView.bottomAnchor, constant: -20)
])

// Add mock-up rows to the stack view
let metrics = ["Metric first", "Metric second", "Metric third", "Metric fourth", "Metric fifth"]
for (index, metric) in metrics.enumerated() {
let rowStackView = UIStackView()
rowStackView.axis = .horizontal
rowStackView.alignment = .center
rowStackView.distribution = .fill
rowStackView.spacing = 10

let label = UILabel()
label.text = metric
label.textAlignment = .left

let spacer = UIView()
spacer.translatesAutoresizingMaskIntoConstraints = false
spacer.widthAnchor.constraint(equalToConstant: 20).isActive = true

let valueLabel = UILabel()
valueLabel.text = String(format: "%.2f", Double(index + 1) * 1.1) // Example decimal value
valueLabel.textAlignment = .right

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

stackView.addArrangedSubview(rowStackView)
}

// Store the popup view
self.popupView = popupView

// 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
}

func setupDatePickerLimits() {
let now = Date()
let oneDayInterval: TimeInterval = 23 * 60 * 60 + 59 * 60
Expand Down

0 comments on commit 0fd6882

Please sign in to comment.