diff --git a/LoopFollow/Controllers/AppStateController.swift b/LoopFollow/Controllers/AppStateController.swift index d5f714936..422e1910c 100644 --- a/LoopFollow/Controllers/AppStateController.swift +++ b/LoopFollow/Controllers/AppStateController.swift @@ -36,19 +36,20 @@ enum ChartSettingsChangeEnum: Int { // General Settings Flags enum GeneralSettingsChangeEnum: Int { - case colorBGTextChange = 1 - case speakBGChange = 2 - case backgroundRefreshFrequencyChange = 4 - case backgroundRefreshChange = 8 - case appBadgeChange = 16 - case dimScreenWhenIdleChange = 32 - case forceDarkModeChang = 64 - case persistentNotificationChange = 128 - case persistentNotificationLastBGTimeChange = 256 - case screenlockSwitchStateChange = 512 + case colorBGTextChange = 1 + case speakBGChange = 2 + case backgroundRefreshFrequencyChange = 4 + case backgroundRefreshChange = 8 + case appBadgeChange = 16 + case dimScreenWhenIdleChange = 32 + case forceDarkModeChang = 64 + case persistentNotificationChange = 128 + case persistentNotificationLastBGTimeChange = 256 + case screenlockSwitchStateChange = 512 case showStatsChange = 1024 case showSmallGraphChange = 2048 case useIFCCChange = 4096 + case showDisplayNameChange = 8192 } class AppStateController { diff --git a/LoopFollow/Controllers/Nightscout/BGData.swift b/LoopFollow/Controllers/Nightscout/BGData.swift index 75c1f944a..220cd121a 100644 --- a/LoopFollow/Controllers/Nightscout/BGData.swift +++ b/LoopFollow/Controllers/Nightscout/BGData.swift @@ -204,6 +204,14 @@ extension MainViewController { viewUpdateNSBG(sourceName: sourceName) } + func updateServerText(with serverText: String? = nil) { + if UserDefaultsRepository.showDisplayName.value, let displayName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String { + self.serverText.text = displayName + } else if let serverText = serverText { + self.serverText.text = serverText + } + } + // NS BG Data Front end updater func viewUpdateNSBG (sourceName: String) { DispatchQueue.main.async { @@ -229,7 +237,7 @@ extension MainViewController { userUnit = " mmol/L" } - self.serverText.text = sourceName + self.updateServerText(with: sourceName) var snoozerBG = "" var snoozerDirection = "" diff --git a/LoopFollow/ViewControllers/GeneralSettingsViewController.swift b/LoopFollow/ViewControllers/GeneralSettingsViewController.swift index 2f0f2ec5f..050920a76 100644 --- a/LoopFollow/ViewControllers/GeneralSettingsViewController.swift +++ b/LoopFollow/ViewControllers/GeneralSettingsViewController.swift @@ -151,7 +151,20 @@ class GeneralSettingsViewController: FormViewController { NotificationCenter.default.post(name: Notification.Name("toggleSpeakBG"), object: nil) } - +++ ButtonRow() { + <<< SwitchRow("showDisplayName") { row in + row.title = "Show Display Name" + row.value = UserDefaultsRepository.showDisplayName.value + }.onChange { [weak self] row in + guard let value = row.value else { return } + UserDefaultsRepository.showDisplayName.value = value + + if let appState = self!.appStateController { + appState.generalSettingsChanged = true + appState.generalSettingsChanges |= GeneralSettingsChangeEnum.showDisplayNameChange.rawValue + } + } + + +++ ButtonRow() { $0.title = "DONE" }.onCellSelection { (row, arg) in self.dismiss(animated:true, completion: nil) diff --git a/LoopFollow/ViewControllers/MainViewController.swift b/LoopFollow/ViewControllers/MainViewController.swift index 655f3de5a..085c43e79 100644 --- a/LoopFollow/ViewControllers/MainViewController.swift +++ b/LoopFollow/ViewControllers/MainViewController.swift @@ -296,61 +296,65 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele // check the app state // TODO: move to a function ? if let appState = self.appStateController { - - if appState.chartSettingsChanged { - - // can look at settings flags to be more fine tuned - self.updateBGGraphSettings() - - if ChartSettingsChangeEnum.smallGraphHeight.rawValue != 0 { - smallGraphHeightConstraint.constant = CGFloat(UserDefaultsRepository.smallGraphHeight.value) - self.view.layoutIfNeeded() - } - - // reset the app state - appState.chartSettingsChanged = false - appState.chartSettingsChanges = 0 - } - if appState.generalSettingsChanged { - - // settings for appBadge changed - if appState.generalSettingsChanges & GeneralSettingsChangeEnum.appBadgeChange.rawValue != 0 { - - } - - // settings for textcolor changed - if appState.generalSettingsChanges & GeneralSettingsChangeEnum.colorBGTextChange.rawValue != 0 { - self.setBGTextColor() - } - // settings for showStats changed - if appState.generalSettingsChanges & GeneralSettingsChangeEnum.showStatsChange.rawValue != 0 { - statsView.isHidden = !UserDefaultsRepository.showStats.value + if appState.chartSettingsChanged { + + // can look at settings flags to be more fine tuned + self.updateBGGraphSettings() + + if ChartSettingsChangeEnum.smallGraphHeight.rawValue != 0 { + smallGraphHeightConstraint.constant = CGFloat(UserDefaultsRepository.smallGraphHeight.value) + self.view.layoutIfNeeded() + } + + // reset the app state + appState.chartSettingsChanged = false + appState.chartSettingsChanges = 0 } - - // settings for useIFCC changed - if appState.generalSettingsChanges & GeneralSettingsChangeEnum.useIFCCChange.rawValue != 0 { - updateStats() + if appState.generalSettingsChanged { + + // settings for appBadge changed + if appState.generalSettingsChanges & GeneralSettingsChangeEnum.appBadgeChange.rawValue != 0 { + + } + + // settings for textcolor changed + if appState.generalSettingsChanges & GeneralSettingsChangeEnum.colorBGTextChange.rawValue != 0 { + self.setBGTextColor() + } + + // settings for showStats changed + if appState.generalSettingsChanges & GeneralSettingsChangeEnum.showStatsChange.rawValue != 0 { + statsView.isHidden = !UserDefaultsRepository.showStats.value + } + + // settings for useIFCC changed + if appState.generalSettingsChanges & GeneralSettingsChangeEnum.useIFCCChange.rawValue != 0 { + updateStats() + } + + // settings for showSmallGraph changed + if appState.generalSettingsChanges & GeneralSettingsChangeEnum.showSmallGraphChange.rawValue != 0 { + BGChartFull.isHidden = !UserDefaultsRepository.showSmallGraph.value + } + + if appState.generalSettingsChanges & GeneralSettingsChangeEnum.showDisplayNameChange.rawValue != 0 { + self.updateServerText() + } + + // reset the app state + appState.generalSettingsChanged = false + appState.generalSettingsChanges = 0 } - - // settings for showSmallGraph changed - if appState.generalSettingsChanges & GeneralSettingsChangeEnum.showSmallGraphChange.rawValue != 0 { - BGChartFull.isHidden = !UserDefaultsRepository.showSmallGraph.value + if appState.infoDataSettingsChanged { + createDerivedData() + self.infoTable.reloadData() + + // reset + appState.infoDataSettingsChanged = false } - - // reset the app state - appState.generalSettingsChanged = false - appState.generalSettingsChanges = 0 - } - if appState.infoDataSettingsChanged { - createDerivedData() - self.infoTable.reloadData() - - // reset - appState.infoDataSettingsChanged = false - } - - // add more processing of the app state + + // add more processing of the app state } } diff --git a/LoopFollow/repository/UserDefaults.swift b/LoopFollow/repository/UserDefaults.swift index 77557b94c..c16778e9f 100644 --- a/LoopFollow/repository/UserDefaults.swift +++ b/LoopFollow/repository/UserDefaults.swift @@ -75,6 +75,7 @@ class UserDefaultsRepository { static let useIFCC = UserDefaultsValue(key: "useIFCC", default: false) static let showSmallGraph = UserDefaultsValue(key: "showSmallGraph", default: true) static let speakBG = UserDefaultsValue(key: "speakBG", default: false) + static let showDisplayName = UserDefaultsValue(key: "showDisplayName", default: false) static let backgroundRefreshFrequency = UserDefaultsValue(key: "backgroundRefreshFrequency", default: 1) static let backgroundRefresh = UserDefaultsValue(key: "backgroundRefresh", default: true) static let appBadge = UserDefaultsValue(key: "appBadge", default: true)