Skip to content

Commit 06e62f5

Browse files
authored
Merge pull request #973 from MikePlante1/fat-protein
Align the order of Fat and Protein throughout the app
2 parents d1bee89 + 04ad04d commit 06e62f5

File tree

11 files changed

+80
-38
lines changed

11 files changed

+80
-38
lines changed

Trio/Resources/InfoPlist.xcstrings

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,18 @@
457457
}
458458
}
459459
},
460+
"NSCalendarsFullAccessUsageDescription" : {
461+
"comment" : "Privacy - Calendars Full Access Usage Description",
462+
"extractionState" : "extracted_with_value",
463+
"localizations" : {
464+
"en" : {
465+
"stringUnit" : {
466+
"state" : "new",
467+
"value" : "To create events with BG reading values, so that they can be viewed on Apple Watch and CarPlay"
468+
}
469+
}
470+
}
471+
},
460472
"NSCalendarsUsageDescription" : {
461473
"comment" : "Privacy - Calendars Usage Description",
462474
"extractionState" : "extracted_with_value",

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/History/View/CarbEntryEditorView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ struct CarbEntryEditorView: View {
145145

146146
if state.settingsManager.settings.useFPUconversion {
147147
HStack {
148-
Text("Protein")
148+
Text("Fat")
149149
TextFieldWithToolBar(
150-
text: $editedProtein,
150+
text: $editedFat,
151151
placeholder: "0",
152152
keyboardType: .numberPad,
153153
numberFormatter: mealFormatter,
@@ -156,9 +156,9 @@ struct CarbEntryEditorView: View {
156156
}
157157

158158
HStack {
159-
Text("Fat")
159+
Text("Protein")
160160
TextFieldWithToolBar(
161-
text: $editedFat,
161+
text: $editedProtein,
162162
placeholder: "0",
163163
keyboardType: .numberPad,
164164
numberFormatter: mealFormatter,

Trio/Sources/Modules/MealSettings/View/MealSettingsRootView.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,26 @@ extension MealSettings {
8181
if state.useFPUconversion {
8282
VStack {
8383
HStack {
84-
Text("Max Protein")
84+
Text("Max Fat")
8585

8686
Spacer()
8787

8888
Group {
89-
Text(state.maxProtein.description)
90-
.foregroundColor(!displayPickerMaxProtein ? .primary : .accentColor)
89+
Text(state.maxFat.description)
90+
.foregroundColor(!displayPickerMaxFat ? .primary : .accentColor)
9191

9292
Text(" g").foregroundColor(.secondary)
9393
}
9494
}
9595
.onTapGesture {
96-
displayPickerMaxProtein.toggle()
96+
displayPickerMaxFat.toggle()
9797
}
9898
}
9999
.padding(.top)
100100

101-
if displayPickerMaxProtein {
102-
let setting = PickerSettingsProvider.shared.settings.maxProtein
103-
Picker(selection: $state.maxProtein, label: Text("")) {
101+
if displayPickerMaxFat {
102+
let setting = PickerSettingsProvider.shared.settings.maxFat
103+
Picker(selection: $state.maxFat, label: Text("")) {
104104
ForEach(
105105
PickerSettingsProvider.shared.generatePickerValues(from: setting, units: state.units),
106106
id: \.self
@@ -114,26 +114,26 @@ extension MealSettings {
114114

115115
VStack {
116116
HStack {
117-
Text("Max Fat")
117+
Text("Max Protein")
118118

119119
Spacer()
120120

121121
Group {
122-
Text(state.maxFat.description)
123-
.foregroundColor(!displayPickerMaxFat ? .primary : .accentColor)
122+
Text(state.maxProtein.description)
123+
.foregroundColor(!displayPickerMaxProtein ? .primary : .accentColor)
124124

125125
Text(" g").foregroundColor(.secondary)
126126
}
127127
}
128128
.onTapGesture {
129-
displayPickerMaxFat.toggle()
129+
displayPickerMaxProtein.toggle()
130130
}
131131
}
132132
.padding(.top)
133133

134-
if displayPickerMaxFat {
135-
let setting = PickerSettingsProvider.shared.settings.maxFat
136-
Picker(selection: $state.maxFat, label: Text("")) {
134+
if displayPickerMaxProtein {
135+
let setting = PickerSettingsProvider.shared.settings.maxProtein
136+
Picker(selection: $state.maxProtein, label: Text("")) {
137137
ForEach(
138138
PickerSettingsProvider.shared.generatePickerValues(from: setting, units: state.units),
139139
id: \.self

Trio/Sources/Modules/Stat/View/ViewElements/Meal/MealStatsView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,14 @@ struct MealStatsView: View {
205205
}
206206
.chartForegroundStyleScale([
207207
"Carbs": Color.orange,
208-
"Protein": Color.blue,
209-
"Fat": Color.purple
208+
"Fat": Color.purple,
209+
"Protein": Color.blue
210210
])
211211
.chartLegend(position: .bottom, alignment: .leading, spacing: 12) {
212212
let legendItems: [(String, Color)] = state.useFPUconversion ? [
213213
(String(localized: "Carbs"), Color.orange),
214-
(String(localized: "Protein"), Color.blue),
215-
(String(localized: "Fat"), Color.purple)
214+
(String(localized: "Fat"), Color.purple),
215+
(String(localized: "Protein"), Color.blue)
216216
] : [(String(localized: "Carbs"), Color.orange)]
217217

218218
let columns = [GridItem(.adaptive(minimum: 65), spacing: 4)]

Trio/Sources/Modules/Treatments/View/MealPreset/AddMealPresetView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,21 @@ struct AddMealPresetView: View {
8383

8484
@ViewBuilder private func proteinAndFat() -> some View {
8585
HStack {
86-
Text("Protein").foregroundColor(.red)
86+
Text("Fat").foregroundColor(.orange)
8787
Spacer()
8888
TextFieldWithToolBar(
89-
text: $presetProtein,
89+
text: $presetFat,
9090
placeholder: "0",
9191
keyboardType: .numberPad,
9292
numberFormatter: mealFormatter,
9393
unitsText: String(localized: "g", comment: "Units for carbs")
9494
)
9595
}
9696
HStack {
97-
Text("Fat").foregroundColor(.orange)
97+
Text("Protein").foregroundColor(.red)
9898
Spacer()
9999
TextFieldWithToolBar(
100-
text: $presetFat,
100+
text: $presetProtein,
101101
placeholder: "0",
102102
keyboardType: .numberPad,
103103
numberFormatter: mealFormatter,

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

Lines changed: 32 additions & 10 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
@@ -85,35 +86,35 @@ extension Treatments {
8586
@ViewBuilder private func proteinAndFat() -> some View {
8687
HStack {
8788
HStack {
88-
Text("Protein")
89+
Text("Fat")
8990
TextFieldWithToolBar(
90-
text: $state.protein,
91+
text: $state.fat,
9192
placeholder: "0",
9293
keyboardType: .numberPad,
9394
numberFormatter: mealFormatter,
9495
showArrows: true,
95-
previousTextField: { focusedField = previousField(from: .protein) },
96-
nextTextField: { focusedField = nextField(from: .protein) },
96+
previousTextField: { focusedField = previousField(from: .fat) },
97+
nextTextField: { focusedField = nextField(from: .fat) },
9798
unitsText: String(localized: "g", comment: "Units for carbs")
9899
)
99-
.focused($focusedField, equals: .protein)
100+
.focused($focusedField, equals: .fat)
100101
}
101102

102103
Divider().foregroundStyle(.primary).fontWeight(.bold).frame(width: 10)
103104

104105
HStack {
105-
Text("Fat")
106+
Text("Protein")
106107
TextFieldWithToolBar(
107-
text: $state.fat,
108+
text: $state.protein,
108109
placeholder: "0",
109110
keyboardType: .numberPad,
110111
numberFormatter: mealFormatter,
111112
showArrows: true,
112-
previousTextField: { focusedField = previousField(from: .fat) },
113-
nextTextField: { focusedField = nextField(from: .fat) },
113+
previousTextField: { focusedField = previousField(from: .protein) },
114+
nextTextField: { focusedField = nextField(from: .protein) },
114115
unitsText: String(localized: "g", comment: "Units for carbs")
115116
)
116-
.focused($focusedField, equals: .fat)
117+
.focused($focusedField, equals: .protein)
117118
}
118119
}
119120
}
@@ -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)