Skip to content

Commit

Permalink
Add settings to customize the progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Allène committed Jun 8, 2024
1 parent b02cd82 commit 1281664
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 4 deletions.
25 changes: 25 additions & 0 deletions xdrip/Extensions/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1001,6 +1005,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
Expand Down
2 changes: 2 additions & 0 deletions xdrip/Storyboards/en.lproj/SettingsViews.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 8 additions & 0 deletions xdrip/Texts/TextsSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}()
Expand Down
2 changes: 2 additions & 0 deletions xdrip/Utilities/Trace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3193,15 +3193,18 @@ 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)

}

// 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ fileprivate enum Setting:Int, CaseIterable {
//urgent low value
case urgentLowMarkValue = 8

// animate the progress bar?
case animateProgressBar = 11

// reverse the progress bar?
case reverseProgressBar = 12

}

/// conforms to SettingsViewModelProtocol for all general settings in the first sections screen
Expand All @@ -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})

}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

}
Expand Down Expand Up @@ -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

}
Expand Down

0 comments on commit 1281664

Please sign in to comment.