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

Merge branch 'UI' into UI-superBolus

polscm32 2 лет назад
Родитель
Сommit
48972fbe09

+ 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 }

+ 43 - 15
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -273,7 +273,7 @@ struct MainChartView: View {
         .scaleEffect(x: 1, y: -1)
         .frame(width: fullGlucoseWidth(viewWidth: fullSize.width) + additionalWidth(viewWidth: fullSize.width))
         .frame(maxHeight: Config.basalHeight)
-        .background(Color.secondary.opacity(0.1))
+        .background(Color.clear)
         .onChange(of: tempBasals) { _ in
             calculateBasalPoints(fullSize: fullSize)
         }
@@ -319,11 +319,14 @@ struct MainChartView: View {
         return ZStack {
             Path { path in
                 for hour in 0 ..< hours + hours {
-                    let x = firstHourPosition(viewWidth: fullSize.width) +
-                        oneSecondStep(viewWidth: fullSize.width) *
-                        CGFloat(hour) * CGFloat(1.hours.timeInterval)
-                    path.move(to: CGPoint(x: x, y: 0))
-                    path.addLine(to: CGPoint(x: x, y: fullSize.height - 20))
+                    if screenHours < 12 || hour % 2 == 0 {
+                        // only show every second line if screenHours is too big
+                        let x = firstHourPosition(viewWidth: fullSize.width) +
+                            oneSecondStep(viewWidth: fullSize.width) *
+                            CGFloat(hour) * CGFloat(1.hours.timeInterval)
+                        path.move(to: CGPoint(x: x, y: 0))
+                        path.addLine(to: CGPoint(x: x, y: fullSize.height - 20))
+                    }
                 }
             }
             .stroke(useColour, lineWidth: 0.15)
@@ -340,20 +343,45 @@ struct MainChartView: View {
         }
     }
 
+    // MARK: TO DO: CHANGE TIME LABELS TO ONLY DISPLAY EVERY SECOND LABEL WHEN SCREENHOURS IS TOO BIG
+
+//    private func timeLabelsView(fullSize: CGSize) -> some View {
+//        let format = screenHours > 6 ? date24Formatter : dateFormatter
+//        return ZStack {
+//            // X time labels
+//            ForEach(0 ..< hours + hours) { hour in
+//                Text(format.string(from: firstHourDate().addingTimeInterval(hour.hours.timeInterval)))
+//                    .font(.caption)
+//                    .position(
+//                        x: firstHourPosition(viewWidth: fullSize.width) +
+//                            oneSecondStep(viewWidth: fullSize.width) *
+//                            CGFloat(hour) * CGFloat(1.hours.timeInterval),
+//                        y: 10.0
+//                    )
+//                    .foregroundColor(.secondary)
+//            }
+//        }.frame(maxHeight: 20)
+//    }
+
     private func timeLabelsView(fullSize: CGSize) -> some View {
         let format = screenHours > 6 ? date24Formatter : dateFormatter
         return ZStack {
             // X time labels
             ForEach(0 ..< hours + hours) { hour in
-                Text(format.string(from: firstHourDate().addingTimeInterval(hour.hours.timeInterval)))
-                    .font(.caption)
-                    .position(
-                        x: firstHourPosition(viewWidth: fullSize.width) +
-                            oneSecondStep(viewWidth: fullSize.width) *
-                            CGFloat(hour) * CGFloat(1.hours.timeInterval),
-                        y: 10.0
-                    )
-                    .foregroundColor(.secondary)
+                if screenHours >= 12 && hour % 2 == 1 {
+                    // only show every second time label if screenHours is too big
+                    EmptyView()
+                } else {
+                    Text(format.string(from: firstHourDate().addingTimeInterval(hour.hours.timeInterval)))
+                        .font(.caption)
+                        .position(
+                            x: firstHourPosition(viewWidth: fullSize.width) +
+                                oneSecondStep(viewWidth: fullSize.width) *
+                                CGFloat(hour) * CGFloat(1.hours.timeInterval),
+                            y: 10.0
+                        )
+                        .foregroundColor(.secondary)
+                }
             }
         }.frame(maxHeight: 20)
     }

+ 13 - 9
FreeAPS/Sources/Modules/Home/View/Header/CurrentGlucoseView.swift

@@ -11,13 +11,18 @@ struct CurrentGlucoseView: View {
 
     @State private var rotationDegrees: Double = 0.0
     @State private var angularGradient = AngularGradient(colors: [
-        Color(red: 0.729, green: 0.337, blue: 1),
-        Color(red: 0.263, green: 0.733, blue: 0.914),
-        Color(red: 0.263, green: 0.733, blue: 0.914),
-        Color(red: 0.263, green: 0.733, blue: 0.914),
-        Color(red: 0.263, green: 0.733, blue: 0.914),
-        Color(red: 0.729, green: 0.337, blue: 1)
-    ], center: .center, startAngle: .degrees(-45), endAngle: .degrees(135))
+        // 184, 87, 255
+        // 159, 108, 250
+        // 124, 139, 243
+        // 87, 170, 236
+        // 67, 187, 233
+        Color(red: 0.7215686275, green: 0.3411764706, blue: 1),
+        Color(red: 0.6235294118, green: 0.4235294118, blue: 0.9803921569),
+        Color(red: 0.4862745098, green: 0.5450980392, blue: 0.9529411765),
+        Color(red: 0.3411764706, green: 0.6666666667, blue: 0.9254901961),
+        Color(red: 0.262745098, green: 0.7333333333, blue: 0.9137254902),
+        Color(red: 0.7215686275, green: 0.3411764706, blue: 1)
+    ], center: .center, startAngle: .degrees(270), endAngle: .degrees(-90))
 
     @Environment(\.colorScheme) var colorScheme
 
@@ -57,8 +62,7 @@ struct CurrentGlucoseView: View {
     }
 
     var body: some View {
-//        let triangleColor = Color(red: 0.729, green: 0.337, blue: 1)
-        let triangleColor = Color(red: 0.263, green: 0.733, blue: 0.914)
+        let triangleColor = Color(red: 0.262745098, green: 0.7333333333, blue: 0.9137254902)
 
         ZStack {
             TrendShape(gradient: angularGradient, color: triangleColor)

+ 3 - 3
FreeAPS/Sources/Modules/Home/View/Header/LoopView.swift

@@ -21,13 +21,13 @@ struct LoopView: View {
         return formatter
     }
 
-    private let rect = CGRect(x: 0, y: 0, width: 35, height: 35)
+    private let rect = CGRect(x: 0, y: 0, width: 24, height: 24)
     var body: some View {
         VStack(alignment: .center) {
             ZStack {
                 Circle()
-                    .strokeBorder(color, lineWidth: 5)
-                    .frame(width: rect.width, height: rect.height, alignment: .bottom)
+                    .strokeBorder(color, lineWidth: 4)
+                    .frame(width: rect.width, height: rect.height, alignment: .center)
                     .mask(mask(in: rect).fill(style: FillStyle(eoFill: true)))
                 if isLooping {
                     ProgressView()

+ 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.....
-
-    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")

+ 46 - 17
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 {
@@ -368,6 +372,8 @@ extension Home {
         var legendPanel: some View {
             ZStack {
                 HStack(alignment: .center) {
+                    Spacer()
+
                     Group {
                         Circle().fill(Color.loopGreen).frame(width: 8, height: 8)
                         Text("BG")
@@ -385,9 +391,15 @@ extension Home {
                         Text("ZT")
                             .font(.system(size: 12, weight: .bold)).foregroundColor(.zt)
                     }
+
+                    Spacer()
+
+                    loopView.padding(.top, 16)
+
+                    Spacer()
+
                     Group {
                         Circle().fill(Color.loopYellow).frame(width: 8, height: 8)
-                            .padding(.leading, 8)
                         Text("COB")
                             .font(.system(size: 12, weight: .bold)).foregroundColor(.loopYellow)
                     }
@@ -406,9 +418,9 @@ extension Home {
                         )
                         .font(.system(size: 12, weight: .bold)).foregroundColor(.secondary)
                     }
+                    Spacer()
                 }
                 .frame(maxWidth: .infinity)
-                .padding([.bottom], 20)
             }
         }
 
@@ -424,11 +436,30 @@ extension Home {
                         try? moc.save()
                         state.hours = button.hours
                     }
-                    .foregroundStyle(button.active ? .primary : .secondary)
+                    .foregroundStyle(button.active ? (colorScheme == .dark ? Color.white : Color.black).opacity(0.9) : .secondary)
                     .frame(maxHeight: 30).padding(.horizontal, 8)
-                    .background(button.active ? Color(.systemGray5) : .clear, in: .capsule(style: .circular))
+                    .background(
+                        button.active ?
+                            // RGB(30, 60, 95)
+                            (
+                                colorScheme == .dark ? Color(red: 0.1176470588, green: 0.2352941176, blue: 0.3725490196) :
+                                    Color.white
+                            ) :
+                            Color
+                            .clear
+                    )
+                    .cornerRadius(20)
                 }
             }
+            .shadow(
+                color: colorScheme == .dark ? Color(
+                    red: 0.02745098039,
+                    green: 0.1098039216,
+                    blue: 0.1411764706
+                ) : Color
+                    .black.opacity(0.33),
+                radius: 3
+            )
             .font(buttonFont)
         }
 
@@ -660,15 +691,15 @@ extension Home {
                 VStack(spacing: 0) {
                     Spacer()
 
-                    ZStack {
-                        glucoseView
+//                    ZStack {
+                    glucoseView.padding(.top, 75)
 
-                        loopView
-                            /// circles width is 110, loops width is 35 -> (110/2) - (35/2) = 55 - 17.5 = 37.5
-                            .offset(x: UIScreen.main.bounds.width * 0.43, y: -37.5)
-                            .padding(.trailing, 10)
-                    }
-                    .padding(.top, 75)
+//                        loopView
+//                            /// circles width is 110, loops width is 35 -> (110/2) - (35/2) = 55 - 17.5 = 37.5
+//                            .offset(x: UIScreen.main.bounds.width * 0.43, y: -37.5)
+//                            .padding(.trailing, 10)
+//                    }
+//                    .padding(.top, 75)
 
                     Spacer()
 
@@ -697,8 +728,6 @@ extension Home {
 
                     timeInterval
 
-                    Spacer()
-
                     legendPanel
 
                     Spacer()