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

style: Update styling of time warning

bastiaan.verhaar 1 год назад
Родитель
Сommit
1ccd9bc266

+ 61 - 76
FreeAPS/Sources/Modules/Home/View/Header/PumpView.swift

@@ -6,8 +6,6 @@ struct PumpView: View {
     let name: String
     let expiresAtDate: Date?
     let timerDate: Date
-    let pumpStatusBadge: UIImage?
-    let pumpStatusBadgeColor: Color?
     let pumpStatusHighlightMessage: String?
     let battery: [OpenAPS_Battery]
 
@@ -20,96 +18,83 @@ struct PumpView: View {
     }
 
     var body: some View {
-        ZStack(alignment: .topLeading) {
-            if let pumpStatusHighlightMessage = pumpStatusHighlightMessage { // display message instead pump info
-                VStack(alignment: .center) {
-                    Text(pumpStatusHighlightMessage).font(.footnote).fontWeight(.bold)
-                        .multilineTextAlignment(.center).frame(maxWidth: /*@START_MENU_TOKEN@*/ .infinity/*@END_MENU_TOKEN@*/)
-                }.frame(width: 100)
-            } else {
-                VStack(alignment: .leading, spacing: 20) {
-                    if reservoir == nil && battery.isEmpty {
-                        VStack(alignment: .center, spacing: 12) {
-                            HStack {
-                                Image(systemName: "keyboard.onehanded.left")
-                                    .font(.body)
-                                    .imageScale(.large)
-                            }
-                            HStack {
-                                Text("Add pump")
-                                    .font(.caption)
-                                    .bold()
-                            }
+        if let pumpStatusHighlightMessage = pumpStatusHighlightMessage { // display message instead pump info
+            VStack(alignment: .center) {
+                Text(pumpStatusHighlightMessage).font(.footnote).fontWeight(.bold)
+                    .multilineTextAlignment(.center).frame(maxWidth: /*@START_MENU_TOKEN@*/ .infinity/*@END_MENU_TOKEN@*/)
+            }.frame(width: 100)
+        } else {
+            VStack(alignment: .leading, spacing: 20) {
+                if reservoir == nil && battery.isEmpty {
+                    VStack(alignment: .center, spacing: 12) {
+                        HStack {
+                            Image(systemName: "keyboard.onehanded.left")
+                                .font(.body)
+                                .imageScale(.large)
                         }
-                        .frame(alignment: .top)
-                    }
-                    if let reservoir = reservoir {
                         HStack {
-                            Image(systemName: "cross.vial.fill")
-                                .font(.callout)
+                            Text("Add pump")
+                                .font(.caption)
+                                .bold()
+                        }
+                    }
+                    .frame(alignment: .top)
+                }
+                if let reservoir = reservoir {
+                    HStack {
+                        Image(systemName: "cross.vial.fill")
+                            .font(.callout)
 
-                            if reservoir == 0xDEAD_BEEF {
-                                Text("50+ " + NSLocalizedString("U", comment: "Insulin unit"))
-                                    .font(.callout)
-                                    .fontWeight(.bold)
-                                    .fontDesign(.rounded)
-                            } else {
-                                Text(
-                                    Formatter.integerFormatter
-                                        .string(from: reservoir as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit")
-                                )
+                        if reservoir == 0xDEAD_BEEF {
+                            Text("50+ " + NSLocalizedString("U", comment: "Insulin unit"))
                                 .font(.callout)
                                 .fontWeight(.bold)
                                 .fontDesign(.rounded)
-                            }
+                        } else {
+                            Text(
+                                Formatter.integerFormatter
+                                    .string(from: reservoir as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit")
+                            )
+                            .font(.callout)
+                            .fontWeight(.bold)
+                            .fontDesign(.rounded)
                         }
-                        .padding(.vertical, 5)
-                        .padding(.horizontal, 10)
-                        .foregroundStyle(reservoirColor)
-                        .overlay(
-                            Capsule()
-                                .stroke(reservoirColor.opacity(0.4), lineWidth: 2)
-                        )
                     }
+                    .padding(.vertical, 5)
+                    .padding(.horizontal, 10)
+                    .foregroundStyle(reservoirColor)
+                    .overlay(
+                        Capsule()
+                            .stroke(reservoirColor.opacity(0.4), lineWidth: 2)
+                    )
+                }
 
-                    if (battery.first?.display) != nil, let shouldBatteryDisplay = battery.first?.display, shouldBatteryDisplay {
-                        HStack {
-                            Image(systemName: "battery.100")
-                                .font(.callout)
-                                .foregroundStyle(batteryColor)
-                            Text("\(Int(battery.first?.percent ?? 100)) %")
-                                .font(.callout).fontWeight(.bold).fontDesign(.rounded)
-                        }
+                if (battery.first?.display) != nil, let shouldBatteryDisplay = battery.first?.display, shouldBatteryDisplay {
+                    HStack {
+                        Image(systemName: "battery.100")
+                            .font(.callout)
+                            .foregroundStyle(batteryColor)
+                        Text("\(Int(battery.first?.percent ?? 100)) %")
+                            .font(.callout).fontWeight(.bold).fontDesign(.rounded)
                     }
+                }
 
-                    if let date = expiresAtDate {
-                        HStack {
-                            Image(systemName: "stopwatch.fill")
-                                .font(.callout)
-                                .foregroundStyle(timerColor)
+                if let date = expiresAtDate {
+                    HStack {
+                        Image(systemName: "stopwatch.fill")
+                            .font(.callout)
+                            .foregroundStyle(timerColor)
 
-                            Text(remainingTimeString(time: date.timeIntervalSince(timerDate)))
-                                .font(!(date.timeIntervalSince(timerDate) > 0) ? .subheadline : .callout)
-                                .fontWeight(.bold)
-                                .fontDesign(.rounded)
-                        }
-                        // aligns the stopwatch icon exactly with the first pixel of the reservoir icon
-                        .padding(.leading, 12)
+                        Text(remainingTimeString(time: date.timeIntervalSince(timerDate)))
+                            .font(!(date.timeIntervalSince(timerDate) > 0) ? .subheadline : .callout)
+                            .fontWeight(.bold)
+                            .fontDesign(.rounded)
                     }
+                    // aligns the stopwatch icon exactly with the first pixel of the reservoir icon
+                    .padding(.leading, 12)
                 }
             }
-            if let badgeImage = pumpStatusBadge, let badgeColor = pumpStatusBadgeColor {
-                HStack {
-                    Spacer()
-                    Image(uiImage: badgeImage.withRenderingMode(.alwaysTemplate))
-                        .colorMultiply(badgeColor)
-                }
-                .padding(.trailing, -2)
-                .padding(.top, -10)
-                .zIndex(1)
-            }
         }
-        .frame(width: 100)
     }
 
     private func remainingTimeString(time: TimeInterval) -> String {

+ 30 - 2
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -80,6 +80,31 @@ extension Home {
             }
         }
 
+        @ViewBuilder func pumpTimezoneView(_ badgeImage: UIImage, _ badgeColor: Color) -> some View {
+            HStack {
+                Image(uiImage: badgeImage.withRenderingMode(.alwaysTemplate))
+                    .font(.system(size: 14))
+                    .colorMultiply(badgeColor)
+                Text("Timezone offset detected")
+                    .bold()
+                    .font(.system(size: 14))
+                    .foregroundStyle(badgeColor)
+            }
+            .onTapGesture {
+                if state.pumpDisplayState != nil {
+                    // sends user to pump settings
+                    state.setupPump.toggle()
+                }
+            }
+            .frame(maxWidth: .infinity, alignment: .center)
+            .padding(.vertical, 5)
+            .padding(.horizontal, 10)
+            .overlay(
+                Capsule()
+                    .stroke(badgeColor.opacity(0.4), lineWidth: 2)
+            )
+        }
+
         var glucoseView: some View {
             CurrentGlucoseView(
                 timerDate: state.timerDate,
@@ -108,8 +133,6 @@ extension Home {
                 name: state.pumpName,
                 expiresAtDate: state.pumpExpiresAtDate,
                 timerDate: state.timerDate,
-                pumpStatusBadge: state.pumpStatusBadgeImage,
-                pumpStatusBadgeColor: state.pumpStatusBadgeColor,
                 pumpStatusHighlightMessage: state.pumpStatusHighlightMessage,
                 battery: state.batteryFromPersistence
             )
@@ -825,6 +848,11 @@ extension Home {
 
         @ViewBuilder func mainViewElements(_ geo: GeometryProxy) -> some View {
             VStack(spacing: 0) {
+                if let badgeImage = state.pumpStatusBadgeImage, let badgeColor = state.pumpStatusBadgeColor {
+                    pumpTimezoneView(badgeImage, badgeColor)
+                        .padding(.top, 10)
+                        .padding(.horizontal, 20)
+                }
                 ZStack {
                     /// glucose bobble
                     glucoseView