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

Merge pull request #973 from MikePlante1/fat-protein

Align the order of Fat and Protein throughout the app
Deniz Cengiz 3 месяцев назад
Родитель
Сommit
06e62f50b0

+ 12 - 0
Trio/Resources/InfoPlist.xcstrings

@@ -457,6 +457,18 @@
         }
       }
     },
+    "NSCalendarsFullAccessUsageDescription" : {
+      "comment" : "Privacy - Calendars Full Access Usage Description",
+      "extractionState" : "extracted_with_value",
+      "localizations" : {
+        "en" : {
+          "stringUnit" : {
+            "state" : "new",
+            "value" : "To create events with BG reading values, so that they can be viewed on Apple Watch and CarPlay"
+          }
+        }
+      }
+    },
     "NSCalendarsUsageDescription" : {
       "comment" : "Privacy - Calendars Usage Description",
       "extractionState" : "extracted_with_value",

+ 3 - 0
Trio/Sources/Helpers/PropertyPersistentFlags.swift

@@ -23,4 +23,7 @@ final class PropertyPersistentFlags {
     @PersistedProperty(key: "diagnosticsSharing") var diagnosticsSharingEnabled: Bool?
 
     @PersistedProperty(key: "lastCleanupDate") var lastCleanupDate: Date?
+
+    // TODO: This flag can be deleted in March 2027. Check the commit for other places to cleanup.
+    @PersistedProperty(key: "hasSeenFatProteinOrderChange") var hasSeenFatProteinOrderChange: Bool?
 }

+ 2 - 1
Trio/Sources/Helpers/PropertyWrappers/PersistedProperty.swift

@@ -122,7 +122,8 @@ enum FileProtectionFixer {
         let flagFiles = [
             "onboardingCompleted.plist",
             "diagnosticsSharing.plist",
-            "lastCleanupDate.plist"
+            "lastCleanupDate.plist",
+            "hasSeenFatProteinOrderChange.plist"
         ]
 
         let fileManager = FileManager.default

+ 3 - 0
Trio/Sources/Localizations/Main/Localizable.xcstrings

@@ -230208,6 +230208,9 @@
         }
       }
     },
