Skip to content

Commit 88a399f

Browse files
authored
Merge pull request #524 from MikePlante1/fat-protein
Align Fat/Protein order in TRC to Trio v0.6.0.51
2 parents dde04cd + 9fa0c0a commit 88a399f

4 files changed

Lines changed: 49 additions & 12 deletions

File tree

LoopFollow/Remote/Settings/RemoteSettingsView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,10 @@ struct RemoteSettingsView: View {
450450

451451
if device.value == "Trio" {
452452
HStack {
453-
Text("Max Protein")
453+
Text("Max Fat")
454454
Spacer()
455455
TextFieldWithToolBar(
456-
quantity: $viewModel.maxProtein,
456+
quantity: $viewModel.maxFat,
457457
maxLength: 4,
458458
unit: HKUnit.gram(),
459459
allowDecimalSeparator: true,
@@ -469,10 +469,10 @@ struct RemoteSettingsView: View {
469469
}
470470

471471
HStack {
472-
Text("Max Fat")
472+
Text("Max Protein")
473473
Spacer()
474474
TextFieldWithToolBar(
475-
quantity: $viewModel.maxFat,
475+
quantity: $viewModel.maxProtein,
476476
maxLength: 4,
477477
unit: HKUnit.gram(),
478478
allowDecimalSeparator: true,

LoopFollow/Remote/TRC/MealView.swift

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct MealView: View {
3333
@State private var statusMessage: String? = nil
3434
@State private var selectedTime: Date? = nil
3535
@State private var isScheduling: Bool = false
36+
@State private var showFatProteinOrderBanner = false
3637

3738
enum AlertType {
3839
case confirmMeal
@@ -46,6 +47,24 @@ struct MealView: View {
4647
VStack {
4748
Form {
4849
Section(header: Text("Meal Data")) {
50+
// TODO: This banner can be deleted in March 2027. Check the commit for other places to cleanup.
51+
if showFatProteinOrderBanner {
52+
HStack {
53+
Image(systemName: "arrow.left.arrow.right")
54+
Text("The order of Fat and Protein inputs has changed.").font(.callout)
55+
Spacer()
56+
Button {
57+
Storage.shared.hasSeenFatProteinOrderChange.value = true
58+
withAnimation { showFatProteinOrderBanner = false }
59+
} label: {
60+
Image(systemName: "xmark.circle.fill")
61+
}
62+
.buttonStyle(.plain)
63+
}
64+
.listRowBackground(Color.orange.opacity(0.75))
65+
.transition(.opacity)
66+
}
67+
4968
HKQuantityInputView(
5069
label: "Carbs",
5170
quantity: $carbs,
@@ -61,26 +80,26 @@ struct MealView: View {
6180

6281
if mealWithFatProtein.value {
6382
HKQuantityInputView(
64-
label: "Protein",
65-
quantity: $protein,
83+
label: "Fat",
84+
quantity: $fat,
6685
unit: .gram(),
6786
maxLength: 4,
6887
minValue: HKQuantity(unit: .gram(), doubleValue: 0),
69-
maxValue: maxProtein.value,
70-
isFocused: $proteinFieldIsFocused,
88+
maxValue: maxFat.value,
89+
isFocused: $fatFieldIsFocused,
7190
onValidationError: { message in
7291
handleValidationError(message)
7392
}
7493
)
7594

7695
HKQuantityInputView(
77-
label: "Fat",
78-
quantity: $fat,
96+
label: "Protein",
97+
quantity: $protein,
7998
unit: .gram(),
8099
maxLength: 4,
81100
minValue: HKQuantity(unit: .gram(), doubleValue: 0),
82-
maxValue: maxFat.value,
83-
isFocused: $fatFieldIsFocused,
101+
maxValue: maxProtein.value,
102+
isFocused: $proteinFieldIsFocused,
84103
onValidationError: { message in
85104
handleValidationError(message)
86105
}
@@ -153,6 +172,10 @@ struct MealView: View {
153172
.onAppear {
154173
selectedTime = nil
155174
isScheduling = false
175+
176+
if !Storage.shared.hasSeenFatProteinOrderChange.value && Storage.shared.mealWithFatProtein.value {
177+
showFatProteinOrderBanner = true
178+
}
156179
}
157180
.alert(isPresented: $showAlert) {
158181
switch alertType {

LoopFollow/Storage/Storage.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class Storage {
2929
var mealWithBolus = StorageValue<Bool>(key: "mealWithBolus", defaultValue: false)
3030
var mealWithFatProtein = StorageValue<Bool>(key: "mealWithFatProtein", defaultValue: false)
3131

32+
// TODO: This flag can be deleted in March 2027. Check the commit for other places to cleanup.
33+
var hasSeenFatProteinOrderChange = StorageValue<Bool>(key: "hasSeenFatProteinOrderChange", defaultValue: false)
34+
3235
var cachedJWT = StorageValue<String?>(key: "cachedJWT", defaultValue: nil)
3336
var jwtExpirationDate = StorageValue<Date?>(key: "jwtExpirationDate", defaultValue: nil)
3437

LoopFollow/ViewControllers/MainViewController.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
142142

143143
loadDebugData()
144144

145+
// Capture before migrations run: true for existing users, false for fresh installs.
146+
let isExistingUser = Storage.shared.migrationStep.exists
147+
145148
if Storage.shared.migrationStep.value < 1 {
146149
Storage.shared.migrateStep1()
147150
Storage.shared.migrationStep.value = 1
@@ -157,6 +160,14 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
157160
Storage.shared.migrationStep.value = 3
158161
}
159162

163+
// TODO: This migration step can be deleted in March 2027. Check the commit for other places to cleanup.
164+
if Storage.shared.migrationStep.value < 4 {
165+
// Existing users need to see the fat/protein order change banner.
166+
// New users never saw the old order, so mark it as already seen.
167+
Storage.shared.hasSeenFatProteinOrderChange.value = !isExistingUser
168+
Storage.shared.migrationStep.value = 4
169+
}
170+
160171
// Synchronize info types to ensure arrays are the correct size
161172
synchronizeInfoTypes()
162173

0 commit comments

Comments
 (0)