Jelajahi Sumber

Merge branch 'zulu' into UI

polscm32 2 tahun lalu
induk
melakukan
5708d698e5

+ 25 - 30
FreeAPS/Sources/Modules/Home/HomeStateModel.swift

@@ -61,25 +61,12 @@ extension Home {
         @Published var thresholdLines: Bool = false
         @Published var timeZone: TimeZone?
         @Published var hours: Int16 = 6
-
-        enum Scale: Int, CaseIterable, Identifiable {
-            case one = 1
-            case three = 3
-            case six = 6
-            case twelve = 12
-            case twentyfour = 24
-            var id: Self { self }
-        }
-
-        @Published var scale: Scale = .six {
-            didSet {
-                hours = Int16(calculateScreenHours(scale: scale))
-            }
-        }
+        @Published var totalBolus: Decimal = 0
 
         let coredataContext = CoreDataStack.shared.persistentContainer.viewContext
 
         override func subscribe() {
+            calculateTINS()
             setupGlucose()
             setupBasals()
             setupBoluses()
@@ -211,21 +198,6 @@ extension Home {
                 .store(in: &lifetime)
         }
 
-        func calculateScreenHours(scale: Scale) -> Int {
-            switch scale {
-            case .one:
-                return 1
-            case .three:
-                return 3
-            case .six:
-                return 6
-            case .twelve:
-                return 12
-            case .twentyfour:
-                return 24
-            }
-        }
-
         func addCarbs() {
             showModal(for: .addCarbs(editMode: false, override: false))
         }
@@ -306,6 +278,29 @@ extension Home {
             }
         }
 
+        // MARK: WORKS....BUT MAYBE TIMEZONE PROBLEMS COULD OCCUR
+
+        func calculateTINS() -> String {
+            let date = Date()
+            let calendar = Calendar.current
+            let offset = hours
+
+            var offsetComponents = DateComponents()
+            //        offsetComponents.hour = -offset.rawValue
+            offsetComponents.hour = -Int(offset)
+
+            let startTime = calendar.date(byAdding: offsetComponents, to: date)!
+            print("******************")
+            print("die voll krasse start time ist: \(startTime)")
+
+            let bolusesForCurrentDay = boluses.filter { $0.timestamp >= startTime && $0.type == .bolus }
+
+            let totalBolus = bolusesForCurrentDay.map { $0.amount ?? 0 }.reduce(0, +)
+            let roundedTotalBolus = Decimal(round(100 * Double(totalBolus)) / 100)
+
+            return "\(roundedTotalBolus)"
+        }
+
         private func setupSuspensions() {
             DispatchQueue.main.async { [weak self] in
                 guard let self = self else { return }

+ 0 - 31
FreeAPS/Sources/Modules/Home/View/Header/PumpView.swift

@@ -6,13 +6,9 @@ struct PumpView: View {
     @Binding var name: String
     @Binding var expiresAtDate: Date?
     @Binding var timerDate: Date
-    @Binding var boluses: [PumpHistoryEvent]
-    @Binding var screenHours: Int16
 
     @State var state: Home.StateModel
 
-    @State var totalBolus: Decimal = 0
-
     private var reservoirFormatter: NumberFormatter {
         let formatter = NumberFormatter()
         formatter.numberStyle = .decimal
@@ -84,8 +80,6 @@ struct PumpView: View {
                         .foregroundColor(batteryColor)
                     Text("\(Int(battery.percent ?? 100)) %").font(.callout)
                         .fontWeight(.bold)
-                    Text(calculateTINS())
-                        .font(.callout).fontWeight(.bold)
                 }
             }
 
@@ -104,31 +98,6 @@ struct PumpView: View {
         }
     }
 
-    // MARK: WORKS....BUT MAYBE TIMEZONE PROBLEMS COULD OCCUR
-
-    // DEFINETELY SOMETHING FOR OUR TIMEZONE EXPERT.....
-
-    private func calculateTINS() -> String {
-        let date = Date()
-        let calendar = Calendar.current
-        let offset = screenHours
-
-        var offsetComponents = DateComponents()
-        //        offsetComponents.hour = -offset.rawValue
-        offsetComponents.hour = -Int(offset)
-
-        let startTime = calendar.date(byAdding: offsetComponents, to: date)!
-        print("******************")
-        print("die voll krasse start time ist: \(startTime)")
-
-        let bolusesForCurrentDay = boluses.filter { $0.timestamp >= startTime && $0.type == .bolus }
-
-        let totalBolus = bolusesForCurrentDay.map { $0.amount ?? 0 }.reduce(0, +)
-        let roundedTotalBolus = Decimal(round(100 * Double(totalBolus)) / 100)
-
-        return "\(roundedTotalBolus) U"
-    }
-
     private func remainingTimeString(time: TimeInterval) -> String {
         guard time > 0 else {
             return NSLocalizedString("Replace pod", comment: "View/Header when pod expired")

+ 7 - 3
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -189,8 +189,6 @@ extension Home {
                 name: $state.pumpName,
                 expiresAtDate: $state.pumpExpiresAtDate,
                 timerDate: $state.timerDate,
-                boluses: $state.boluses,
-                screenHours: $state.hours,
                 state: state
             )
             .onTapGesture {
@@ -231,7 +229,7 @@ extension Home {
                     comment: "Manual Temp basal"
                 )
             }
-            return rateString + NSLocalizedString(" U/hr", comment: "Unit per hour with space") + manualBasalString
+            return rateString + " " + NSLocalizedString(" U/hr", comment: "Unit per hour with space") + manualBasalString
         }
 
         var tempTargetString: String? {
@@ -330,6 +328,12 @@ extension Home {
                         .font(.system(size: 12, weight: .bold))
                         .foregroundColor(.insulin)
                         .padding(.leading, 8)
+                    Text(
+                        "TINS: \(state.calculateTINS())" +
+                            NSLocalizedString(" U", comment: "Unit in number of units delivered (keep the space character!)")
+                    )
+                    .font(.system(size: 12, weight: .bold))
+                    .foregroundColor(.insulin)
                 }
 
                 if let tempTargetString = tempTargetString {