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

Strikethrough and no seconds when stale

Jonas Björkert 2 лет назад
Родитель
Сommit
0ca2ab7cea

+ 1 - 1
LoopFollow/Application/Base.lproj/Main.storyboard

@@ -362,7 +362,7 @@
                                         <nil key="textColor"/>
                                         <nil key="highlightedColor"/>
                                         <variation key="heightClass=regular-widthClass=compact">
-                                            <fontDescription key="fontDescription" type="system" pointSize="65"/>
+                                            <fontDescription key="fontDescription" type="system" pointSize="40"/>
                                         </variation>
                                     </label>
                                     <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="xzZ-jc-k2v">

+ 24 - 21
LoopFollow/Controllers/Timers.swift

@@ -41,10 +41,7 @@ extension MainViewController {
                                            repeats: true)
     }
     
-    // Updates Min Ago display
-    @objc func minAgoTimerDidEnd(_ timer:Timer) {
-        
-        // print("min ago timer ended")
+    @objc func minAgoTimerDidEnd(_ timer: Timer) {
         if bgData.count > 0 {
             let bgSeconds = bgData.last!.date
             let now = Date().timeIntervalSince1970
@@ -54,36 +51,42 @@ extension MainViewController {
             let formatter = DateComponentsFormatter()
             formatter.unitsStyle = .positional // Use the appropriate positioning for the current locale
             
-            if secondsAgo < 270 {
-                formatter.allowedUnits = [ .minute] // Units to display in the formatted string
+            if secondsAgo >= 720 { // 720 seconds = 12 minutes
+                formatter.allowedUnits = [.minute] // Only show minutes after 12 minutes have passed
+            } else if secondsAgo < 270 { // Less than 4.5 minutes
+                formatter.allowedUnits = [.minute] // Show only minutes if less than 4.5 minutes
             } else {
-                formatter.allowedUnits = [ .minute, .second] // Units to display in the formatted string
+                formatter.allowedUnits = [.minute, .second] // Show minutes and seconds otherwise
             }
             
+            let formattedDuration = formatter.string(from: secondsAgo) ?? ""
+            let minAgoDisplayText = formattedDuration + " min ago"
             
-            //formatter.zeroFormattingBehavior = [ .pad ] // Pad with zeroes where appropriate for the locale
-            let formattedDuration = formatter.string(from: secondsAgo)
-            
-            MinAgoText.text = formattedDuration ?? ""
-            MinAgoText.text! += " min ago"
-            latestMinAgoString = formattedDuration ?? ""
-            latestMinAgoString += " min ago"
+            MinAgoText.text = minAgoDisplayText
+            latestMinAgoString = minAgoDisplayText
             
             if let snoozer = self.tabBarController!.viewControllers?[2] as? SnoozeViewController {
-                snoozer.MinAgoLabel.text = formattedDuration ?? ""
-                snoozer.MinAgoLabel.text! += " min ago"
-            } else { return }
-            
+                snoozer.MinAgoLabel.text = minAgoDisplayText
+                
+                let bgLabelText = snoozer.BGLabel.attributedText?.string ?? ""
+                let bgLabelAttributes = snoozer.BGLabel.attributedText?.attributes(at: 0, effectiveRange: nil) ?? [:]
+                let attributeString = NSMutableAttributedString(string: bgLabelText, attributes: bgLabelAttributes)
+                
+                // Apply strikethrough in system red if more than 12 minutes old
+                if secondsAgo >= 720 { // 720 seconds = 12 minutes
+                    attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: NSRange(location: 0, length: attributeString.length))
+                    attributeString.addAttribute(NSAttributedString.Key.strikethroughColor, value: UIColor.systemRed, range: NSRange(location: 0, length: attributeString.length))
+                }
+                snoozer.BGLabel.attributedText = attributeString
+            }
         } else {
             MinAgoText.text = ""
             latestMinAgoString = ""
             
             if let snoozer = self.tabBarController!.viewControllers?[2] as? SnoozeViewController {
                 snoozer.MinAgoLabel.text = ""
-            } else { return }
-            
+            }
         }
-        
     }
     
     // Runs a 60 second timer when an alarm is snoozed

+ 0 - 20
LoopFollow/ViewControllers/MainViewController.swift

@@ -425,26 +425,6 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
         showHideNSDetails()
     }
     
-    
-
-    //update Min Ago Text. We need to call this separately because it updates between readings
-    func updateMinAgo(){
-        if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Update min ago text") }
-        guard let snoozer = self.tabBarController!.viewControllers?[2] as? SnoozeViewController else { return }
-        if bgData.count > 0 {
-            let deltaTime = (TimeInterval(Date().timeIntervalSince1970)-bgData[bgData.count - 1].date) / 60
-            minAgoBG = Double(TimeInterval(Date().timeIntervalSince1970)-bgData[bgData.count - 1].date)
-            MinAgoText.text = String(Int(deltaTime)) + " min ago"
-            snoozer.MinAgoLabel.text = String(Int(deltaTime)) + " min ago"
-            latestMinAgoString = String(Int(deltaTime)) + " min ago"
-        } else {
-            MinAgoText.text = ""
-            snoozer.MinAgoLabel.text = ""
-            latestMinAgoString = ""
-        }
-        
-    }
-    
     //Clear the info data before next pull. This ensures we aren't displaying old data if something fails.
     func clearLastInfoData(index: Int){
         tableData[index].value = ""