Jelajahi Sumber

adjust in-app backgroundColor to be same as APN; init identifer for subtype in APN

kskandis 1 tahun lalu
induk
melakukan
80a7e5e437

+ 18 - 20
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -60,8 +60,8 @@ extension Home {
 
         func sendTestRepeat(storedMessages: [MessageContent], repeats: Bool = false) { // TODO: REMOVE!!!
             if repeats == true {
-                for loop in 0 ... 5 {
-                    for i in 0 ... storedMessages.count - 1 {
+                for _ in 0 ... 5 {
+                    for _ in 0 ... storedMessages.count - 1 {
                         var count = 0
                         _ = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { t in
                             print(count)
@@ -78,7 +78,9 @@ extension Home {
                 for i in 0 ... storedMessages.count - 1 {
                     print(i)
                     print(storedMessages[i].content)
-                    router.alertMessage.send(storedMessages[i])
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
+                        router.alertMessage.send(storedMessages[i])
+                    }
                 }
             }
         }
@@ -95,7 +97,7 @@ extension Home {
                 type: MessageType.info,
                 subtype: .algorithm,
                 title: "Trio Not Active",
-                useAPN: false,
+                useAPN: true,
                 trigger: firstTrigger
             )
             debug(
@@ -110,7 +112,7 @@ extension Home {
                 type: MessageType.warning,
                 subtype: .algorithm,
                 title: "Trio Not Active",
-                useAPN: false,
+                useAPN: true,
                 trigger: secondTrigger
             )
             debug(
@@ -127,14 +129,14 @@ extension Home {
             var messageCont: MessageContent
 
             sendTestTriggerMessage()
-//            return
+
             messageCont = MessageContent(
-                // content: "68 mg/dL" + "↔︎" + "-1" + "\n" + "Plugin CGM Source",
-                content: "68 mg/dL" + "↔︎" + "-1",
+                content: "68 mg/dL" + "↔︎" + "-1" + "\n" + "Plugin CGM Source",
                 type: MessageType.warning,
                 subtype: .glucose,
                 title: "LOWALERT! 68 mg/dL" + "↔︎" + "-1",
-                useAPN: true
+                useAPN: true,
+                action: .snooze
             )
             router.alertMessage.send(messageCont)
 
@@ -143,6 +145,7 @@ extension Home {
                 type: MessageType.error, // errorPump
                 subtype: .pump,
                 title: "Critical Pod Fault 008",
+                useAPN: true,
                 action: .pumpConfig
             )
             storedMessages.append(messageCont)
@@ -158,7 +161,8 @@ extension Home {
                 content: "10 U insulin or less remaining in Pod. Change Pod soon.",
                 type: MessageType.warning,
                 subtype: .pump,
-                title: "Low Reservoir"
+                title: "Low Reservoir",
+                useAPN: true
             )
             storedMessages.append(messageCont)
 
@@ -171,10 +175,11 @@ extension Home {
             storedMessages.append(messageCont)
 
             messageCont = MessageContent(
-                content: "83 mg/dL" + "↔︎" + "-1" + "\n" + "Plugin CGM Source",
-                type: MessageType.other,
+                content: "83 mg/dL" + "↔︎" + "-1", // + "\n" + "Plugin CGM Source",
+                type: MessageType.info,
                 subtype: .glucose,
-                title: "Glucose 83 mg/dL" + "↔︎" + "-1"
+                title: "Glucose 83 mg/dL" + "↔︎" + "-1",
+                action: .snooze
             )
             storedMessages.append(messageCont)
             messageCont = MessageContent(
@@ -200,14 +205,7 @@ extension Home {
 //            info(.apsManager, "Temp Basal failed with error")
 //            info(.apsManager, "Pump not suspended by Announcement")
 
-//            sendTestRepeat(storedMessages: storedMessages, repeats: true)
-
             sendTestRepeat(storedMessages: storedMessages, repeats: false)
-            for i in 0 ... storedMessages.count - 1 {
-                print(i)
-                print(storedMessages[i].content)
-                router.alertMessage.send(storedMessages[i])
-            }
         }
 
         var bolusProgressFormatter: NumberFormatter {

+ 32 - 14
FreeAPS/Sources/Modules/Main/MainStateModel.swift

@@ -194,7 +194,6 @@ extension Main {
             var config = SwiftMessages.defaultConfig
             let view = MessageView.viewFromNib(layout: .cardView)
 
-//            viewRespectsSystemMinimumLayoutMargins = false
             view.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
             config.prefersStatusBarHidden = true
 
@@ -231,7 +230,7 @@ extension Main {
             switch message.type {
             case .info,
                  .other:
-                config.duration = .seconds(seconds: 5)//.automatic
+                config.duration = .seconds(seconds: 5)
                 titleContent = message.title != "" ? message.title : NSLocalizedString("Info", comment: "Info title")
             case .warning:
                 config.duration = .forever
@@ -279,8 +278,7 @@ extension Main {
                 .sink { message in
                     guard !self.isApnPumpConfigAction(message) else { return }
                     guard self.allowNotify(message) else { return }
-//                    self.queueMessageIfNeeded(message) // TODO: Remove if Batched Info and Throttled APNs are NOT in-scope
-                    self.showAlertMessage(message) // TODO: Call this if Batched Info and Throttled APNs are NOT in-scope
+                    self.showAlertMessage(message)
                 }
                 .store(in: &lifetime)
 
@@ -310,24 +308,44 @@ extension MessageView {
     }
 
     func customConfigureTheme(colorSchemePreference: ColorSchemeOption) {
-        let defaultSystemColorScheme = currentColorScheme() // UIColor.defaultSystemBackgroundColor
+        let defaultSystemColorScheme = currentColorScheme()
         var backgroundColor = UIColor.systemBackground
         var foregroundColor = UIColor.white
-        // Color.gray.opacity(0.1) is used by MainRootView but is translucent
-        // lightGray is same color as MainRootView background and systemGray6 is a shade darker
-        // systemGray5 is a shade darker than systemGray6 and gray is a few shades darker
-        // systemBackground is the same as systemGray6 when iOS is light mode
+        let iOSlightTrioDark = UIColor(
+            red: 122 / 255,
+            green: 146 / 255,
+            blue: 163 / 255,
+            alpha: 0.95
+        )
+        let iOSlightTrioLight = UIColor(
+            red: 234 / 255,
+            green: 236 / 255,
+            blue: 237 / 255,
+            alpha: 1
+        )
+        let iOSlightTrioSystem = UIColor(
+            red: 233 / 255,
+            green: 235 / 255,
+            blue: 236 / 255,
+            alpha: 0.95
+        )
+        let iOSdarkTrioDark = UIColor(
+            red: 16 / 255,
+            green: 37 / 255,
+            blue: 53 / 255,
+            alpha: 0.95
+        )
         switch colorSchemePreference {
         case .systemDefault:
-            backgroundColor = defaultSystemColorScheme == .light ? UIColor.systemBackground :
-                UIColor(Color.black.opacity(0.9))
+            backgroundColor = defaultSystemColorScheme == .light ? iOSlightTrioSystem :
+                iOSdarkTrioDark
             foregroundColor = UIColor.label
         case .dark:
-            backgroundColor = defaultSystemColorScheme == .light ? UIColor.systemGray5 :
-                UIColor(Color.black.opacity(0.9))
+            backgroundColor = defaultSystemColorScheme == .light ? iOSlightTrioDark :
+                iOSdarkTrioDark
             foregroundColor = defaultSystemColorScheme == .light ? UIColor.black : UIColor.white
         case .light:
-            backgroundColor = defaultSystemColorScheme == .light ? .systemGray6 : UIColor
+            backgroundColor = defaultSystemColorScheme == .light ? iOSlightTrioLight : UIColor
                 .gray
             foregroundColor = defaultSystemColorScheme == .light ? UIColor.black : UIColor.white
         }

+ 19 - 2
FreeAPS/Sources/Services/UserNotifications/UserNotificationsManager.swift

@@ -484,6 +484,7 @@ final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, In
 extension BaseUserNotificationsManager: alertMessageNotificationObserver {
     func alertMessageNotification(_ message: MessageContent) {
         let content = UNMutableNotificationContent()
+        var identifier: Identifier = .alertMessageNotification
 
         if message.title == "" {
             switch message.type {
@@ -491,7 +492,7 @@ extension BaseUserNotificationsManager: alertMessageNotificationObserver {
                 content.title = NSLocalizedString("Info", comment: "Info title")
             case .warning:
                 content.title = NSLocalizedString("Warning", comment: "Warning title")
-            case .error: // .errorPump:
+            case .error:
                 content.title = NSLocalizedString("Error", comment: "Error title")
             default:
                 content.title = message.title
@@ -499,6 +500,22 @@ extension BaseUserNotificationsManager: alertMessageNotificationObserver {
         } else {
             content.title = message.title
         }
+        switch message.subtype {
+        case .pump:
+            identifier = .pumpNotification
+        case .carb:
+            identifier = .carbsRequiredNotification
+        case .glucose:
+            identifier = .glucocoseNotification
+        case .algorithm:
+            if message.trigger != nil {
+                identifier = .noLoopFirstNotification
+            } else {
+                identifier = .alertMessageNotification
+            }
+        default:
+            identifier = .alertMessageNotification
+        }
         switch message.action {
         case .snooze:
             content.userInfo[NotificationAction.key] = NotificationAction.snooze.rawValue
@@ -510,7 +527,7 @@ extension BaseUserNotificationsManager: alertMessageNotificationObserver {
         content.body = NSLocalizedString(message.content, comment: "Info message")
         content.sound = .default
         addRequest(
-            identifier: .alertMessageNotification,
+            identifier: identifier,
             content: content,
             deleteOld: true,
             trigger: message.trigger,