Skip to content

Commit

Permalink
Bolus on/off toggle added to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dsnallfot committed Mar 27, 2024
1 parent dd13868 commit 0a502b8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
6 changes: 4 additions & 2 deletions LoopFollow/Application/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,6 @@
</buttonConfiguration>
<connections>
<action selector="bolusButtonPressed:" destination="4ie-sJ-hfo" eventType="touchUpInside" id="bgi-Qm-ZLF"/>
<action selector="remoteBolusButtonPresses:" destination="aie-2F-6fa" eventType="touchUpInside" id="F63-Xn-GVD"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="p4l-1b-Z8k">
Expand Down Expand Up @@ -746,9 +745,11 @@
</view>
<tabBarItem key="tabBarItem" title="Remote" image="appletvremote.gen1" catalog="system" id="Eec-Uu-0Sd"/>
<navigationItem key="navigationItem" id="ce2-Vz-Uuo"/>
<connections>
<outlet property="remoteBolusButton" destination="2Vg-R6-0Rz" id="Nb5-jA-f06"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="RnA-lD-Sot" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
<exit id="aie-2F-6fa" userLabel="Exit" sceneMemberID="exit"/>
</objects>
<point key="canvasLocation" x="-1039.2" y="745.56650246305423"/>
</scene>
Expand Down Expand Up @@ -1138,6 +1139,7 @@
<toolbarItems/>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="bolusRow" destination="1MG-ka-WeC" id="mBu-Yw-aqz"/>
<outlet property="bolusUnits" destination="w60-pI-Fq0" id="fzb-I7-3Q9"/>
<outlet property="carbGrams" destination="4O6-tP-VAz" id="h4d-TM-Wbc"/>
<outlet property="fatGrams" destination="ic7-Xb-WJk" id="pYE-nL-A3C"/>
Expand Down
18 changes: 15 additions & 3 deletions LoopFollow/ViewControllers/MealViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import LocalAuthentication

class MealViewController: UIViewController {

@IBOutlet weak var bolusRow: UIView!
@IBOutlet weak var sendMealButton: UIButton!
@IBOutlet weak var carbGrams: UITextField!
@IBOutlet weak var fatGrams: UITextField!
Expand All @@ -22,8 +23,11 @@ class MealViewController: UIViewController {
super.viewDidLoad()
if UserDefaultsRepository.forceDarkMode.value {
overrideUserInterfaceStyle = .dark

// Do any additional setup after loading the view.
}

// Check the value of hideRemoteBolus and hide the bolusRow accordingly
if UserDefaultsRepository.hideRemoteBolus.value {
hideBolusRow()
}
}

Expand Down Expand Up @@ -307,7 +311,15 @@ class MealViewController: UIViewController {
sendMealButton.setAttributedTitle(attributedTitle, for: .normal)
}


// Function to hide the bolusRow
func hideBolusRow() {
bolusRow.isHidden = true
}

// Function to show the bolusRow
func showBolusRow() {
bolusRow.isHidden = false
}

@IBAction func doneButtonTapped(_ sender: Any) {
dismiss(animated: true, completion: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ class RemoteSettingsViewController: FormViewController {
UserDefaultsRepository.maxBolus.value = Double(value)
}

form +++ Section("Advanced functions")
<<< SwitchRow("hideRemoteBolus") { row in
row.title = "Hide Bolus (app restart needed)"
row.value = UserDefaultsRepository.hideRemoteBolus.value
}.onChange { [weak self] row in
guard let value = row.value else { return }
UserDefaultsRepository.hideRemoteBolus.value = value
}

+++ Section(header: "Preset Settings", footer: "Add the overrides, temp targets and meal presets you would like to be able to choose from in respective views picker. Separate them by comma + blank space. Example: Override 1, Override 2, Override 3")

Expand All @@ -209,7 +217,6 @@ class RemoteSettingsViewController: FormViewController {
guard let value = row.value else { return }
UserDefaultsRepository.presetString.value = value
}

+++ ButtonRow() {
$0.title = "DONE"
}.onCellSelection { (row, arg) in
Expand Down
23 changes: 21 additions & 2 deletions LoopFollow/ViewControllers/RemoteViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,23 @@ import UIKit

class RemoteViewController: UIViewController {

@IBOutlet weak var remoteBolusButton: UIButton!

override func viewDidLoad() {
super.viewDidLoad()
if UserDefaultsRepository.forceDarkMode.value {
overrideUserInterfaceStyle = .dark
}

// Do any additional setup after loading the view.
// Initial UI setup based on hideRemoteBolus value
updateUI()
}

// Function to update UI based on hideRemoteBolus value
func updateUI() {
let isRemoteBolusHidden = UserDefaultsRepository.hideRemoteBolus.value
remoteBolusButton.isHidden = isRemoteBolusHidden
}
}

@IBAction func presetButtonPressed(_ sender: Any) {
let presetViewController = storyboard!.instantiateViewController(withIdentifier: "remotePreset") as! PresetViewController
Expand Down Expand Up @@ -55,4 +64,14 @@ class RemoteViewController: UIViewController {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}

// Function to hide the bolusRow
func hideRemoteBolusButton() {
remoteBolusButton.isHidden = true
}

// Function to show the bolusRow
func showRemoteBolusButton() {
remoteBolusButton.isHidden = false
}
}
2 changes: 1 addition & 1 deletion LoopFollow/repository/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ class UserDefaultsRepository {
static let overrideString = UserDefaultsValue<String>(key: "overrideString", default: "🚫 Avbryt Override, ⬇️ 75%, 🤢 Magsjuka, 🍬 Efter dextro, 🍬😴 Efter dextro natt, 🏃‍♂️ Hög aktivitet, ⬇️ 90%, ❌ Blocka SMB, ⚽️ Gympa, 😴 Nattläge, 🍇 Vindruvor, 🍭 Godisdag, 🐌 Ledig dag, 🤧 Förkyld, 👻 Resistens, 🥯 Sen frukost")
static let tempTargetsString = UserDefaultsValue<String>(key: "tempTargetsString", default: "🚫 Avbryt Temp Target, 🏃‍♂️ Hög aktivitet, 🍬 Efter dextro, 🍽️ Äter snart, ❌ Blocka SMB, ⬆️ Boost, ⚽️ Gympa, 🍬😴 Efter dextro natt, 😴 Nattläge")
static let presetString = UserDefaultsValue<String>(key: "presetString", default: "🍬 1 Dextro, 🍬 2 Dextro, 🥭 Frukt, 🥯 Frukost, 🍝 Lunch, 🥪 Mellis, 🥘 Middag, 🍭 Godis, 🍔 McDonalds, 🍿 Snacks")
//to fix later on //static let hideBolus = UserDefaultsValue<Bool>(key: "hideBolus", default: true)
static let hideRemoteBolus = UserDefaultsValue<Bool>(key: "hideRemoteBolus", default: true)

// API settings
static let twilioSIDString = UserDefaultsValue<String>(key: "twilioSIDString", default: "")
Expand Down

0 comments on commit 0a502b8

Please sign in to comment.