+    "The order of Fat and Protein inputs has changed." : {
+
+    },
     "The oref algorithm determines insulin dosing based on a number of scenarios that it estimates with different types of forecasts." : {
       "localizations" : {
         "bg" : {

+ 4 - 4
Trio/Sources/Modules/History/View/CarbEntryEditorView.swift

@@ -145,9 +145,9 @@ struct CarbEntryEditorView: View {
 
                     if state.settingsManager.settings.useFPUconversion {
                         HStack {
-                            Text("Protein")
+                            Text("Fat")
                             TextFieldWithToolBar(
-                                text: $editedProtein,
+                                text: $editedFat,
                                 placeholder: "0",
                                 keyboardType: .numberPad,
                                 numberFormatter: mealFormatter,
@@ -156,9 +156,9 @@ struct CarbEntryEditorView: View {
                         }
 
                         HStack {
-                            Text("Fat")
+                            Text("Protein")
                             TextFieldWithToolBar(
-                                text: $editedFat,
+                                text: $editedProtein,
                                 placeholder: "0",
                                 keyboardType: .numberPad,
                                 numberFormatter: mealFormatter,

+ 14 - 14
Trio/Sources/Modules/MealSettings/View/MealSettingsRootView.swift

@@ -81,26 +81,26 @@ extension MealSettings {
                             if state.useFPUconversion {
                                 VStack {
                                     HStack {
-                                        Text("Max Protein")
+                                        Text("Max Fat")
 
                                         Spacer()
 
                                         Group {
-                                            Text(state.maxProtein.description)
-                                                .foregroundColor(!displayPickerMaxProtein ? .primary : .accentColor)
+                                            Text(state.maxFat.description)
+                                                .foregroundColor(!displayPickerMaxFat ? .primary : .accentColor)
 
                                             Text(" g").foregroundColor(.secondary)
                                         }
                                     }
                                     .onTapGesture {
-                                        displayPickerMaxProtein.toggle()
+                                        displayPickerMaxFat.toggle()
                                     }
                                 }
                                 .padding(.top)
 
-                                if displayPickerMaxProtein {
-                                    let setting = PickerSettingsProvider.shared.settings.maxProtein
-                                    Picker(selection: $state.maxProtein, label: Text("")) {
+                                if displayPickerMaxFat {
+                                    let setting = PickerSettingsProvider.shared.settings.maxFat
+                                    Picker(selection: $state.maxFat, label: Text("")) {
                                         ForEach(
                                             PickerSettingsProvider.shared.generatePickerValues(from: setting, units: state.units),
                                             id: \.self
@@ -114,26 +114,26 @@ extension MealSettings {
 
                                 VStack {
                                     HStack {
-                                        Text("Max Fat")
+                                        Text("Max Protein")
 
                                         Spacer()
 
                                         Group {
-                                            Text(state.maxFat.description)
-                                                .foregroundColor(!displayPickerMaxFat ? .primary : .accentColor)
+                                            Text(state.maxProtein.description)
+                                                .foregroundColor(!displayPickerMaxProtein ? .primary : .accentColor)
 
                                             Text(" g").foregroundColor(.secondary)
                                         }
                                     }
                                     .onTapGesture {
-                                        displayPickerMaxFat.toggle()
+                                        displayPickerMaxProtein.toggle()
                                     }
                                 }
                                 .padding(.top)
 
-                                if displayPickerMaxFat {
-                                    let setting = PickerSettingsProvider.shared.settings.maxFat
-                                    Picker(selection: $state.maxFat, label: Text("")) {
+                                if displayPickerMaxProtein {
+                                    let setting = PickerSettingsProvider.shared.settings.maxProtein
+                                    Picker(selection: $state.maxProtein, label: Text("")) {
                                         ForEach(
                                             PickerSettingsProvider.shared.generatePickerValues(from: setting, units: state.units),
                                             id: \.self

+ 4 - 4
Trio/Sources/Modules/Stat/View/ViewElements/Meal/MealStatsView.swift

@@ -205,14 +205,14 @@ struct MealStatsView: View {
         }
         .chartForegroundStyleScale([
             "Carbs": Color.orange,
-            "Protein": Color.blue,
-            "Fat": Color.purple
+            "Fat": Color.purple,
+            "Protein": Color.blue
         ])
         .chartLegend(position: .bottom, alignment: .leading, spacing: 12) {
             let legendItems: [(String, Color)] = state.useFPUconversion ? [
                 (String(localized: "Carbs"), Color.orange),
-                (String(localized: "Protein"), Color.blue),
-                (String(localized: "Fat"), Color.purple)
+                (String(localized: "Fat"), Color.purple),
+                (String(localized: "Protein"), Color.blue)
             ] : [(String(localized: "Carbs"), Color.orange)]
 
             let columns = [GridItem(.adaptive(minimum: 65), spacing: 4)]

+ 4 - 4
Trio/Sources/Modules/Treatments/View/MealPreset/AddMealPresetView.swift

@@ -83,10 +83,10 @@ struct AddMealPresetView: View {
 
     @ViewBuilder private func proteinAndFat() -> some View {
         HStack {
-            Text("Protein").foregroundColor(.red)
+            Text("Fat").foregroundColor(.orange)
             Spacer()
             TextFieldWithToolBar(
-                text: $presetProtein,
+                text: $presetFat,
                 placeholder: "0",
                 keyboardType: .numberPad,
                 numberFormatter: mealFormatter,
@@ -94,10 +94,10 @@ struct AddMealPresetView: View {
             )
         }
         HStack {
-            Text("Fat").foregroundColor(.orange)
+            Text("Protein").foregroundColor(.red)
             Spacer()
             TextFieldWithToolBar(
-                text: $presetFat,
+                text: $presetProtein,
                 placeholder: "0",
                 keyboardType: .numberPad,
                 numberFormatter: mealFormatter,

+ 32 - 10
Trio/Sources/Modules/Treatments/View/TreatmentsRootView.swift

@@ -24,6 +24,7 @@ extension Treatments {
         @State private var calculatorDetent = PresentationDetent.large
         @State private var pushed: Bool = false
         @State private var debounce: DispatchWorkItem?
+        @State private var showFatProteinOrderBanner = false
 
         private enum Config {
             static let dividerHeight: CGFloat = 2
@@ -85,35 +86,35 @@ extension Treatments {
         @ViewBuilder private func proteinAndFat() -> some View {
             HStack {
                 HStack {
-                    Text("Protein")
+                    Text("Fat")
                     TextFieldWithToolBar(
-                        text: $state.protein,
+                        text: $state.fat,
                         placeholder: "0",
                         keyboardType: .numberPad,
                         numberFormatter: mealFormatter,
                         showArrows: true,
-                        previousTextField: { focusedField = previousField(from: .protein) },
-                        nextTextField: { focusedField = nextField(from: .protein) },
+                        previousTextField: { focusedField = previousField(from: .fat) },
+                        nextTextField: { focusedField = nextField(from: .fat) },
                         unitsText: String(localized: "g", comment: "Units for carbs")
                     )
-                    .focused($focusedField, equals: .protein)
+                    .focused($focusedField, equals: .fat)
                 }
 
                 Divider().foregroundStyle(.primary).fontWeight(.bold).frame(width: 10)
 
                 HStack {
-                    Text("Fat")
+                    Text("Protein")
                     TextFieldWithToolBar(
-                        text: $state.fat,
+                        text: $state.protein,
                         placeholder: "0",
                         keyboardType: .numberPad,
                         numberFormatter: mealFormatter,
                         showArrows: true,
-                        previousTextField: { focusedField = previousField(from: .fat) },
-                        nextTextField: { focusedField = nextField(from: .fat) },
+                        previousTextField: { focusedField = previousField(from: .protein) },
+                        nextTextField: { focusedField = nextField(from: .protein) },
                         unitsText: String(localized: "g", comment: "Units for carbs")
                     )
-                    .focused($focusedField, equals: .fat)
+                    .focused($focusedField, equals: .protein)
                 }
             }
         }
@@ -198,6 +199,23 @@ extension Treatments {
 
                             if state.useFPUconversion {
                                 proteinAndFat()
+
+                                if showFatProteinOrderBanner {
+                                    HStack {
+                                        Image(systemName: "arrow.left.arrow.right")
+                                        Text("The order of Fat and Protein inputs has changed.").font(.callout)
+                                        Spacer()
+                                        Button {
+                                            PropertyPersistentFlags.shared.hasSeenFatProteinOrderChange = true
+                                            withAnimation { showFatProteinOrderBanner = false }
+                                        } label: {
+                                            Image(systemName: "xmark.circle.fill")
+                                        }
+                                        .buttonStyle(.plain)
+                                    }
+                                    .listRowBackground(Color.orange.opacity(0.75))
+                                    .transition(.opacity)
+                                }
                             }
 
                             // Time
@@ -391,6 +409,10 @@ extension Treatments {
                     Task { @MainActor in
                         state.insulinCalculated = await state.calculateInsulin()
                     }
+
+                    if PropertyPersistentFlags.shared.hasSeenFatProteinOrderChange != true {
+                        showFatProteinOrderBanner = true
+                    }
                 }
             }
             .onDisappear {

+ 1 - 0
Trio/Sources/Services/OnboardingManager/OnboardingManager.swift

@@ -24,6 +24,7 @@ import Swinject
     /// Marks onboarding as completed and updates the shouldShowOnboarding flag.
     func completeOnboarding() {
         PropertyPersistentFlags.shared.onboardingCompleted = true
+        PropertyPersistentFlags.shared.hasSeenFatProteinOrderChange = true
         shouldShowOnboarding = false
     }
 

+ 1 - 1
Trio/Sources/Services/WatchManager/AppleWatchManager.swift

@@ -326,7 +326,7 @@ final class BaseWatchManager: NSObject, WCSessionDelegate, Injectable, WatchMana
                         glucoseLast = glucoseLast.asMmolL
                         glucoseSecondLast = glucoseSecondLast.asMmolL
                     }
-                    
+
                     let deltaValue = glucoseLast - glucoseSecondLast
                     let formattedDelta = Formatter.glucoseFormatter(for: self.units)
                         .string(from: deltaValue as NSNumber) ?? "0"