Просмотр исходного кода

Merge pull request #524 from MikePlante1/fat-protein

Align Fat/Protein order in TRC to Trio v0.6.0.51
Marion Barker 4 месяцев назад
Родитель
Сommit
88a399f017

+ 4 - 4
LoopFollow/Remote/Settings/RemoteSettingsView.swift

@@ -450,10 +450,10 @@ struct RemoteSettingsView: View {
 
             if device.value == "Trio" {
                 HStack {
-                    Text("Max Protein")
+                    Text("Max Fat")
                     Spacer()
                     TextFieldWithToolBar(
-                        quantity: $viewModel.maxProtein,
+                        quantity: $viewModel.maxFat,
                         maxLength: 4,
                         unit: HKUnit.gram(),
                         allowDecimalSeparator: true,
@@ -469,10 +469,10 @@ struct RemoteSettingsView: View {
                 }
 
                 HStack {
-                    Text("Max Fat")
+                    Text("Max Protein")
                     Spacer()
                     TextFieldWithToolBar(
-                        quantity: $viewModel.maxFat,
+                        quantity: $viewModel.maxProtein,
                         maxLength: 4,
                         unit: HKUnit.gram(),
                         allowDecimalSeparator: true,

+ 31 - 8
LoopFollow/Remote/TRC/MealView.swift

@@ -33,6 +33,7 @@ struct MealView: View {
     @State private var statusMessage: String? = nil
     @State private var selectedTime: Date? = nil
     @State private var isScheduling: Bool = false
+    @State private var showFatProteinOrderBanner = false
 
     enum AlertType {
         case confirmMeal
@@ -46,6 +47,24 @@ struct MealView: View {
             VStack {
                 Form {
                     Section(header: Text("Meal Data")) {
+                        // TODO: This banner can be deleted in March 2027. Check the commit for other places to cleanup.
+                        if showFatProteinOrderBanner {
+                            HStack {
+                                Image(systemName: "arrow.left.arrow.right")
+                                Text("The order of Fat and Protein inputs has changed.").font(.callout)
+                                Spacer()
+                                Button {
+                                    Storage.shared.hasSeenFatProteinOrderChange.value = true
+                                    withAnimation { showFatProteinOrderBanner = false }
+                                } label: {
+                                    Image(systemName: "xmark.circle.fill")
+                                }
+                                .buttonStyle(.plain)
+                            }
+                            .listRowBackground(Color.orange.opacity(0.75))
+                            .transition(.opacity)
+                        }
+
                         HKQuantityInputView(
                             label: "Carbs",
                             quantity: $carbs,
@@ -61,26 +80,26 @@ struct MealView: View {
 
                         if mealWithFatProtein.value {
                             HKQuantityInputView(
-                                label: "Protein",
-                                quantity: $protein,
+                                label: "Fat",
+                                quantity: $fat,
                                 unit: .gram(),
                                 maxLength: 4,
                                 minValue: HKQuantity(unit: .gram(), doubleValue: 0),
-                                maxValue: maxProtein.value,
-                                isFocused: $proteinFieldIsFocused,
+                                maxValue: maxFat.value,
+                                isFocused: $fatFieldIsFocused,
                                 onValidationError: { message in
                                     handleValidationError(message)
                                 }
                             )
 
                             HKQuantityInputView(
-                                label: "Fat",
-                                quantity: $fat,
+                                label: "Protein",
+                                quantity: $protein,
                                 unit: .gram(),
                                 maxLength: 4,
                                 minValue: HKQuantity(unit: .gram(), doubleValue: 0),
-                                maxValue: maxFat.value,
-                                isFocused: $fatFieldIsFocused,
+                                maxValue: maxProtein.value,
+                                isFocused: $proteinFieldIsFocused,
                                 onValidationError: { message in
                                     handleValidationError(message)
                                 }
@@ -153,6 +172,10 @@ struct MealView: View {
             .onAppear {
                 selectedTime = nil
                 isScheduling = false
+
+                if !Storage.shared.hasSeenFatProteinOrderChange.value && Storage.shared.mealWithFatProtein.value {
+                    showFatProteinOrderBanner = true
+                }
             }
             .alert(isPresented: $showAlert) {
                 switch alertType {

+ 3 - 0
LoopFollow/Storage/Storage.swift

@@ -29,6 +29,9 @@ class Storage {
     var mealWithBolus = StorageValue<Bool>(key: "mealWithBolus", defaultValue: false)
     var mealWithFatProtein = StorageValue<Bool>(key: "mealWithFatProtein", defaultValue: false)
 
+    // TODO: This flag can be deleted in March 2027. Check the commit for other places to cleanup.
+    var hasSeenFatProteinOrderChange = StorageValue<Bool>(key: "hasSeenFatProteinOrderChange", defaultValue: false)
+
     var cachedJWT = StorageValue<String?>(key: "cachedJWT", defaultValue: nil)
     var jwtExpirationDate = StorageValue<Date?>(key: "jwtExpirationDate", defaultValue: nil)
 

+ 11 - 0
LoopFollow/ViewControllers/MainViewController.swift

@@ -142,6 +142,9 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
 
         loadDebugData()
 
+        // Capture before migrations run: true for existing users, false for fresh installs.
+        let isExistingUser = Storage.shared.migrationStep.exists
+
         if Storage.shared.migrationStep.value < 1 {
             Storage.shared.migrateStep1()
             Storage.shared.migrationStep.value = 1
@@ -157,6 +160,14 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
             Storage.shared.migrationStep.value = 3
         }
 
+        // TODO: This migration step can be deleted in March 2027. Check the commit for other places to cleanup.
+        if Storage.shared.migrationStep.value < 4 {
+            // Existing users need to see the fat/protein order change banner.
+            // New users never saw the old order, so mark it as already seen.
+            Storage.shared.hasSeenFatProteinOrderChange.value = !isExistingUser
+            Storage.shared.migrationStep.value = 4
+        }
+
         // Synchronize info types to ensure arrays are the correct size
         synchronizeInfoTypes()