Procházet zdrojové kódy

Header View UI improvements.
Dynamic fonts for Header View elements.
More prominent Glucose.
Improved horisontal alignment.
Display time delta instad of timestamp also for current glucose.

Jon Mårtensson před 3 roky
rodič
revize
f139d72e27

+ 29 - 15
FreeAPS/Sources/Modules/Home/View/Header/CurrentGlucoseView.swift

@@ -27,6 +27,14 @@ struct CurrentGlucoseView: View {
         return formatter
         return formatter
     }
     }
 
 
+    private var timaAgoFormatter: NumberFormatter {
+        let formatter = NumberFormatter()
+        formatter.numberStyle = .decimal
+        formatter.maximumFractionDigits = 0
+        formatter.negativePrefix = ""
+        return formatter
+    }
+
     private var dateFormatter: DateFormatter {
     private var dateFormatter: DateFormatter {
         let formatter = DateFormatter()
         let formatter = DateFormatter()
         formatter.timeStyle = .short
         formatter.timeStyle = .short
@@ -34,8 +42,8 @@ struct CurrentGlucoseView: View {
     }
     }
 
 
     var body: some View {
     var body: some View {
-        VStack(alignment: .center, spacing: 6) {
-            HStack(spacing: 8) {
+        VStack(alignment: .center) {
+            HStack {
                 Text(
                 Text(
                     recentGlucose?.glucose
                     recentGlucose?.glucose
                         .map {
                         .map {
@@ -43,24 +51,30 @@ struct CurrentGlucoseView: View {
                                 .string(from: Double(units == .mmolL ? $0.asMmolL : Decimal($0)) as NSNumber)! }
                                 .string(from: Double(units == .mmolL ? $0.asMmolL : Decimal($0)) as NSNumber)! }
                         ?? "--"
                         ?? "--"
                 )
                 )
-                .font(.system(size: 24, weight: .bold))
-                .fixedSize()
+                .font(.title).fontWeight(.bold)
                 .foregroundColor(alarm == nil ? colorOfGlucose : .loopRed)
                 .foregroundColor(alarm == nil ? colorOfGlucose : .loopRed)
-                image.padding(.bottom, 2)
 
 
-            }.padding(.leading, 4)
-            HStack(alignment: .lastTextBaseline, spacing: 2) {
+                image
+            }
+            HStack {
+                let minutes = (recentGlucose?.dateString.timeIntervalSinceNow ?? 0) / 60
+                let text = timaAgoFormatter.string(for: Double(minutes)) ?? ""
                 Text(
                 Text(
-                    recentGlucose.map { dateFormatter.string(from: $0.dateString) } ?? "--"
-                ).font(.caption2).foregroundColor(.secondary)
+                    text == "0" ? "< 1 " + NSLocalizedString("min", comment: "Short form for minutes") : (
+                        text + " " +
+                            NSLocalizedString("min", comment: "Short form for minutes") + " "
+                    )
+                )
+                .font(.caption2).foregroundColor(.secondary)
+
                 Text(
                 Text(
                     delta
                     delta
-                        .map { deltaFormatter.string(from: Double(units == .mmolL ? $0.asMmolL : Decimal($0)) as NSNumber)!
-                        } ??
-                        "--"
-
-                ).font(.system(size: 12, weight: .bold))
-            }
+                        .map {
+                            deltaFormatter.string(from: Double(units == .mmolL ? $0.asMmolL : Decimal($0)) as NSNumber)!
+                        } ?? "--"
+                )
+                .font(.caption2).foregroundColor(.secondary)
+            }.frame(alignment: .top)
         }
         }
     }
     }
 
 

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

@@ -21,13 +21,13 @@ struct LoopView: View {
         return formatter
         return formatter
     }
     }
 
 
-    private let rect = CGRect(x: 0, y: 0, width: 32, height: 32)
+    private let rect = CGRect(x: 0, y: 0, width: 28, height: 28)
     var body: some View {
     var body: some View {
         VStack(alignment: .center) {
         VStack(alignment: .center) {
             ZStack {
             ZStack {
                 Circle()
                 Circle()
-                    .strokeBorder(color, lineWidth: 6)
-                    .frame(width: rect.width, height: rect.height)
+                    .strokeBorder(color, lineWidth: 5)
+                    .frame(width: rect.width, height: rect.height, alignment: .bottom)
                     .mask(mask(in: rect).fill(style: FillStyle(eoFill: true)))
                     .mask(mask(in: rect).fill(style: FillStyle(eoFill: true)))
                 if isLooping {
                 if isLooping {
                     ProgressView()
                     ProgressView()
@@ -51,7 +51,7 @@ struct LoopView: View {
         if minAgo > 1440 {
         if minAgo > 1440 {
             return "--"
             return "--"
         }
         }
-        return "\(minAgo) " + NSLocalizedString("min ago", comment: "Minutes ago since last loop")
+        return "\(minAgo) " + NSLocalizedString("min", comment: "Minutes ago since last loop")
     }
     }
 
 
     private var color: Color {
     private var color: Color {

+ 13 - 10
FreeAPS/Sources/Modules/Home/View/Header/PumpView.swift

@@ -27,28 +27,30 @@ struct PumpView: View {
                     Image(systemName: "drop.fill")
                     Image(systemName: "drop.fill")
                         .resizable()
                         .resizable()
                         .aspectRatio(contentMode: .fit)
                         .aspectRatio(contentMode: .fit)
-                        .frame(height: 8)
+                        .frame(maxHeight: 10)
                         .foregroundColor(reservoirColor)
                         .foregroundColor(reservoirColor)
                     if reservoir == 0xDEAD_BEEF {
                     if reservoir == 0xDEAD_BEEF {
-                        Text("50+ " + NSLocalizedString("U", comment: "Insulin unit")).font(.system(size: 12, weight: .bold))
+                        Text("50+ " + NSLocalizedString("U", comment: "Insulin unit")).font(.footnote)
+                            .fontWeight(.bold)
                     } else {
                     } else {
                         Text(
                         Text(
                             reservoirFormatter
                             reservoirFormatter
                                 .string(from: reservoir as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit")
                                 .string(from: reservoir as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit")
                         )
                         )
-                        .font(.system(size: 12, weight: .bold))
+                        .font(.footnote).fontWeight(.bold)
                     }
                     }
-                }
+                }.frame(alignment: .top)
             }
             }
             if let battery = battery, battery.display ?? false, expiresAtDate == nil {
             if let battery = battery, battery.display ?? false, expiresAtDate == nil {
                 HStack {
                 HStack {
                     Image(systemName: "battery.100")
                     Image(systemName: "battery.100")
                         .resizable()
                         .resizable()
                         .aspectRatio(contentMode: .fit)
                         .aspectRatio(contentMode: .fit)
-                        .frame(height: 8)
+                        .frame(maxHeight: 10)
                         .foregroundColor(batteryColor)
                         .foregroundColor(batteryColor)
-                    Text("\(Int(battery.percent ?? 100)) %").font(.system(size: 12, weight: .bold))
-                }
+                    Text("\(Int(battery.percent ?? 100)) %").font(.footnote)
+                        .fontWeight(.bold)
+                }.frame(alignment: .bottom)
             }
             }
 
 
             if let date = expiresAtDate {
             if let date = expiresAtDate {
@@ -56,10 +58,11 @@ struct PumpView: View {
                     Image(systemName: "stopwatch.fill")
                     Image(systemName: "stopwatch.fill")
                         .resizable()
                         .resizable()
                         .aspectRatio(contentMode: .fit)
                         .aspectRatio(contentMode: .fit)
-                        .frame(height: 8)
+                        .frame(maxHeight: 10)
                         .foregroundColor(timerColor)
                         .foregroundColor(timerColor)
-                    Text(remainingTimeString(time: date.timeIntervalSince(timerDate))).font(.system(size: 12, weight: .bold))
-                }
+                    Text(remainingTimeString(time: date.timeIntervalSince(timerDate))).font(.footnote)
+                        .fontWeight(.bold)
+                }.frame(alignment: .bottom)
             }
             }
         }
         }
     }
     }

+ 8 - 8
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -21,7 +21,7 @@ extension Home {
         @State var cv_ = ""
         @State var cv_ = ""
         @State var sd_ = ""
         @State var sd_ = ""
         @State var CVorSD = ""
         @State var CVorSD = ""
-        // Switch between Loops and Errors when tapping in ststPanel
+        // Switch between Loops and Errors when tapping in statPanel
         @State var loopStatTitle = NSLocalizedString("Loops", comment: "Nr of Loops in statPanel")
         @State var loopStatTitle = NSLocalizedString("Loops", comment: "Nr of Loops in statPanel")
 
 
         private var numberFormatter: NumberFormatter {
         private var numberFormatter: NumberFormatter {
@@ -71,29 +71,29 @@ extension Home {
                 Spacer()
                 Spacer()
             }
             }
             .frame(maxWidth: .infinity)
             .frame(maxWidth: .infinity)
-            .frame(maxHeight: 70)
             .padding(.top, geo.safeAreaInsets.top)
             .padding(.top, geo.safeAreaInsets.top)
+            .padding(.bottom)
             .background(Color.gray.opacity(0.2))
             .background(Color.gray.opacity(0.2))
         }
         }
 
 
         var cobIobView: some View {
         var cobIobView: some View {
             VStack(alignment: .leading, spacing: 12) {
             VStack(alignment: .leading, spacing: 12) {
                 HStack {
                 HStack {
-                    Text("IOB").font(.caption2).foregroundColor(.secondary)
+                    Text("IOB").font(.footnote).foregroundColor(.secondary)
                     Text(
                     Text(
                         (numberFormatter.string(from: (state.suggestion?.iob ?? 0) as NSNumber) ?? "0") +
                         (numberFormatter.string(from: (state.suggestion?.iob ?? 0) as NSNumber) ?? "0") +
                             NSLocalizedString(" U", comment: "Insulin unit")
                             NSLocalizedString(" U", comment: "Insulin unit")
                     )
                     )
-                    .font(.system(size: 12, weight: .bold))
-                }
+                    .font(.footnote).fontWeight(.bold)
+                }.frame(alignment: .top)
                 HStack {
                 HStack {
-                    Text("COB").font(.caption2).foregroundColor(.secondary)
+                    Text("COB").font(.footnote).foregroundColor(.secondary)
                     Text(
                     Text(
                         (numberFormatter.string(from: (state.suggestion?.cob ?? 0) as NSNumber) ?? "0") +
                         (numberFormatter.string(from: (state.suggestion?.cob ?? 0) as NSNumber) ?? "0") +
                             NSLocalizedString(" g", comment: "gram of carbs")
                             NSLocalizedString(" g", comment: "gram of carbs")
                     )
                     )
-                    .font(.system(size: 12, weight: .bold))
-                }
+                    .font(.footnote).fontWeight(.bold)
+                }.frame(alignment: .bottom)
             }
             }
         }
         }