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

Surface Snooze All as Settings button; drop bobble long-press

trioneer недель назад: 2
Родитель
Сommit
1281fc6d8c

+ 42 - 9
Trio/Sources/Localizations/Main/Localizable.xcstrings

@@ -5474,6 +5474,9 @@
         }
       }
     },
+    "·" : {
+
+    },
     "“Trio” Would Like to Use Bluetooth" : {
       "localizations" : {
         "bg" : {
@@ -21353,6 +21356,7 @@
     },
     "1 hour" : {
       "comment" : "Snooze glucose alerts for 1 hour",
+      "extractionState" : "stale",
       "localizations" : {
         "bg" : {
           "stringUnit" : {
@@ -22106,6 +22110,7 @@
     },
     "3 hours" : {
       "comment" : "Snooze glucose alerts for 3 hours",
+      "extractionState" : "stale",
       "localizations" : {
         "bg" : {
           "stringUnit" : {
@@ -23741,6 +23746,7 @@
     },
     "20 min" : {
       "comment" : "Snooze glucose alerts for 20 minutes",
+      "extractionState" : "stale",
       "localizations" : {
         "bg" : {
           "stringUnit" : {
@@ -48226,6 +48232,9 @@
         }
       }
     },
+    "at least" : {
+
+    },
     "At the default setting, 35% of the calculation is based on the last 24 hours of insulin use, with the remaining 65% considering the last 10 days of data." : {
       "localizations" : {
         "bg" : {
@@ -176145,6 +176154,9 @@
         }
       }
     },
+    "Mutes every Trio alarm for a duration you pick. Critical alerts still pierce the snooze." : {
+
+    },
     "Name" : {
       "comment" : "Preset name",
       "localizations" : {
@@ -189015,9 +189027,6 @@
         }
       }
     },
-    "On by default for all CGM or apps that handle glucose alerts (all Dexcom CGMs, xDrip4iOS). Turn off if you've disabled those and want Trio to alert you instead." : {
-
-    },
     "Once a day (or after a new build is installed), Trio sends a small JSON object to a self-hosted endpoint maintained by the Trio team. No third-party analytics service is involved." : {
 
     },
@@ -193190,9 +193199,6 @@
         }
       }
     },
-    "Override Silence & Focus" : {
-
-    },
     "Override Silence & Focus Mode" : {
 
     },
@@ -193832,6 +193838,9 @@
         }
       }
     },
+    "Overrides Focus" : {
+
+    },
     "Overrides Silence & Focus Mode" : {
 
     },
@@ -230210,9 +230219,21 @@
     "Snooze" : {
 
     },
-    "Snooze (20 min)" : {
+    "Snooze (15 min)" : {
 
     },
+    "Snooze 1 hr" : {
+      "comment" : "Snooze glucose alerts for 1 hour"
+    },
+    "Snooze 3 hrs" : {
+      "comment" : "Snooze glucose alerts for 3 hours"
+    },
+    "Snooze 6 hrs" : {
+      "comment" : "Snooze glucose alerts for 6 hours"
+    },
+    "Snooze 15 min" : {
+      "comment" : "Snooze glucose alerts for 15 minutes"
+    },
     "Snooze Alerts" : {
       "localizations" : {
         "bg" : {
@@ -230337,7 +230358,10 @@
         }
       }
     },
-    "Snooze all (20 min)" : {
+    "Snooze all (15 min)" : {
+
+    },
+    "Snooze All Alarms" : {
 
     },
     "snooze from testview clicked" : {
@@ -250422,7 +250446,10 @@
         }
       }
     },
-    "These alarms are silenced because your CGM app handles them. Turn off \"Use CGM App Alerts\" below to have Trio alert you instead." : {
+    "These alarms are silenced because the %@ app handles CGM alerts. To have Trio notify you instead, turn off \"Use CGM App Alerts\" below." : {
+
+    },
+    "These alarms are silenced because the CGM app handles them. To have Trio notify you instead, turn off \"Use CGM App Alerts\" below." : {
 
     },
     "These thresholds drive the chart band colors, statistics in-range buckets, Live Activity colors, and Contact Image colors." : {
@@ -290791,6 +290818,12 @@
         }
       }
     },
+    "Your CGM app handles alerts (Dexcom G6 / One, G7 / One+, or xDrip4iOS). Turn off to let Trio alert you." : {
+
+    },
+    "Your CGM has no companion app, so Trio handles alarms." : {
+
+    },
     "Your entered amount was limited by your max Bolus setting of %d%@" : {
       "comment" : "For the  Bolus View pop-up",
       "extractionState" : "manual",

+ 0 - 5
Trio/Sources/Modules/Home/View/HomeRootView.swift

@@ -142,11 +142,6 @@ extension Home {
                         state.shouldDisplayCGMSetupSheet.toggle()
                     }
                 }
-                .onLongPressGesture {
-                    let impactHeavy = UIImpactFeedbackGenerator(style: .heavy)
-                    impactHeavy.impactOccurred()
-                    state.showModal(for: .snooze)
-                }
         }
 
         var pumpView: some View {

+ 93 - 34
Trio/Sources/Modules/Settings/View/Subviews/NotificationsView.swift

@@ -15,6 +15,8 @@ struct NotificationsView: BaseView {
     @ObservedObject var state: Settings.StateModel
     @State var notificationsDisabled = false
     @State var showAlert = false
+    @State private var showSnoozeSheet = false
+    @State private var snoozeUntilDate: Date = .distantPast
     @State private var shouldDisplayHint: Bool = false
     @State var hintDetent = PresentationDetent.large
     @State var selectedVerboseHint: AnyView? = AnyView(
@@ -33,45 +35,32 @@ struct NotificationsView: BaseView {
     var body: some View {
         List {
             Section(
-                header: Text("Manage iOS Preferences"),
+                header: Text("Mute Trio Alarms"),
                 content: {
-                    manageNotifications
+                    VStack {
+                        Button {
+                            showSnoozeSheet = true
+                        } label: {
+                            HStack {
+                                Image(systemName: "zzz").foregroundStyle(.tint)
+                                Text("Snooze All Alarms").bold()
+                            }
+                            .font(.title3)
+                        }
+                        .frame(maxWidth: .infinity, alignment: .center)
+                        .buttonStyle(.bordered)
+                    }.padding(.vertical)
                 }
             ).listRowBackground(Color.chart)
 
-            Section {
-                VStack {
+            Section(
+                header: Text("Manage iOS Preferences"),
+                content: {
                     notificationsEnabledStatus
-                    HStack(alignment: .top) {
-                        Text("Notifications give you important Trio information without requiring you to open the app.")
-                            .font(.footnote)
-                            .foregroundColor(.secondary)
-                            .lineLimit(nil)
-                        Spacer()
-                        Button(
-                            action: {
-                                hintLabel = String(localized: "Manage iOS Preferences")
-                                selectedVerboseHint = AnyView(
-                                    VStack(alignment: .leading, spacing: 10) {
-                                        Text(
-                                            "Notifications give you important Trio information without requiring you to open the app."
-                                        )
-                                        Text(
-                                            "Keep these turned ON in your phone’s settings to ensure you receive Trio Notifications, Critical Alerts, and Time Sensitive Notifications."
-                                        )
-                                    }
-                                )
-                                shouldDisplayHint.toggle()
-                            },
-                            label: {
-                                HStack {
-                                    Image(systemName: "questionmark.circle")
-                                }
-                            }
-                        ).buttonStyle(BorderlessButtonStyle())
-                    }.padding(.top)
-                }.padding(.bottom)
-            }.listRowBackground(Color.chart)
+
+                    manageNotifications
+                }
+            ).listRowBackground(Color.chart)
 
             Section(
                 header: Text("Notification Center"),
@@ -84,7 +73,12 @@ struct NotificationsView: BaseView {
 
                     Text("Day & Night Windows")
                         .navigationLink(to: .alarmWindows, from: self)
+                }
+            ).listRowBackground(Color.chart)
 
+            Section(
+                header: Text("Other Notifications"),
+                content: {
                     if #available(iOS 16.2, *) {
                         Text("Live Activity").navigationLink(to: .liveActivitySettings, from: self)
                     }
@@ -118,6 +112,9 @@ struct NotificationsView: BaseView {
                 sheetTitle: String(localized: "Help", comment: "Help sheet title")
             )
         }
+        .sheet(isPresented: $showSnoozeSheet) {
+            snoozeSheet
+        }
         .scrollContentBackground(.hidden)
         .background(appState.trioBackgroundColor(for: colorScheme))
         .navigationTitle("Notifications")
@@ -165,4 +162,66 @@ extension NotificationsView {
             onOff(!notificationsDisabled)
         }
     }
+
+    /// Inline sheet replacement for the old Snooze module. Lists the four
+    /// canonical snooze durations and routes through `TrioAlertManager`
+    /// directly — no module / router roundtrip, no legacy `GlucoseAlarm`
+    /// shape, no obsolete 20 min option.
+    private var snoozeSheet: some View {
+        NavigationStack {
+            List {
+                if snoozeUntilDate > Date() {
+                    Section {
+                        HStack {
+                            Image(systemName: "moon.zzz.fill").foregroundStyle(.tint)
+                            Text(String(
+                                format: String(localized: "Snoozed until %@"),
+                                snoozeUntilDate.formatted(date: .omitted, time: .shortened)
+                            ))
+                                .font(.headline)
+                        }
+                    }.listRowBackground(Color.chart)
+                }
+                Section(footer: Text(
+                    "Pick a duration to mute every Trio alarm. Critical alerts (e.g. occlusion, urgent low) still pierce the snooze."
+                )) {
+                    ForEach(NotificationResponseAction.allCases, id: \.self) { action in
+                        Button {
+                            applySnooze(action.duration)
+                        } label: {
+                            HStack {
+                                Text(action.localizedTitle).foregroundStyle(.primary)
+                                Spacer()
+                                Image(systemName: "chevron.right")
+                                    .foregroundColor(.gray)
+                                    .font(.footnote)
+                            }
+                        }
+                    }
+                }.listRowBackground(Color.chart)
+            }
+            .scrollContentBackground(.hidden)
+            .background(appState.trioBackgroundColor(for: colorScheme))
+            .navigationTitle("Snooze Alerts")
+            .navigationBarTitleDisplayMode(.inline)
+            .toolbar {
+                ToolbarItem(placement: .topBarTrailing) {
+                    Button("Close") { showSnoozeSheet = false }
+                }
+            }
+            .onAppear {
+                snoozeUntilDate = UserDefaults.standard
+                    .object(forKey: "UserNotificationsManager.snoozeUntilDate") as? Date ?? .distantPast
+            }
+        }
+    }
+
+    private func applySnooze(_ duration: TimeInterval) {
+        let trioAlertManager = resolver.resolve(TrioAlertManager.self)
+        Task { @MainActor in
+            await trioAlertManager?.applySnooze(for: duration)
+            snoozeUntilDate = Date().addingTimeInterval(duration)
+            showSnoozeSheet = false
+        }
+    }
 }