Przeglądaj źródła

Rework header
* rework header view in home root view
* add TDD and move basal to header
* readd tins, if chosen, tins is displayed in header instead of tdd
* readd temp target in same spot as profiles, only display them if no profile is already active
* add conditional coloring of person icon also for profiles

polscm32 2 lat temu
rodzic
commit
728b5f1815

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

@@ -25,10 +25,9 @@ struct LoopView: View {
 
     var body: some View {
         HStack(alignment: .center) {
-//            Rectangle().frame(width: UIScreen.main.bounds.width / 2.5, height: 2, alignment: .leading).foregroundColor(color)
             ZStack {
                 Image(systemName: "circle")
-                    .font(.system(size: 15))
+                    .font(.system(size: 16))
                     .fontWeight(.bold)
                     .foregroundColor(color)
 
@@ -38,16 +37,16 @@ struct LoopView: View {
                 }
             }
             if isLooping {
-                Text("looping").font(.caption2).foregroundColor(colorScheme == .dark ? Color.white.opacity(0.9) : Color.secondary)
+                Text("looping").font(.system(size: 16))
             } else if manualTempBasal {
-                Text("Manual").font(.caption2).foregroundColor(colorScheme == .dark ? Color.white.opacity(0.9) : Color.secondary)
+                Text("Manual").font(.system(size: 16))
+
             } else if actualSuggestion?.timestamp != nil {
-                Text(timeString).font(.caption2)
-                    .foregroundColor(colorScheme == .dark ? Color.white.opacity(0.9) : Color.secondary)
+                Text(timeString).font(.system(size: 16))
+
             } else {
-                Text("--").font(.caption2).foregroundColor(colorScheme == .dark ? Color.white.opacity(0.9) : Color.secondary)
+                Text("--").font(.system(size: 16))
             }
-//            Rectangle().frame(width: UIScreen.main.bounds.width / 2.5, height: 2, alignment: .trailing).foregroundColor(color)
         }
     }
 

+ 9 - 34
FreeAPS/Sources/Modules/Home/View/Header/PumpView.swift

@@ -39,72 +39,47 @@ struct PumpView: View {
     }
 
     var body: some View {
-        HStack {
-            Image(systemName: "syringe.fill")
-                .font(.system(size: 16))
-                .foregroundColor(Color.insulin)
-            Text(
-                (numberFormatter.string(from: (state.suggestion?.iob ?? 0) as NSNumber) ?? "0") +
-                    NSLocalizedString(" U", comment: "Insulin unit")
-            )
-            .font(.callout).fontWeight(.bold)
-
-            Spacer()
-
-            Image(systemName: "fork.knife")
-                .font(.system(size: 16))
-                .foregroundColor(.loopYellow)
-            Text(
-                (numberFormatter.string(from: (state.suggestion?.cob ?? 0) as NSNumber) ?? "0") +
-                    NSLocalizedString(" g", comment: "gram of carbs")
-            )
-            .font(.callout).fontWeight(.bold)
-
-            Spacer()
-
+        VStack(alignment: .leading, spacing: 20) {
             if let reservoir = reservoir {
                 HStack {
                     Image(systemName: "drop.fill")
-                        .font(.system(size: 16))
+                        .font(.system(size: 15))
                         .foregroundColor(reservoirColor)
                     if reservoir == 0xDEAD_BEEF {
-                        Text("50+ " + NSLocalizedString("U", comment: "Insulin unit")).font(.callout).fontWeight(.bold)
+                        Text("50+ " + NSLocalizedString("U", comment: "Insulin unit")).font(.system(size: 15))
                     } else {
                         Text(
                             reservoirFormatter
                                 .string(from: reservoir as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit")
                         )
-                        .font(.callout).fontWeight(.bold)
+                        .font(.system(size: 15))
                     }
                 }
 
                 if let timeZone = timeZone, timeZone.secondsFromGMT() != TimeZone.current.secondsFromGMT() {
                     Image(systemName: "clock.badge.exclamationmark.fill")
-                        .font(.system(size: 16))
+                        .font(.system(size: 15))
                         .symbolRenderingMode(.palette)
                         .foregroundStyle(.red, Color(.warning))
                 }
             }
 
-            Spacer()
-
             if let battery = battery, battery.display ?? false, expiresAtDate == nil {
                 HStack {
                     Image(systemName: "battery.100")
-                        .font(.system(size: 16))
+                        .font(.system(size: 15))
                         .foregroundColor(batteryColor)
-                    Text("\(Int(battery.percent ?? 100)) %").font(.callout)
-                        .fontWeight(.bold)
+                    Text("\(Int(battery.percent ?? 100)) %").font(.system(size: 15))
                 }
             }
 
             if let date = expiresAtDate {
                 HStack {
                     Image(systemName: "stopwatch.fill")
-                        .font(.system(size: 16))
+                        .font(.system(size: 15))
                         .foregroundColor(timerColor)
 
-                    Text(remainingTimeString(time: date.timeIntervalSince(timerDate))).font(.callout).fontWeight(.bold)
+                    Text(remainingTimeString(time: date.timeIntervalSince(timerDate))).font(.system(size: 15))
                 }
             }
         }

+ 179 - 68
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -310,11 +310,11 @@ extension Home {
             HStack(alignment: .center) {
                 if state.pumpSuspended {
                     Text("Pump suspended")
-                        .font(.system(size: 12, weight: .bold)).foregroundColor(.loopGray)
+                        .font(.system(size: 15, weight: .bold)).foregroundColor(.loopGray)
                         .padding(.leading, 8)
                 } else if let tempBasalString = tempBasalString {
                     Text(tempBasalString)
-                        .font(.system(size: 12, weight: .bold))
+                        .font(.system(size: 15, weight: .bold))
                         .foregroundColor(.insulin)
                         .padding(.leading, 8)
                 }
@@ -323,7 +323,7 @@ extension Home {
                         "TINS: \(state.calculateTINS())" +
                             NSLocalizedString(" U", comment: "Unit in number of units delivered (keep the space character!)")
                     )
-                    .font(.system(size: 12, weight: .bold))
+                    .font(.system(size: 15, weight: .bold))
                     .foregroundColor(.insulin)
                 }
 
@@ -335,29 +335,6 @@ extension Home {
 
                 Spacer()
 
-                if let overrideString = overrideString {
-                    HStack {
-                        Text("👤 " + overrideString)
-                            .font(.system(size: 12))
-                            .foregroundColor(.secondary)
-                        Image(systemName: "xmark")
-                            .foregroundStyle(.secondary)
-                    }
-                    .alert(
-                        "Return to Normal?", isPresented: $showCancelAlert,
-                        actions: {
-                            Button("No", role: .cancel) {}
-                            Button("Yes", role: .destructive) {
-                                state.cancelProfile()
-                            }
-                        }, message: { Text("This will change settings back to your normal profile.") }
-                    )
-                    .padding(.trailing, 8)
-                    .onTapGesture {
-                        showCancelAlert = true
-                    }
-                }
-
                 if state.closedLoop, state.settingsManager.preferences.maxIOB == 0 {
                     Text("Max IOB: 0").font(.callout).foregroundColor(.orange).padding(.trailing, 20)
                 }
@@ -562,7 +539,7 @@ extension Home {
                             .font(.system(size: 26))
                             .padding(8)
                     }
-                    .foregroundColor(state.isTempTargetActive ? Color.purple : colorIcon)
+                    .foregroundColor((state.isTempTargetActive || (overrideString != nil)) ? Color.purple : colorIcon)
                     .buttonStyle(.borderless)
                     Spacer()
                     Button { state.showModal(for: .statistics)
@@ -666,6 +643,167 @@ extension Home {
             .offset(y: -90)
         }
 
+        @ViewBuilder func rightHeaderPanel(_: GeometryProxy) -> some View {
+            VStack(alignment: .leading, spacing: 20) {
+                /// Loop view at bottomLeading
+                LoopView(
+                    suggestion: $state.suggestion,
+                    enactedSuggestion: $state.enactedSuggestion,
+                    closedLoop: $state.closedLoop,
+                    timerDate: $state.timerDate,
+                    isLooping: $state.isLooping,
+                    lastLoopDate: $state.lastLoopDate,
+                    manualTempBasal: $state.manualTempBasal
+                ).onTapGesture {
+                    state.isStatusPopupPresented = true
+                }.onLongPressGesture {
+                    let impactHeavy = UIImpactFeedbackGenerator(style: .heavy)
+                    impactHeavy.impactOccurred()
+                    state.runLoop()
+                }
+                /// eventualBG string at bottomTrailing
+                if let eventualBG = state.eventualBG {
+                    HStack {
+                        Image(systemName: "arrow.right.circle")
+                            .font(.system(size: 14))
+                        Text(
+                            numberFormatter.string(
+                                from: (
+                                    state.units == .mmolL ? eventualBG
+                                        .asMmolL : Decimal(eventualBG)
+                                ) as NSNumber
+                            )!
+                        )
+                        .font(.system(size: 14))
+                    }
+                }
+            }
+        }
+
+        @ViewBuilder func mealPanel(_: GeometryProxy) -> some View {
+            HStack(spacing: 40) {
+                HStack {
+                    Image(systemName: "syringe.fill")
+                        .font(.system(size: 15))
+                        .foregroundColor(Color.insulin)
+                    Text(
+                        (numberFormatter.string(from: (state.suggestion?.iob ?? 0) as NSNumber) ?? "0") +
+                            NSLocalizedString(" U", comment: "Insulin unit")
+                    )
+                    .font(.system(size: 15))
+                }
+                HStack {
+                    Image(systemName: "fork.knife")
+                        .font(.system(size: 15))
+                        .foregroundColor(.loopYellow)
+                    Text(
+                        (numberFormatter.string(from: (state.suggestion?.cob ?? 0) as NSNumber) ?? "0") +
+                            NSLocalizedString(" g", comment: "gram of carbs")
+                    )
+                    .font(.system(size: 15))
+                }
+                HStack {
+                    if state.pumpSuspended {
+                        Text("Pump suspended")
+                            .font(.system(size: 12)).foregroundColor(.loopGray)
+                    } else if let tempBasalString = tempBasalString {
+                        Text(tempBasalString)
+                            .font(.system(size: 15))
+                            .foregroundColor(.insulin)
+                    }
+                }
+                if !state.tins {
+                    HStack {
+                        Text(
+                            "TDD: " +
+                                (numberFormatter.string(from: (state.suggestion?.tdd ?? 0) as NSNumber) ?? "--") +
+                                NSLocalizedString(" U", comment: "Insulin unit")
+                        ).font(.system(size: 15))
+                    }
+                } else {
+                    Text(
+                        "TINS: \(state.calculateTINS())" +
+                            NSLocalizedString(" U", comment: "Unit in number of units delivered (keep the space character!)")
+                    )
+                    .font(.system(size: 15))
+                    .foregroundColor(.insulin)
+                }
+            }
+        }
+
+        @ViewBuilder func profileView(_: GeometryProxy) -> some View {
+            let colourChart: Color = colorScheme == .dark ? Color(
+                red: 0.05490196078,
+                green: 0.05490196078,
+                blue: 0.05490196078
+            ) : .white
+
+            if let overrideString = overrideString {
+                ZStack {
+                    /// rectangle as background
+                    RoundedRectangle(cornerRadius: 15)
+                        .fill(colourChart)
+                        .clipShape(RoundedRectangle(cornerRadius: 15))
+                        .frame(height: UIScreen.main.bounds.height / 20)
+                        .shadow(
+                            color:
+                            Color(red: 0.7215686275, green: 0.3411764706, blue: 1),
+                            radius: 1
+                        )
+                    HStack {
+                        /// actual profile view
+                        Image(systemName: "person.fill")
+                            .font(.system(size: 20))
+                            .foregroundStyle(Color.purple)
+                        Spacer()
+                        Text(overrideString)
+                            .font(.system(size: 18))
+                        Spacer()
+                        Image(systemName: "xmark.app")
+                            .font(.system(size: 20))
+                    }.padding(.horizontal, 10)
+                        .alert(
+                            "Return to Normal?", isPresented: $showCancelAlert,
+                            actions: {
+                                Button("No", role: .cancel) {}
+                                Button("Yes", role: .destructive) {
+                                    state.cancelProfile()
+                                }
+                            }, message: { Text("This will change settings back to your normal profile.") }
+                        )
+                        .padding(.trailing, 8)
+                        .onTapGesture {
+                            showCancelAlert = true
+                        }
+                }.padding(.horizontal, 10)
+            }
+
+            /// just show temp target if no profile is already active
+            if overrideString == nil, let tempTargetString = tempTargetString {
+                ZStack {
+                    /// rectangle as background
+                    RoundedRectangle(cornerRadius: 15)
+                        .fill(colourChart)
+                        .clipShape(RoundedRectangle(cornerRadius: 15))
+                        .frame(height: UIScreen.main.bounds.height / 20)
+                        .shadow(
+                            color:
+                            Color(red: 0.7215686275, green: 0.3411764706, blue: 1),
+                            radius: 1
+                        )
+                    HStack {
+                        Image(systemName: "person.fill")
+                            .font(.system(size: 20))
+                            .foregroundStyle(Color.purple)
+                        Spacer()
+                        Text(tempTargetString)
+                            .font(.system(size: 15))
+                        Spacer()
+                    }.padding(.horizontal, 10)
+                }.padding(.horizontal, 10)
+            }
+        }
+
         var body: some View {
             let colorBackground = colorScheme == .dark ? LinearGradient(
                 gradient: Gradient(colors: [
@@ -688,56 +826,29 @@ extension Home {
                 VStack(spacing: 0) {
                     Spacer()
 
-                    ZStack(alignment: .bottom) {
+                    ZStack {
                         /// glucose bobble
                         glucoseView
 
-                        /// eventualBG string at bottomTrailing
-                        if let eventualBG = state.eventualBG {
-                            Text(
-                                "⇢ " + numberFormatter.string(
-                                    from: (
-                                        state.units == .mmolL ? eventualBG
-                                            .asMmolL : Decimal(eventualBG)
-                                    ) as NSNumber
-                                )!
-                            )
-                            .font(.system(size: 12))
-                            .foregroundColor(.secondary)
-                            .padding(.leading)
-                            .offset(x: 75, y: 4)
-                        }
+                        /// right panel with loop status and evBG
+                        HStack {
+                            Spacer()
+                            rightHeaderPanel(geo)
+                        }.padding(.trailing, 20)
 
-                        /// Loop view at bottomLeading
-                        LoopView(
-                            suggestion: $state.suggestion,
-                            enactedSuggestion: $state.enactedSuggestion,
-                            closedLoop: $state.closedLoop,
-                            timerDate: $state.timerDate,
-                            isLooping: $state.isLooping,
-                            lastLoopDate: $state.lastLoopDate,
-                            manualTempBasal: $state.manualTempBasal
-                        ).padding(.trailing)
-                            .offset(x: -80, y: 4)
-                            .onTapGesture {
-                                state.isStatusPopupPresented = true
-                            }.onLongPressGesture {
-                                let impactHeavy = UIImpactFeedbackGenerator(style: .heavy)
-                                impactHeavy.impactOccurred()
-                                state.runLoop()
-                            }
-                    }.padding(.top, 40)
+                        /// left panel with pump related info
+                        HStack {
+                            pumpView
+                            Spacer()
+                        }.padding(.leading, 20)
 
-                    Spacer()
+                    }.padding(.top, 40)
 
-                    header(geo)
-                        .padding(.top, 15)
-                        .padding(.horizontal, 10)
+                    mealPanel(geo).padding(.top, 20)
 
                     Spacer()
 
-                    infoPanel
-                        .padding(.horizontal, 10)
+                    profileView(geo).padding(.vertical)
 
                     RoundedRectangle(cornerRadius: 15)
                         .fill(colourChart)