// // WatchSettingsViewController.swift // LoopFollow // // Created by Jose Paredes on 7/16/20. // Copyright © 2020 Jon Fawcett. All rights reserved. // import Foundation import Eureka import EventKit import EventKitUI class WatchSettingsViewController: FormViewController { var appStateController: AppStateController? override func viewDidLoad() { super.viewDidLoad() if UserDefaultsRepository.forceDarkMode.value { overrideUserInterfaceStyle = .dark } let eventStore = EKEventStore() eventStore.requestCalendarAccess { [weak self] (granted, error) in guard let self = self else { return } DispatchQueue.main.async { // Update the form based on the calendar access status self.buildWatchSettings(hasCalendarAccess: granted) self.showHideNSDetails() } } } func showHideNSDetails() { var isHidden = false var isEnabled = true if !IsNightscoutEnabled() { isHidden = true isEnabled = false } let tmpArr = ["IOB", "COB", "BASAL", "LOOP", "OVERRIDE"] for i in 0..("calendarIdentifier") { row in row.title = "Calendar" row.options = calendars.map { $0.identifier } row.value = UserDefaultsRepository.calendarIdentifier.value row.displayValueFor = { value in guard let value = value else { return nil } let matching = calendars .flatMap { $0 } .filter { $0.identifier.range(of: value) != nil || $0.title.range(of: value) != nil } if matching.count > 0 { return "\(String(matching[0].title))" } else { return " - " } } }.onChange { [weak self] row in guard let value = row.value else { return } UserDefaultsRepository.calendarIdentifier.value = value } <<< TextRow("watchLine1"){ row in row.title = "Line 1" row.value = UserDefaultsRepository.watchLine1.value }.onChange { row in guard let value = row.value else { return } UserDefaultsRepository.watchLine1.value = value } <<< TextRow("watchLine2"){ row in row.title = "Line 2" row.value = UserDefaultsRepository.watchLine2.value }.onChange { row in guard let value = row.value else { return } UserDefaultsRepository.watchLine2.value = value } +++ Section(header: "Available Variables", footer: "") <<< LabelRow("BG"){ row in row.title = "%BG% : Blood Glucose Reading" } <<< LabelRow("DIRECTION"){ row in row.title = "%DIRECTION% : Dexcom Trend Arrow" } <<< LabelRow("DELTA"){ row in row.title = "%DELTA% : +/- From Last Reading" } <<< LabelRow("IOB"){ row in row.title = "%IOB% : Insulin on Board" } <<< LabelRow("COB"){ row in row.title = "%COB% : Carbs on Board" } <<< LabelRow("BASAL"){ row in row.title = "%BASAL% : Current Basal u/hr" } <<< LabelRow("LOOP"){ row in row.title = "%LOOP% : Loop Status Symbol" } <<< LabelRow("OVERRIDE"){ row in row.title = "%OVERRIDE% : Active Override %" } <<< LabelRow("MINAGO"){ row in row.title = "%MINAGO% : Only displays for old readings" } +++ ButtonRow() { $0.title = "DONE" }.onCellSelection { (row, arg) in self.dismiss(animated:true, completion: nil) } } }