From 51545052fc6b2f7b10cf3feab030ca4487ffc0d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bj=C3=B6rkert?= Date: Tue, 5 Dec 2023 10:01:55 +0100 Subject: [PATCH 1/2] Show App Name --- .../Controllers/AppStateController.swift | 21 ++-- .../Controllers/Nightscout/BGData.swift | 10 +- .../GeneralSettingsViewController.swift | 15 ++- .../ViewControllers/MainViewController.swift | 106 +++++++++--------- LoopFollow/repository/UserDefaults.swift | 1 + 5 files changed, 90 insertions(+), 63 deletions(-) diff --git a/LoopFollow/Controllers/AppStateController.swift b/LoopFollow/Controllers/AppStateController.swift index d5f714936..6b5be6b1a 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 showAppNameChange = 8192 } class AppStateController { diff --git a/LoopFollow/Controllers/Nightscout/BGData.swift b/LoopFollow/Controllers/Nightscout/BGData.swift index 75c1f944a..e4482ea0a 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.showAppName.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..e8e2b61ea 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("showAppName") { row in + row.title = "Show App Name" + row.value = UserDefaultsRepository.showAppName.value + }.onChange { [weak self] row in + guard let value = row.value else { return } + UserDefaultsRepository.showAppName.value = value + + if let appState = self!.appStateController { + appState.generalSettingsChanged = true + appState.generalSettingsChanges |= GeneralSettingsChangeEnum.showAppNameChange.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..84ee0091d 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.showAppNameChange.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..897eb8c9a 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 showAppName = UserDefaultsValue(key: "showAppName", 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) From b5a8145ade8f5e80e242427b8ed0cd07424deffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bj=C3=B6rkert?= Date: Tue, 5 Dec 2023 17:26:38 +0100 Subject: [PATCH 2/2] Refactor to Display Name --- LoopFollow/Controllers/AppStateController.swift | 2 +- LoopFollow/Controllers/Nightscout/BGData.swift | 2 +- .../GeneralSettingsViewController.swift | 10 +++++----- LoopFollow/ViewControllers/MainViewController.swift | 2 +- LoopFollow/repository/UserDefaults.swift | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/LoopFollow/Controllers/AppStateController.swift b/LoopFollow/Controllers/AppStateController.swift index 6b5be6b1a..422e1910c 100644 --- a/LoopFollow/Controllers/AppStateController.swift +++ b/LoopFollow/Controllers/AppStateController.swift @@ -49,7 +49,7 @@ enum GeneralSettingsChangeEnum: Int { case showStatsChange = 1024 case showSmallGraphChange = 2048 case useIFCCChange = 4096 - case showAppNameChange = 8192 + case showDisplayNameChange = 8192 } class AppStateController { diff --git a/LoopFollow/Controllers/Nightscout/BGData.swift b/LoopFollow/Controllers/Nightscout/BGData.swift index e4482ea0a..220cd121a 100644 --- a/LoopFollow/Controllers/Nightscout/BGData.swift +++ b/LoopFollow/Controllers/Nightscout/BGData.swift @@ -205,7 +205,7 @@ extension MainViewController { } func updateServerText(with serverText: String? = nil) { - if UserDefaultsRepository.showAppName.value, let displayName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String { + 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 diff --git a/LoopFollow/ViewControllers/GeneralSettingsViewController.swift b/LoopFollow/ViewControllers/GeneralSettingsViewController.swift index e8e2b61ea..050920a76 100644 --- a/LoopFollow/ViewControllers/GeneralSettingsViewController.swift +++ b/LoopFollow/ViewControllers/GeneralSettingsViewController.swift @@ -151,16 +151,16 @@ class GeneralSettingsViewController: FormViewController { NotificationCenter.default.post(name: Notification.Name("toggleSpeakBG"), object: nil) } - <<< SwitchRow("showAppName") { row in - row.title = "Show App Name" - row.value = UserDefaultsRepository.showAppName.value + <<< 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.showAppName.value = value + UserDefaultsRepository.showDisplayName.value = value if let appState = self!.appStateController { appState.generalSettingsChanged = true - appState.generalSettingsChanges |= GeneralSettingsChangeEnum.showAppNameChange.rawValue + appState.generalSettingsChanges |= GeneralSettingsChangeEnum.showDisplayNameChange.rawValue } } diff --git a/LoopFollow/ViewControllers/MainViewController.swift b/LoopFollow/ViewControllers/MainViewController.swift index 84ee0091d..085c43e79 100644 --- a/LoopFollow/ViewControllers/MainViewController.swift +++ b/LoopFollow/ViewControllers/MainViewController.swift @@ -338,7 +338,7 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele BGChartFull.isHidden = !UserDefaultsRepository.showSmallGraph.value } - if appState.generalSettingsChanges & GeneralSettingsChangeEnum.showAppNameChange.rawValue != 0 { + if appState.generalSettingsChanges & GeneralSettingsChangeEnum.showDisplayNameChange.rawValue != 0 { self.updateServerText() } diff --git a/LoopFollow/repository/UserDefaults.swift b/LoopFollow/repository/UserDefaults.swift index 897eb8c9a..c16778e9f 100644 --- a/LoopFollow/repository/UserDefaults.swift +++ b/LoopFollow/repository/UserDefaults.swift @@ -75,7 +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 showAppName = UserDefaultsValue(key: "showAppName", 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)