Переглянути джерело

Change stopwatch exchange for time-dependent hourglass SF Symbol nightscout/Trio#530

Deniz Cengiz 1 рік тому
батько
коміт
c98259c5f2
1 змінених файлів з 39 додано та 22 видалено
  1. 39 22
      Trio/Sources/Modules/Home/View/Header/PumpView.swift

+ 39 - 22
Trio/Sources/Modules/Home/View/Header/PumpView.swift

@@ -16,6 +16,23 @@ struct PumpView: View {
         return formatter
         return formatter
     }
     }
 
 
+    private var hourglassIcon: String {
+        guard let expiration = expiresAtDate else { return "hourglass" }
+
+        let hoursRemaining = expiration.timeIntervalSince(timerDate) / 3600
+
+        switch hoursRemaining {
+        case 60 ... 72:
+            return "hourglass.bottomhalf.filled"
+        case 12 ..< 60:
+            return "hourglass"
+        case 0 ..< 12:
+            return "hourglass.tophalf.filled"
+        default:
+            return "hourglass"
+        }
+    }
+
     var body: some View {
     var body: some View {
         if let pumpStatusHighlightMessage = pumpStatusHighlightMessage { // display message instead pump info
         if let pumpStatusHighlightMessage = pumpStatusHighlightMessage { // display message instead pump info
             VStack(alignment: .center) {
             VStack(alignment: .center) {
@@ -79,28 +96,28 @@ struct PumpView: View {
                 }
                 }
 
 
                 if let date = expiresAtDate {
                 if let date = expiresAtDate {
-                    HStack {
-                        Image(systemName: "stopwatch.fill")
-                            .font(.callout)
-                            .foregroundStyle(timerColor)
-
-                        let remainingTimeString = remainingTimeString(time: date.timeIntervalSince(timerDate))
-
-                        Text(remainingTimeString)
-                            .font(date.timeIntervalSince(timerDate) > 0 ? .callout : .subheadline)
-                            .fontWeight(.bold)
-                            .fontDesign(.rounded)
-                            .lineLimit(2)
-                            .multilineTextAlignment(.leading)
-                            .frame(
-                                // If the string is > 6 chars, i.e., exceeds "xd yh", limit width to 80 pts
-                                // This forces the "Replace pod" string to wrap to 2 lines.
-                                maxWidth: remainingTimeString.count > 6 ? 80 : .infinity,
-                                alignment: .leading
-                            )
-                    }
-                    // aligns the stopwatch icon exactly with the first pixel of the reservoir icon
-                    .padding(.leading, date.timeIntervalSince(timerDate) > 0 ? 12 : 0)
+                HStack {
+                    Image(systemName: hourglassIcon)
+                        .font(.callout)
+                        .foregroundStyle(timerColor)
+
+                    let remainingTimeString = remainingTimeString(time: date.timeIntervalSince(timerDate))
+
+                    Text(remainingTimeString)
+                        .font(date.timeIntervalSince(timerDate) > 0 ? .callout : .subheadline)
+                        .fontWeight(.bold)
+                        .fontDesign(.rounded)
+                        .lineLimit(2)
+                        .multilineTextAlignment(.leading)
+                        .frame(
+                            // If the string is > 6 chars, i.e., exceeds "xd yh", limit width to 80 pts
+                            // This forces the "Replace pod" string to wrap to 2 lines.
+                            maxWidth: remainingTimeString.count > 6 ? 80 : .infinity,
+                            alignment: .leading
+                        )
+                }
+                // aligns the stopwatch icon exactly with the first pixel of the reservoir icon
+                .padding(.leading, date.timeIntervalSince(timerDate) > 0 ? 12 : 0)
                 }
                 }
             }
             }
         }
         }