Skip to content

Commit dc1e669

Browse files
committed
Add Fat/Protein order change banner and flag
Introduce a persisted flag (hasSeenFatProteinOrderChange) to track whether the user has acknowledged that the order of Fat and Protein inputs changed. Show a dismissible banner in TreatmentsRootView when the flag is unset, and mark the flag when dismissed. Set the flag during onboarding completion so new users won't see the banner. Add the new flag to FileProtectionFixer cleanup list and add a localization key for the banner text. Can be removed after 1 year (March 2027).
1 parent 09472ec commit dc1e669

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

Trio/Sources/Helpers/PropertyPersistentFlags.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ final class PropertyPersistentFlags {
2323
@PersistedProperty(key: "diagnosticsSharing") var diagnosticsSharingEnabled: Bool?
2424

2525
@PersistedProperty(key: "lastCleanupDate") var lastCleanupDate: Date?
26+
27+
// TODO: This flag can be deleted in March 2027. Check the commit for other places to cleanup.
28+
@PersistedProperty(key: "hasSeenFatProteinOrderChange") var hasSeenFatProteinOrderChange: Bool?
2629
}

Trio/Sources/Helpers/PropertyWrappers/PersistedProperty.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ enum FileProtectionFixer {
122122
let flagFiles = [
123123
"onboardingCompleted.plist",
124124
"diagnosticsSharing.plist",
125-
"lastCleanupDate.plist"
125+
"lastCleanupDate.plist",
126+
"hasSeenFatProteinOrderChange.plist"
126127
]
127128

128129
let fileManager = FileManager.default

Trio/Sources/Localizations/Main/Localizable.xcstrings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230207,6 +230207,9 @@
230207230207
}
230208230208
}
230209230209
}
230210+
},
230211+
"The order of Fat and Protein inputs has changed." : {
230212+
230210230213
},
230211230214
"The oref algorithm determines insulin dosing based on a number of scenarios that it estimates with different types of forecasts." : {
230212230215
"localizations" : {

Trio/Sources/Modules/Treatments/View/TreatmentsRootView.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extension Treatments {
2424
@State private var calculatorDetent = PresentationDetent.large
2525
@State private var pushed: Bool = false
2626
@State private var debounce: DispatchWorkItem?
27+
@State private var showFatProteinOrderBanner = false
2728

2829
private enum Config {
2930
static let dividerHeight: CGFloat = 2
@@ -198,6 +199,23 @@ extension Treatments {
198199

199200
if state.useFPUconversion {
200201
proteinAndFat()
202+
203+
if showFatProteinOrderBanner {
204+
HStack {
205+
Image(systemName: "arrow.left.arrow.right")
206+
Text("The order of Fat and Protein inputs has changed.").font(.callout)
207+
Spacer()
208+
Button {
209+
PropertyPersistentFlags.shared.hasSeenFatProteinOrderChange = true
210+
withAnimation { showFatProteinOrderBanner = false }
211+
} label: {
212+
Image(systemName: "xmark.circle.fill")
213+
}
214+
.buttonStyle(.plain)
215+
}
216+
.listRowBackground(Color.orange.opacity(0.75))
217+
.transition(.opacity)
218+
}
201219
}
202220

203221
// Time
@@ -391,6 +409,10 @@ extension Treatments {
391409
Task { @MainActor in
392410
state.insulinCalculated = await state.calculateInsulin()
393411
}
412+
413+
if PropertyPersistentFlags.shared.hasSeenFatProteinOrderChange != true {
414+
showFatProteinOrderBanner = true
415+
}
394416
}
395417
}
396418
.onDisappear {

Trio/Sources/Services/OnboardingManager/OnboardingManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Swinject
2424
/// Marks onboarding as completed and updates the shouldShowOnboarding flag.
2525
func completeOnboarding() {
2626
PropertyPersistentFlags.shared.onboardingCompleted = true
27+
PropertyPersistentFlags.shared.hasSeenFatProteinOrderChange = true
2728
shouldShowOnboarding = false
2829
}
2930

0 commit comments

Comments
 (0)