Jonas Björkert 1 год назад
Родитель
Сommit
1f4a80a8d4

+ 0 - 15
LoopFollow/Controllers/NightScout.swift

@@ -51,21 +51,6 @@ extension MainViewController {
         var absorptionTime: Int
     }
     
-    func isStaleData() -> Bool {
-        if bgData.count > 0 {
-            let now = dateTimeUtils.getNowTimeIntervalUTC()
-            let lastReadingTime = bgData.last!.date
-            let secondsAgo = now - lastReadingTime
-            if secondsAgo >= 20*60 {
-                return true
-            } else {
-                return false
-            }
-        } else {
-            return false
-        }
-    }
-        
     func clearOldTempBasal()
     {
         basalData.removeAll()

+ 6 - 2
LoopFollow/Controllers/Nightscout/BGData.swift

@@ -260,11 +260,15 @@ extension MainViewController {
                 Observable.shared.deltaText.value = "+" + Localizer.toDisplayUnits(String(deltaBG))
             }
 
+            // Stale
+            Observable.shared.bgStale.value = deltaTime >= 12
+
             // Apply strikethrough to BGText based on the staleness of the data
+            // Also clear badge if bgvalue is stale
             let bgTextStr = self.BGText.text ?? ""
             let attributeString = NSMutableAttributedString(string: bgTextStr)
             attributeString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: NSRange(location: 0, length: attributeString.length))
-            if deltaTime >= 12 { // Data is stale
+            if Observable.shared.bgStale.value { // Data is stale
                 attributeString.addAttribute(.strikethroughColor, value: UIColor.systemRed, range: NSRange(location: 0, length: attributeString.length))
                 self.updateBadge(val: 0)
             } else { // Data is fresh
@@ -280,7 +284,7 @@ extension MainViewController {
                         bgValue: bgTextStr,
                         trend: Observable.shared.directionText.value,
                         delta: Observable.shared.deltaText.value,
-                        stale: deltaTime >= 12
+                        stale: Observable.shared.bgStale.value
                     )
             }
         }

+ 106 - 75
LoopFollow/Snoozer/SnoozerView.swift

