Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle to hide slopes in alarms #449

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions xdrip/Extensions/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ extension UserDefaults {
case snoozeAllAlertsFromDate = "snoozeAllAlertsFromDate"
/// for how long did the user snooze all alarms
case snoozeAllAlertsUntilDate = "snoozeAllAlertsUntilDate"
/// hide slope in alarms
case hideSlopeInAlarms = "hideSlopeInAlarms"

// Housekeeper settings

Expand Down Expand Up @@ -1197,6 +1199,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: Alert Settings

Expand Down
21 changes: 13 additions & 8 deletions xdrip/Managers/Alerts/AlertKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ 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, createAlertBodyForBgReadingAlerts(bgReading: lastBgReading, alertKind: self), createAlertTitleForBgReadingAlerts(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)
return (true, createAlertBodyForBgReadingAlerts(bgReading: lastBgReading, alertKind: self, showSlope: UserDefaults.standard.showSlopeInAlarms), createAlertTitleForBgReadingAlerts(alertKind: self, showSlope: UserDefaults.standard.showSlopeInAlarms), nil)
} else {return (false, nil, nil, nil)}
} else {return (false, nil, nil, nil)}

Expand All @@ -203,7 +203,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, createAlertBodyForBgReadingAlerts(bgReading: lastBgReading, alertKind: self), createAlertTitleForBgReadingAlerts(alertKind: self), nil)
return (true, createAlertBodyForBgReadingAlerts(bgReading: lastBgReading, alertKind: self, showSlope: UserDefaults.standard.showSlopeInAlarms), createAlertTitleForBgReadingAlerts(alertKind: self, showSlope: UserDefaults.standard.showSlopeInAlarms), nil)
} else {return (false, nil, nil, nil)}
} else {return (false, nil, nil, nil)}

Expand All @@ -220,7 +220,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, createAlertBodyForBgReadingAlerts(bgReading: lastBgReading, alertKind: self), createAlertTitleForBgReadingAlerts(alertKind: self), nil)
return (true, createAlertBodyForBgReadingAlerts(bgReading: lastBgReading, alertKind: self, showSlope: UserDefaults.standard.showSlopeInAlarms), createAlertTitleForBgReadingAlerts(alertKind: self, showSlope: UserDefaults.standard.showSlopeInAlarms), nil)
} else {return (false, nil, nil, nil)}

} else {return (false, nil, nil, nil)}
Expand All @@ -240,7 +240,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, createAlertBodyForBgReadingAlerts(bgReading: lastBgReading, alertKind: self), createAlertTitleForBgReadingAlerts(alertKind: self), nil)
return (true, createAlertBodyForBgReadingAlerts(bgReading: lastBgReading, alertKind: self, showSlope: UserDefaults.standard.showSlopeInAlarms), createAlertTitleForBgReadingAlerts(alertKind: self, showSlope: UserDefaults.standard.showSlopeInAlarms), nil)
} else {return (false, nil, nil, nil)}

} else {return (false, nil, nil, nil)}
Expand Down Expand Up @@ -451,7 +451,12 @@ public enum AlertKind:Int, CaseIterable {
}

// specifically for high, low, very high, very low because these need the same kind of alertTitle
fileprivate func createAlertTitleForBgReadingAlerts(alertKind: AlertKind) -> String {
fileprivate func createAlertTitleForBgReadingAlerts(alertKind: AlertKind, showSlope:Bool) -> String {
guard showSlope else {
return ""
}

var returnValue:String = ""
// the start of the body, which says like "High Alert"
switch alertKind {
case .low:
Expand All @@ -472,14 +477,14 @@ fileprivate func createAlertTitleForBgReadingAlerts(alertKind: AlertKind) -> Str
}

// specifically for high, low, very high, very low because these need to show an alert body with the BG value etc
fileprivate func createAlertBodyForBgReadingAlerts(bgReading:BgReading, alertKind:AlertKind) -> String {
fileprivate func createAlertBodyForBgReadingAlerts(bgReading:BgReading, alertKind:AlertKind, showSlope:Bool) -> String {
var returnValue:String = ""

// add unit
returnValue = returnValue + " " + bgReading.calculatedValue.mgdlToMmolAndToString(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl)

// add slopeArrow
if !bgReading.hideSlope {
if showSlope && !bgReading.hideSlope {
returnValue = returnValue + " " + bgReading.slopeArrow()
}

Expand Down
4 changes: 4 additions & 0 deletions xdrip/Texts/TextsSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,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")
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {}
Expand All @@ -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 {
Expand All @@ -115,6 +129,9 @@ struct SettingsViewAlertSettingsViewModel:SettingsViewModelProtocol {

case .volumeTestiOSSound:
return Texts_SettingsView.volumeTestiOSSound

case .showSlopeInAlarms:
return Texts_SettingsView.showSlopeInAlarms

}
}
Expand All @@ -129,7 +146,7 @@ struct SettingsViewAlertSettingsViewModel:SettingsViewModelProtocol {

return .disclosureIndicator

case .volumeTestSoundPlayer, .volumeTestiOSSound:
case .volumeTestSoundPlayer, .volumeTestiOSSound, .showSlopeInAlarms:

return .none

Expand Down