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 settings to customize the progress bar #507

Open
wants to merge 3 commits 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
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 @@ -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
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 @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand Down Expand Up @@ -3217,15 +3226,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 = 9

// reverse the progress bar?
case reverseProgressBar = 10

}

/// 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