@@ -10,99 +10,130 @@ import SwiftUI
 
 struct SnoozerView: View {
     @ObservedObject var minAgoText = Observable.shared.minAgoText
-    @ObservedObject var bgText = Observable.shared.bgText
+    @ObservedObject var bgText     = Observable.shared.bgText
     @ObservedObject var bgTextColor = Observable.shared.bgTextColor
     @ObservedObject var directionText = Observable.shared.directionText
-    @ObservedObject var deltaText = Observable.shared.deltaText
-    @ObservedObject var bgStale = Observable.shared.bgStale
+    @ObservedObject var deltaText   = Observable.shared.deltaText
+    @ObservedObject var bgStale     = Observable.shared.bgStale
 
     @Binding var snoozeMinutes: Int
     var onSnooze: () -> Void
 
     var body: some View {
-        ZStack {
-            Color.black
-                .edgesIgnoringSafeArea(.all)
+        GeometryReader { geo in
+            ZStack {
+                Color.black
+                    .edgesIgnoringSafeArea(.all)
 
-            VStack(spacing: 0) {
-                VStack(spacing: 0) {
-                    Text(bgText.value)
-                        .font(.system(size: 220, weight: .black))
-                        .minimumScaleFactor(0.5)
-                        .foregroundColor(bgTextColor.value)
-                        .strikethrough(
-                            bgStale.value,
-                            pattern: .solid,
-                            color: bgStale.value ? .red : .clear
-                        )
-                        .frame(maxWidth: .infinity, maxHeight: 167)
+                Group {
+                    if geo.size.width > geo.size.height {
+                        // Landscape: two columns
+                        HStack(spacing: 0) {
+                            leftColumn
+                            rightColumn
+                        }
+                    } else {
+                        // Portrait: single column
+                        VStack(spacing: 0) {
+                            leftColumn
+                            rightColumn
+                        }
+                    }
+                }
+                .frame(width: geo.size.width, height: geo.size.height)
+            }
+        }
+    }
 
-                    Text(directionText.value)
-                        .font(.system(size: 110, weight: .black))
-                        .minimumScaleFactor(0.5)
-                        .foregroundColor(.white)
-                        .frame(maxWidth: .infinity, maxHeight: 96)
+    // MARK: - Left Column (BG / Direction / Delta / Age)
+    private var leftColumn: some View {
+        VStack(spacing: 0) {
+            Text(bgText.value)
+                .font(.system(size: 220, weight: .black))
+                .minimumScaleFactor(0.5)
+                .foregroundColor(bgTextColor.value)
+                .strikethrough(
+                    bgStale.value,
+                    pattern: .solid,
+                    color: bgStale.value ? .red : .clear
+                )
+                .frame(maxWidth: .infinity, maxHeight: 167)
 
-                    Text(deltaText.value)
-                        .font(.system(size: 70))
-                        .minimumScaleFactor(0.5)
-                        .foregroundColor(.white.opacity(0.8))
-                        .frame(maxWidth: .infinity, maxHeight: 78)
+            Text(directionText.value)
+                .font(.system(size: 110, weight: .black))
+                .minimumScaleFactor(0.5)
+                .foregroundColor(.white)
+                .frame(maxWidth: .infinity, maxHeight: 96)
 
-                    Text(minAgoText.value)
-                        .font(.system(size: 70))
-                        .minimumScaleFactor(0.5)
-                        .foregroundColor(.white.opacity(0.6))
-                        .frame(maxWidth: .infinity, maxHeight: 48)
-                }
+            Text(deltaText.value)
+                .font(.system(size: 70))
+                .minimumScaleFactor(0.5)
+                .foregroundColor(.white.opacity(0.8))
+                .frame(maxWidth: .infinity, maxHeight: 78)
+
+            Text(minAgoText.value)
+                .font(.system(size: 70))
+                .minimumScaleFactor(0.5)
+                .foregroundColor(.white.opacity(0.6))
+                .frame(maxWidth: .infinity, maxHeight: 48)
+        }
+        .padding(.top, 16)
+        .padding(.horizontal, 16)
+    }
+
+    // MARK: - Right Column (Clock/Alert + Snooze Controls)
+    private var rightColumn: some View {
+        VStack(spacing: 0) {
+            Spacer()
 
-                // MARK: Clock + optional alert label
-                VStack(spacing: 8) {
-                    Text("19:59"/*time.value*/)
-                        .font(.system(size: 70))
+            // Clock and (optional) alert
+            VStack(spacing: 8) {
+                Text("19:59" /* replace with time.value */)
+                    .font(.system(size: 70))
+                    .minimumScaleFactor(0.5)
+                    .foregroundColor(.white)
+                    .frame(height: 78)
+
+                /*
+                if let alarm = alarmText.value, !alarm.isEmpty {
+                    Text(alarm)
+                        .font(.system(size: 40, weight: .semibold))
+                        .foregroundColor(.red)
                         .minimumScaleFactor(0.5)
-                        .foregroundColor(.white)
-                        .frame(height: 78)
-/*
-                    if let alarm = ""/*alarmText.value*/, !alarm.isEmpty {
-                        Text(alarm)
-                            .font(.system(size: 40, weight: .semibold))
-                            .foregroundColor(.red)
-                            .minimumScaleFactor(0.5)
-                            .lineLimit(1)
-                            .frame(height: 48)
-                    }*/
+                        .lineLimit(1)
+                        .frame(height: 48)
                 }
-                .padding(.vertical, 16)
+                */
+            }
 
-                Spacer()
+            Spacer()
 
-                // MARK: Snooze controls
-                HStack(spacing: 12) {
-                    Text("Snooze for")
-                        .font(.system(size: 20))
-                        .foregroundColor(.white)
-                    Text("\(snoozeMinutes) min")
-                        .font(.system(size: 20, weight: .semibold))
-                        .foregroundColor(.white)
-                    Spacer()
-                    Stepper("", value: $snoozeMinutes, in: 1...60)
-                        .labelsHidden()
-                }
-                .padding(.horizontal, 32)
-                .frame(height: 44)
+            // Snooze controls
+            HStack(spacing: 12) {
+                Text("Snooze for")
+                    .font(.system(size: 20))
+                    .foregroundColor(.white)
+                Text("\(snoozeMinutes) min")
+                    .font(.system(size: 20, weight: .semibold))
+                    .foregroundColor(.white)
+                Spacer()
+                Stepper("", value: $snoozeMinutes, in: 1...60)
+                    .labelsHidden()
+            }
+            .padding(.horizontal, 32)
+            .frame(height: 44)
 
-                Button(action: onSnooze) {
-                    Text("Snooze")
-                        .font(.system(size: 24, weight: .bold))
-                        .frame(maxWidth: .infinity, minHeight: 56)
-                }
-                .background(Color(white: 0.15))
-                .foregroundColor(.white)
-                .cornerRadius(8)
-                .padding(.horizontal, 32)
-                .padding(.bottom, 32)
+            Button(action: onSnooze) {
+                Text("Snooze")
+                    .font(.system(size: 24, weight: .bold))
+                    .frame(maxWidth: .infinity, minHeight: 56)
             }
+            .background(Color(white: 0.15))
+            .foregroundColor(.white)
+            .cornerRadius(8)
+            .padding(.horizontal, 32)
+            .padding(.bottom, 32)
         }
+        .padding(.top, 16)
     }
 }

+ 0 - 5
LoopFollow/Storage/Observable.swift

@@ -24,10 +24,5 @@ class Observable {
     var directionText = ObservableValue<String>(default: "-")
     var deltaText = ObservableValue<String>(default: "+0")
 
-
-    // Work in progress here..
-    var trendArrow = ObservableValue<String>(default: "→")
-    var alarmTitle = ObservableValue<String?>(default: nil)
-
     private init() {}
 }