Bläddra i källkod

Use Fat / Protein Toggle in Add Carbs View. A new UX test.

Jon Mårtensson 3 år sedan
förälder
incheckning
128aebf62e

+ 3 - 3
FreeAPS/Sources/Modules/AddCarbs/AddCarbsStateModel.swift

@@ -12,7 +12,7 @@ extension AddCarbs {
         @Published var protein: Decimal = 0
         @Published var fat: Decimal = 0
         @Published var carbsRequired: Decimal?
-        @Published var useFPU: Bool = true
+        @Published var useFPUconversion: Bool = true
         @Published var dish: String = ""
         @Published var selection: Presets?
         @Published var summation: [String] = []
@@ -21,8 +21,8 @@ extension AddCarbs {
         // @Environment(\.managedObjectContext) var moc
 
         override func subscribe() {
+            subscribeSetting(\.useFPUconversion, on: $useFPUconversion) { useFPUconversion = $0 }
             carbsRequired = provider.suggestion?.carbsReq
-            useFPU = settingsManager.settings.useFPUconversion
         }
 
         func add() {
@@ -31,7 +31,7 @@ extension AddCarbs {
                 return
             }
 
-            if useFPU {
+            if useFPUconversion {
                 // -------------------------- FPU--------------------------------------
                 let interval = settings.settings.minuteInterval // Interval betwwen carbs
                 let timeCap = settings.settings.timeCap // Max Duration

+ 38 - 24
FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift

@@ -36,7 +36,6 @@ extension AddCarbs {
                         }
                     }
                 }
-
                 Section {
                     HStack {
                         Text("Carbs").fontWeight(.semibold)
@@ -51,34 +50,49 @@ extension AddCarbs {
                         Text("grams").foregroundColor(.secondary)
                     }.padding(.vertical)
 
-                    if state.useFPU {
+                    if state.useFPUconversion {
                         proteinAndFat()
                     }
                     HStack {
                         Button {
+                            state.useFPUconversion.toggle()
+                        }
+                        label: { Text(state.useFPUconversion ? "Hide Fat & Protein" : "Fat and Protein") }
+                            .controlSize(.mini)
+                            .buttonStyle(BorderlessButtonStyle())
+                        Button {
                             isPromtPresented = true
                         }
                         label: { Text("Save as Preset") }
-                    }
-                    .frame(maxWidth: .infinity, alignment: .trailing)
-                    .controlSize(.mini)
-                    .buttonStyle(BorderlessButtonStyle())
-
-                    .disabled(
-                        (state.carbs <= 0 && state.fat <= 0 && state.protein <= 0) ||
-                            (
-                                (((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal) == state
-                                    .carbs && (((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal) == state
-                                    .fat && (((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal) == state
-                                    .protein
+                            .frame(maxWidth: .infinity, alignment: .trailing)
+                            .controlSize(.mini)
+                            .buttonStyle(BorderlessButtonStyle())
+                            .foregroundColor(
+                                (state.carbs <= 0 && state.fat <= 0 && state.protein <= 0) ||
+                                    (
+                                        (((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal) == state
+                                            .carbs && (((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal) == state
+                                            .fat && (((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal) ==
+                                            state
+                                            .protein
+                                    ) ? .secondary : .orange
                             )
-                    )
+                            .disabled(
+                                (state.carbs <= 0 && state.fat <= 0 && state.protein <= 0) ||
+                                    (
+                                        (((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal) == state
+                                            .carbs && (((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal) == state
+                                            .fat && (((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal) == state
+                                            .protein
+                                    )
+                            )
+                    }
                     .popover(isPresented: $isPromtPresented) {
                         presetPopover
                     }
                 }
 
-                if state.useFPU {
+                if state.useFPUconversion {
                     Section {
                         mealPresets
                     }
@@ -95,7 +109,7 @@ extension AddCarbs {
                         .frame(maxWidth: .infinity, alignment: .center)
                 }
 
-                if !state.useFPU {
+                if !state.useFPUconversion {
                     Section {
                         mealPresets
                     }
@@ -223,28 +237,28 @@ extension AddCarbs {
 
         @ViewBuilder private func proteinAndFat() -> some View {
             HStack {
-                Text("Protein").foregroundColor(.red) // .fontWeight(.thin)
+                Text("Fat").foregroundColor(.orange) // .fontWeight(.thin)
                 Spacer()
                 DecimalTextField(
                     "0",
-                    value: $state.protein,
+                    value: $state.fat,
                     formatter: formatter,
                     autofocus: false,
                     cleanInput: true
-                ).foregroundColor(.loopRed)
-
+                )
                 Text("grams").foregroundColor(.secondary)
             }
             HStack {
-                Text("Fat").foregroundColor(.orange) // .fontWeight(.thin)
+                Text("Protein").foregroundColor(.red) // .fontWeight(.thin)
                 Spacer()
                 DecimalTextField(
                     "0",
-                    value: $state.fat,
+                    value: $state.protein,
                     formatter: formatter,
                     autofocus: false,
                     cleanInput: true
-                )
+                ).foregroundColor(.loopRed)
+
                 Text("grams").foregroundColor(.secondary)
             }
         }

+ 0 - 3
FreeAPS/Sources/Modules/FPUConfig/FPUConfigStateModel.swift

@@ -2,15 +2,12 @@ import SwiftUI
 
 extension FPUConfig {
     final class StateModel: BaseStateModel<Provider> {
-        @Published var useFPUconversion = true
         @Published var individualAdjustmentFactor: Decimal = 0
         @Published var timeCap: Decimal = 0
         @Published var minuteInterval: Decimal = 0
         @Published var delay: Decimal = 0
 
         override func subscribe() {
-            subscribeSetting(\.useFPUconversion, on: $useFPUconversion) { useFPUconversion = $0 }
-
             subscribeSetting(\.timeCap, on: $timeCap.map(Int.init), initial: {
                 let value = max(min($0, 12), 5)
                 timeCap = Decimal(value)

+ 0 - 4
FreeAPS/Sources/Modules/FPUConfig/View/FPUConfigRootView.swift

@@ -22,10 +22,6 @@ extension FPUConfig {
 
         var body: some View {
             Form {
-                Section(header: Text("Convert Fat and Protein")) {
-                    Toggle("Enable", isOn: $state.useFPUconversion)
-                }
-
                 Section(header: Text("Conversion settings")) {
                     HStack {
                         Text("Delay In Minutes")