Skip to content

Commit

Permalink
[LOOP-5056] Presets Homepage Bugs (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
Camji55 authored Dec 19, 2024
1 parent f6a4cd0 commit 19ca694
Show file tree
Hide file tree
Showing 23 changed files with 138 additions and 298 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Temp Presets.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
12 changes: 12 additions & 0 deletions Loop/DerivedAssetsBase.xcassets/presets.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Temp Presets-2.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
39 changes: 7 additions & 32 deletions Loop/DerivedAssetsBase.xcassets/settings.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "settings.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
},
{
"idiom" : "universal",
"scale" : "1x",
"height-class" : "compact"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"height-class" : "compact",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"height-class" : "compact",
"scale" : "3x"
"idiom" : "universal"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
}
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Loop/Extensions/ChartColorPalette+Loop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ import LoopKitUI

extension ChartColorPalette {
static var primary: ChartColorPalette {
return ChartColorPalette(axisLine: .axisLineColor, axisLabel: .axisLabelColor, grid: .gridColor, glucoseTint: .glucoseTintColor, insulinTint: .insulinTintColor, carbTint: .carbTintColor)
return ChartColorPalette(axisLine: .axisLineColor, axisLabel: .axisLabelColor, grid: .gridColor, presetTint: .presets, glucoseTint: .glucoseTintColor, insulinTint: .insulinTintColor, carbTint: .carbTintColor)
}
}
4 changes: 2 additions & 2 deletions Loop/Managers/ExtensionDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ final class ExtensionDataManager {
context.isClosedLoop = self.automaticDosingStatus.automaticDosingEnabled

context.preMealPresetAllowed = self.automaticDosingStatus.automaticDosingEnabled && self.settingsManager.settings.preMealTargetRange != nil
context.preMealPresetActive = self.temporaryPresetsManager.preMealTargetEnabled()
context.customPresetActive = self.temporaryPresetsManager.nonPreMealOverrideEnabled()
context.preMealPresetActive = self.temporaryPresetsManager.isPreMealTargetActive()
context.customPresetActive = self.temporaryPresetsManager.isNonPreMealOverrideActive()

// Drop the first element in predictedGlucose because it is the currentGlucose
// and will have a different interval to the next element
Expand Down
4 changes: 2 additions & 2 deletions Loop/Managers/LoopDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,8 @@ extension LoopDataManager: BolusEntryViewModelDelegate {


extension LoopDataManager: CarbEntryViewModelDelegate {
func scheduleOverrideEnabled(at date: Date) -> Bool {
temporaryPresetsManager.scheduleOverrideEnabled(at: date)
func isScheduleOverrideActive(at date: Date) -> Bool {
temporaryPresetsManager.isScheduleOverrideActive(at: date)
}

var defaultAbsorptionTimes: DefaultAbsorptionTimes {
Expand Down
46 changes: 35 additions & 11 deletions Loop/Managers/TemporaryPresetsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class TemporaryPresetsManager {
for observer in self.presetActivationObservers {
observer.presetActivated(context: newPreset.context, duration: newPreset.duration)
}

scheduleClearOverride(override: newPreset)
}
}

Expand All @@ -111,21 +113,42 @@ class TemporaryPresetsManager {
guard oldValue != preMealOverride else {
return
}

if let newValue = preMealOverride, newValue.context != .preMeal || newValue.settings.insulinNeedsScaleFactor != nil {
preconditionFailure("The `preMealOverride` field should be used only for a pre-meal target range override")
}

if preMealOverride != nil {
scheduleOverride = nil
}

overrideHistory.recordOverride(preMealOverride)

notify(forChange: .preferences)
}
}

public var activeOverride: TemporaryScheduleOverride? {
let override = (preMealOverride ?? scheduleOverride)
if override?.isActive() == true {
return override
} else {
return nil
}
}

var clearOverrideTimer: Timer?
public func scheduleClearOverride(override: TemporaryScheduleOverride) {
clearOverrideTimer?.invalidate()
clearOverrideTimer = Timer.scheduledTimer(withTimeInterval: override.scheduledEndDate.timeIntervalSince(Date()), repeats: false, block: { [weak self] _ in
if override == self?.scheduleOverride {
self?.clearOverride()
} else if override == self?.preMealOverride {
self?.clearOverride(matching: .preMeal)
}
})
}

public var isScheduleOverrideInfiniteWorkout: Bool {
guard let scheduleOverride = scheduleOverride else { return false }
return scheduleOverride.context == .legacyWorkout && scheduleOverride.duration.isInfinite
Expand All @@ -137,7 +160,7 @@ class TemporaryPresetsManager {
return nil
}

let preMealOverride = presumingMealEntry ? nil : self.preMealOverride
let preMealOverride = presumingMealEntry ? nil : (self.scheduleOverride?.context == .preMeal ? self.scheduleOverride : nil)

let currentEffectiveOverride: TemporaryScheduleOverride?
switch (preMealOverride, scheduleOverride) {
Expand All @@ -160,16 +183,16 @@ class TemporaryPresetsManager {
}
}

public func scheduleOverrideEnabled(at date: Date = Date()) -> Bool {
public func isScheduleOverrideActive(at date: Date = Date()) -> Bool {
return scheduleOverride?.isActive(at: date) == true
}

public func nonPreMealOverrideEnabled(at date: Date = Date()) -> Bool {
return scheduleOverride?.isActive(at: date) == true
public func isNonPreMealOverrideActive(at date: Date = Date()) -> Bool {
return isScheduleOverrideActive(at: date) == true && scheduleOverride?.context != .preMeal
}

public func preMealTargetEnabled(at date: Date = Date()) -> Bool {
return preMealOverride?.isActive(at: date) == true
public func isPreMealTargetActive(at date: Date = Date()) -> Bool {
return isScheduleOverrideActive(at: date) == true && scheduleOverride?.context == .preMeal
}

public func futureOverrideEnabled(relativeTo date: Date = Date()) -> Bool {
Expand All @@ -178,7 +201,7 @@ class TemporaryPresetsManager {
}

public func enablePreMealOverride(at date: Date = Date(), for duration: TimeInterval) {
preMealOverride = makePreMealOverride(beginningAt: date, for: duration)
scheduleOverride = makePreMealOverride(beginningAt: date, for: duration)
}

private func makePreMealOverride(beginningAt date: Date = Date(), for duration: TimeInterval) -> TemporaryScheduleOverride? {
Expand Down Expand Up @@ -275,6 +298,7 @@ class TemporaryPresetsManager {
}

self.scheduleOverride = scheduleOverride
self.scheduleClearOverride(override: scheduleOverride)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Loop/View Controllers/RootNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class RootNavigationController: UINavigationController {
case .carbEntry:
statusTableViewController.presentCarbEntryScreen(nil)
case .preMeal:
statusTableViewController.togglePreMealMode()
statusTableViewController.presentPresets()
case .bolus:
statusTableViewController.presentBolusScreen()
case .customPresets:
statusTableViewController.presentCustomPresets()
statusTableViewController.presentPresets()
}
}

Expand Down
Loading

0 comments on commit 19ca694

Please sign in to comment.