diff --git a/xdrip/Extensions/UserDefaults.swift b/xdrip/Extensions/UserDefaults.swift index 11960ced5..2ec87f6ae 100644 --- a/xdrip/Extensions/UserDefaults.swift +++ b/xdrip/Extensions/UserDefaults.swift @@ -132,6 +132,11 @@ extension UserDefaults { /// use the newer TITR of 70-140mg/dL to calculate the statistics? If false, we will use the conventional TIR of 70-180mg/dL case useTITRStatisticsRange = "useTITRStatisticsRange" + // Alarms settings + + /// hide slope in alarms + case hideSlopeInAlarms = "hideSlopeInAlarms" + // Housekeeper settings /// For how many days should we keep Readings, Treatments and Calibrations? @@ -1185,6 +1190,15 @@ extension UserDefaults { } } + /// - show slopes in alarms + var showSlopeInAlarms: Bool { + get { + return !bool(forKey: Key.hideSlopeInAlarms.rawValue) + } + set { + set(!newValue, forKey: Key.hideSlopeInAlarms.rawValue) + } + } // MARK: Sensor Info Settings diff --git a/xdrip/Managers/Alerts/AlertKind.swift b/xdrip/Managers/Alerts/AlertKind.swift index ef1f091c3..f1effdf9b 100644 --- a/xdrip/Managers/Alerts/AlertKind.swift +++ b/xdrip/Managers/Alerts/AlertKind.swift @@ -198,7 +198,7 @@ public enum AlertKind:Int, CaseIterable { if lastBgReading.calculatedValue == 0.0 {return (false, nil, nil, nil)} // now do the actual check if alert is applicable or not if lastBgReading.calculatedValue.bgValueRounded(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl) < Double(currentAlertEntry.value).bgValueRounded(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl) { - return (true, lastBgReading.unitizedDeltaString(previousBgReading: lastButOneBgReading, showUnit: true, highGranularity: true, mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl), createAlertTitleForBgReadingAlerts(bgReading: lastBgReading, alertKind: self), nil) + return (true, lastBgReading.unitizedDeltaString(previousBgReading: lastButOneBgReading, showUnit: true, highGranularity: true, mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl), createAlertTitleForBgReadingAlerts(bgReading: lastBgReading, alertKind: self, showSlope: UserDefaults.standard.showSlopeInAlarms), nil) } else {return (false, nil, nil, nil)} } else {return (false, nil, nil, nil)} @@ -211,7 +211,7 @@ public enum AlertKind:Int, CaseIterable { if lastBgReading.calculatedValue == 0.0 {return (false, nil, nil, nil)} // now do the actual check if alert is applicable or not if lastBgReading.calculatedValue.bgValueRounded(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl) > Double(currentAlertEntry.value).bgValueRounded(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl){ - return (true, lastBgReading.unitizedDeltaString(previousBgReading: lastButOneBgReading, showUnit: true, highGranularity: true, mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl), createAlertTitleForBgReadingAlerts(bgReading: lastBgReading, alertKind: self), nil) + return (true, lastBgReading.unitizedDeltaString(previousBgReading: lastButOneBgReading, showUnit: true, highGranularity: true, mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl), createAlertTitleForBgReadingAlerts(bgReading: lastBgReading, alertKind: self, showSlope: UserDefaults.standard.showSlopeInAlarms), nil) } else {return (false, nil, nil, nil)} } else {return (false, nil, nil, nil)} @@ -228,7 +228,7 @@ public enum AlertKind:Int, CaseIterable { if lastBgReading.calculatedValue == 0.0 || lastButOneBgReading.calculatedValue == 0.0 {return (false, nil, nil, nil)} // now do the actual check if alert is applicable or not if lastButOneBgReading.calculatedValue.bgValueRounded(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl) - lastBgReading.calculatedValue.bgValueRounded(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl) > Double(currentAlertEntry.value).bgValueRounded(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl) { - return (true, lastBgReading.unitizedDeltaString(previousBgReading: lastButOneBgReading, showUnit: true, highGranularity: true, mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl), createAlertTitleForBgReadingAlerts(bgReading: lastBgReading, alertKind: self), nil) + return (true, lastBgReading.unitizedDeltaString(previousBgReading: lastButOneBgReading, showUnit: true, highGranularity: true, mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl), createAlertTitleForBgReadingAlerts(bgReading: lastBgReading, alertKind: self, showSlope: UserDefaults.standard.showSlopeInAlarms), nil) } else {return (false, nil, nil, nil)} } else {return (false, nil, nil, nil)} @@ -248,7 +248,7 @@ public enum AlertKind:Int, CaseIterable { if lastBgReading.calculatedValue == 0.0 || lastButOneBgReading.calculatedValue == 0.0 {return (false, nil, nil, nil)} // now do the actual check if alert is applicable or not if lastBgReading.calculatedValue.bgValueRounded(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl) - lastButOneBgReading.calculatedValue.bgValueRounded(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl) > Double(currentAlertEntry.value).bgValueRounded(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl) { - return (true, lastBgReading.unitizedDeltaString(previousBgReading: lastButOneBgReading, showUnit: true, highGranularity: true, mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl), createAlertTitleForBgReadingAlerts(bgReading: lastBgReading, alertKind: self), nil) + return (true, lastBgReading.unitizedDeltaString(previousBgReading: lastButOneBgReading, showUnit: true, highGranularity: true, mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl), createAlertTitleForBgReadingAlerts(bgReading: lastBgReading, alertKind: self, showSlope: UserDefaults.standard.showSlopeInAlarms), nil) } else {return (false, nil, nil, nil)} } else {return (false, nil, nil, nil)} @@ -445,7 +445,7 @@ public enum AlertKind:Int, CaseIterable { } // specifically for high, low, very high, very low because these need the same kind of alertTitle -fileprivate func createAlertTitleForBgReadingAlerts(bgReading:BgReading, alertKind:AlertKind) -> String { +fileprivate func createAlertTitleForBgReadingAlerts(bgReading:BgReading, alertKind:AlertKind, showSlope:Bool) -> String { var returnValue:String = "" // the start of the body, which says like "High Alert" @@ -472,7 +472,7 @@ fileprivate func createAlertTitleForBgReadingAlerts(bgReading:BgReading, alertKi returnValue = returnValue + " " + bgReading.calculatedValue.mgdlToMmolAndToString(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl) // add slopeArrow - if !bgReading.hideSlope { + if showSlope && !bgReading.hideSlope { returnValue = returnValue + " " + bgReading.slopeArrow() } diff --git a/xdrip/Texts/TextsSettingsView.swift b/xdrip/Texts/TextsSettingsView.swift index 0a12a7d2c..7ab22e585 100644 --- a/xdrip/Texts/TextsSettingsView.swift +++ b/xdrip/Texts/TextsSettingsView.swift @@ -641,6 +641,10 @@ class Texts_SettingsView { return NSLocalizedString("volumeTestiOSSound", tableName: filename, bundle: Bundle.main, value: "Volume Test (Current iPhone Volume)", comment: "In Settings, Alerts section, there's an option to test the volume of ios sound, this is the title of the row") }() + static let showSlopeInAlarms: String = { + return NSLocalizedString("showSlopeInAlarms", tableName: filename, bundle: Bundle.main, value: "Show Slope in Alarms", comment: "In Settings, Alerts section, there's an option to show the slopes in the alarms") + }() + static let volumeTestiOSSoundExplanation: String = { return NSLocalizedString("volumeTestiOSSoundExplanation", tableName: filename, bundle: Bundle.main, value: "An alarm sound is now being played with the same volume that will be used for an Alarm Type with 'Override Mute' = Off\n\n(Also used always for Missed Reading alarms which use the iOS volume.)\n\nPress one of the volume buttons to stop the sound, then change the volume with the volume buttons to the desired volume and test again.", comment: "In Settings, Alerts section, there's an option to test the volume settings, this is text explaining the test when clicking the row - this is for ios sound volume test") }() diff --git a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewAlertSettingsViewModel.swift b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewAlertSettingsViewModel.swift index 26ecc9af0..27f04fb7d 100644 --- a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewAlertSettingsViewModel.swift +++ b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewAlertSettingsViewModel.swift @@ -15,6 +15,9 @@ fileprivate enum Setting:Int, CaseIterable { /// volume test for sound play in iOS notification case volumeTestiOSSound = 3 + /// show slope in alarms + case showSlopeInAlarms = 4 + } /// conforms to SettingsViewModelProtocol for all alert settings in the first sections screen @@ -83,7 +86,11 @@ struct SettingsViewAlertSettingsViewModel:SettingsViewModelProtocol { return SettingsSelectedRowAction.showInfoText(title: Texts_Common.warning, message: Texts_SettingsView.volumeTestiOSSoundExplanation, actionHandler: nil) + case .showSlopeInAlarms: + return .nothing + } + } func storeRowReloadClosure(rowReloadClosure: ((Int) -> Void)) {} @@ -97,7 +104,14 @@ struct SettingsViewAlertSettingsViewModel:SettingsViewModelProtocol { } func uiView(index: Int) -> UIView? { - return nil + guard let setting = Setting(rawValue: index) else { fatalError("Unexpected Section") } + + switch setting { + case .showSlopeInAlarms: + return UISwitch(isOn: UserDefaults.standard.showSlopeInAlarms, action: {(isOn:Bool) in UserDefaults.standard.showSlopeInAlarms = isOn}) + default: + return nil + } } func settingsRowText(index: Int) -> String { @@ -115,6 +129,9 @@ struct SettingsViewAlertSettingsViewModel:SettingsViewModelProtocol { case .volumeTestiOSSound: return Texts_SettingsView.volumeTestiOSSound + + case .showSlopeInAlarms: + return Texts_SettingsView.showSlopeInAlarms } } @@ -129,7 +146,7 @@ struct SettingsViewAlertSettingsViewModel:SettingsViewModelProtocol { return .disclosureIndicator - case .volumeTestSoundPlayer, .volumeTestiOSSound: + case .volumeTestSoundPlayer, .volumeTestiOSSound, .showSlopeInAlarms: return .none