diff --git a/xdrip/Extensions/UserDefaults.swift b/xdrip/Extensions/UserDefaults.swift index e9a4899e9..d1dc01ae1 100644 --- a/xdrip/Extensions/UserDefaults.swift +++ b/xdrip/Extensions/UserDefaults.swift @@ -84,6 +84,10 @@ extension UserDefaults { case miniChartHoursToShow = "miniChartHoursToShow" /// should the screen/chart be allowed to rotate? case allowScreenRotation = "allowScreenRotation" + /// should the progress bar be animated? + case animateProgressBar = "animateProgressBar" + /// should the progress bar be towards 0? + case reverseProgressBar = "reverseProgressBar" /// should the clock view be shown when the screen is locked? case showClockWhenScreenIsLocked = "showClockWhenScreenIsLocked" /// how (and if) the screen should be dimmed when screen lock is enabled @@ -1016,6 +1020,27 @@ extension UserDefaults { } } + /// should the progress bar be animated? + @objc dynamic var animateProgressBar: Bool { + // default value for bool in userdefaults is false, as default we want the chart to animate + get { + return !bool(forKey: Key.animateProgressBar.rawValue) + } + set { + set(!newValue, forKey: Key.animateProgressBar.rawValue) + } + } + + /// should the progress bar be towards 0? + @objc dynamic var reverseProgressBar: Bool { + get { + return bool(forKey: Key.reverseProgressBar.rawValue) + } + set { + set(newValue, forKey: Key.reverseProgressBar.rawValue) + } + } + /// should the clock view be shown when the screen is locked? @objc dynamic var showClockWhenScreenIsLocked: Bool { // default value for bool in userdefaults is false, as default we want the clock to show when the screen is locked diff --git a/xdrip/Storyboards/en.lproj/SettingsViews.strings b/xdrip/Storyboards/en.lproj/SettingsViews.strings index 1dadfb106..21f8a69bf 100644 --- a/xdrip/Storyboards/en.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/en.lproj/SettingsViews.strings @@ -36,6 +36,8 @@ "settingsviews_IntervalTitle" = "Notification Interval"; "settingsviews_IntervalMessage" = "Minimum interval between two notifications (mins)"; "settingsviews_allowScreenRotation" = "Allow Chart Rotation"; +"settingsviews_animateProgressBar" = "Animate Progress Bar"; +"settingsviews_reverseProgressBar" = "Reverse Progress Bar"; "settingsviews_showMiniChart" = "Show the Mini-Chart"; "settingsviews_showClockWhenScreenIsLocked" = "Show Clock when Locked"; "settingsviews_screenLockDimmingTypeWhenScreenIsLocked" = "Dim Screen when Locked"; diff --git a/xdrip/Texts/TextsSettingsView.swift b/xdrip/Texts/TextsSettingsView.swift index 334c830dc..019b4b325 100644 --- a/xdrip/Texts/TextsSettingsView.swift +++ b/xdrip/Texts/TextsSettingsView.swift @@ -260,6 +260,14 @@ class Texts_SettingsView { return NSLocalizedString("settingsviews_allowScreenRotation", tableName: filename, bundle: Bundle.main, value: "Allow Chart Rotation", comment: "home screen settings, should the main glucose chart screen be allowed") }() + static let animateProgressBar: String = { + return NSLocalizedString("settingsviews_animateProgressBar", tableName: filename, bundle: Bundle.main, value: "Animate Progress Bar", comment: "home screen settings, should the progress bar be animated") + }() + + static let reverseProgressBar: String = { + return NSLocalizedString("settingsviews_reverseProgressBar", tableName: filename, bundle: Bundle.main, value: "Reverse Progress Bar", comment: "home screen settings, should the progress bar be reversed, and exhausted when the sensor ends") + }() + static let showMiniChart: String = { return NSLocalizedString("settingsviews_showMiniChart", tableName: filename, bundle: Bundle.main, value: "Show the Mini-Chart", comment: "home screen settings, should the mini-chart be shown") }() diff --git a/xdrip/Utilities/Trace.swift b/xdrip/Utilities/Trace.swift index f744ccfe1..77c0f5d8e 100644 --- a/xdrip/Utilities/Trace.swift +++ b/xdrip/Utilities/Trace.swift @@ -373,6 +373,8 @@ class Trace { traceInfo.appendStringAndNewLine("\nHome screen settings:") traceInfo.appendStringAndNewLine(" Allow chart rotation: " + UserDefaults.standard.allowScreenRotation.description) + traceInfo.appendStringAndNewLine(" Animate progress bar: " + UserDefaults.standard.animateProgressBar.description) + traceInfo.appendStringAndNewLine(" Reverse progress bar: " + UserDefaults.standard.reverseProgressBar.description) traceInfo.appendStringAndNewLine(" Screen dimming type when locked: " + UserDefaults.standard.screenLockDimmingType.description) traceInfo.appendStringAndNewLine(" Show mini-chart: " + UserDefaults.standard.showMiniChart.description) traceInfo.appendStringAndNewLine(" Urgent high: " + UserDefaults.standard.urgentHighMarkValueInUserChosenUnitRounded.description) diff --git a/xdrip/View Controllers/Root View Controller/RootViewController.swift b/xdrip/View Controllers/Root View Controller/RootViewController.swift index 81887e794..5c0427ca4 100644 --- a/xdrip/View Controllers/Root View Controller/RootViewController.swift +++ b/xdrip/View Controllers/Root View Controller/RootViewController.swift @@ -2790,7 +2790,7 @@ final class RootViewController: UIViewController, ObservableObject { // disable the chart animation if it's just a normal update, enable it if the call comes from didAppear() - if animate { + if animate && UserDefaults.standard.animateProgressBar { self.pieChartOutlet.animDuration = ConstantsStatistics.pieChartAnimationSpeed } else { self.pieChartOutlet.animDuration = 0 @@ -3171,7 +3171,12 @@ final class RootViewController: UIViewController, ObservableObject { } else { // fill in the labels to show sensor time elapsed and max age - dataSourceSensorCurrentAgeOutlet.text = sensorStartDate?.daysAndHoursAgo() + if UserDefaults.standard.reverseProgressBar { + dataSourceSensorCurrentAgeOutlet.text = sensorTimeLeftInMinutes.minutesToDaysAndHours() + } else { + dataSourceSensorCurrentAgeOutlet.text = sensorStartDate?.daysAndHoursAgo() + } + dataSourceSensorMaxAgeOutlet.text = " / " + sensorMaxAgeInMinutes.minutesToDaysAndHours() @@ -3181,7 +3186,11 @@ final class RootViewController: UIViewController, ObservableObject { } else { // fill in the labels to show sensor time elapsed and max age - dataSourceSensorCurrentAgeOutlet.text = sensorStartDate?.daysAndHoursAgo() + if UserDefaults.standard.reverseProgressBar { + dataSourceSensorCurrentAgeOutlet.text = sensorTimeLeftInMinutes.minutesToDaysAndHours() + } else { + dataSourceSensorCurrentAgeOutlet.text = sensorStartDate?.daysAndHoursAgo() + } dataSourceSensorMaxAgeOutlet.text = " / " + sensorMaxAgeInMinutes.minutesToDaysAndHours() @@ -3217,7 +3226,7 @@ final class RootViewController: UIViewController, ObservableObject { dataSourceLabelOutlet.text = UserDefaults.standard.activeSensorDescription // if animatation is requested, then first set the value to 0 - if animate { + if animate && UserDefaults.standard.animateProgressBar { sensorProgressOutlet.setProgress(0.0, animated: false) @@ -3225,7 +3234,10 @@ final class RootViewController: UIViewController, ObservableObject { // let's run the progress update in an async thread with a really small delay so that the animation updates smoothly after the view has appeared DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { - self.sensorProgressOutlet.setProgress(Float(1 - (sensorTimeLeftInMinutes / sensorMaxAgeInMinutes)), animated: animate) + let valueTowardsTrailing:Float = Float(1 - (sensorTimeLeftInMinutes / sensorMaxAgeInMinutes)) + let valueTowardsLeading:Float = 1 - valueTowardsTrailing + self.sensorProgressOutlet.setProgress(UserDefaults.standard.reverseProgressBar ? valueTowardsLeading : valueTowardsTrailing, animated: animate) + } } else { diff --git a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewHomeScreenSettingsViewModel.swift b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewHomeScreenSettingsViewModel.swift index b613a2d60..3727f7e2c 100644 --- a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewHomeScreenSettingsViewModel.swift +++ b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewHomeScreenSettingsViewModel.swift @@ -37,6 +37,12 @@ fileprivate enum Setting:Int, CaseIterable { //urgent low value case urgentLowMarkValue = 8 + // animate the progress bar? + case animateProgressBar = 9 + + // reverse the progress bar? + case reverseProgressBar = 10 + } /// conforms to SettingsViewModelProtocol for all general settings in the first sections screen @@ -60,6 +66,12 @@ struct SettingsViewHomeScreenSettingsViewModel:SettingsViewModelProtocol { case .screenLockDimmingType, .urgentHighMarkValue, .highMarkValue, .targetMarkValue, .lowMarkValue, .urgentLowMarkValue: return nil + case .animateProgressBar: + return UISwitch(isOn: UserDefaults.standard.animateProgressBar, action: {(isOn:Bool) in UserDefaults.standard.animateProgressBar = isOn}) + + case .reverseProgressBar: + return UISwitch(isOn: UserDefaults.standard.reverseProgressBar, action: {(isOn:Bool) in UserDefaults.standard.reverseProgressBar = isOn}) + } } @@ -109,6 +121,24 @@ struct SettingsViewHomeScreenSettingsViewModel:SettingsViewModelProtocol { } }) + case .animateProgressBar: + return SettingsSelectedRowAction.callFunction(function: { + if UserDefaults.standard.animateProgressBar { + UserDefaults.standard.animateProgressBar = false + } else { + UserDefaults.standard.animateProgressBar = true + } + }) + + case .reverseProgressBar: + return SettingsSelectedRowAction.callFunction(function: { + if UserDefaults.standard.reverseProgressBar { + UserDefaults.standard.reverseProgressBar = false + } else { + UserDefaults.standard.reverseProgressBar = true + } + }) + case .showClockWhenScreenIsLocked: return SettingsSelectedRowAction.callFunction(function: { if UserDefaults.standard.showClockWhenScreenIsLocked { @@ -179,6 +209,12 @@ struct SettingsViewHomeScreenSettingsViewModel:SettingsViewModelProtocol { case .allowScreenRotation: return Texts_SettingsView.allowScreenRotation + case .animateProgressBar: + return Texts_SettingsView.animateProgressBar + + case .reverseProgressBar: + return Texts_SettingsView.reverseProgressBar + case .showClockWhenScreenIsLocked: return Texts_SettingsView.showClockWhenScreenIsLocked @@ -213,7 +249,7 @@ struct SettingsViewHomeScreenSettingsViewModel:SettingsViewModelProtocol { case .screenLockDimmingType, .urgentHighMarkValue, .highMarkValue, .lowMarkValue, .urgentLowMarkValue, .targetMarkValue: return UITableViewCell.AccessoryType.disclosureIndicator - case .allowScreenRotation, .showClockWhenScreenIsLocked, .showMiniChart: + case .allowScreenRotation, .animateProgressBar, .reverseProgressBar, .showClockWhenScreenIsLocked, .showMiniChart: return UITableViewCell.AccessoryType.none } @@ -242,7 +278,7 @@ struct SettingsViewHomeScreenSettingsViewModel:SettingsViewModelProtocol { case .screenLockDimmingType: return UserDefaults.standard.screenLockDimmingType.description - case .allowScreenRotation, .showClockWhenScreenIsLocked, .showMiniChart: + case .allowScreenRotation, .animateProgressBar, .reverseProgressBar, .showClockWhenScreenIsLocked, .showMiniChart: return nil }