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

Restore long-press snooze sheet on glucose view

trioneer 1 неделя назад
Родитель
Сommit
5c38a0e1db

+ 4 - 0
Trio.xcodeproj/project.pbxproj

@@ -677,6 +677,7 @@
 		DD1745262C55526F00211FAC /* SMBSettingsRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD1745252C55526F00211FAC /* SMBSettingsRootView.swift */; };
 		DD1745292C55642100211FAC /* SettingInputSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD1745282C55642100211FAC /* SettingInputSection.swift */; };
 		DD17452B2C556E8100211FAC /* SettingInputHintView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD17452A2C556E8100211FAC /* SettingInputHintView.swift */; };
+		DD500A712807000000000101 /* SnoozeAllSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD500A712807000000000100 /* SnoozeAllSheet.swift */; };
 		DD17452E2C55AE4800211FAC /* TargetBehavoirDataFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD17452D2C55AE4800211FAC /* TargetBehavoirDataFlow.swift */; };
 		DD1745302C55AE5300211FAC /* TargetBehaviorProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD17452F2C55AE5300211FAC /* TargetBehaviorProvider.swift */; };
 		DD1745322C55AE6000211FAC /* TargetBehavoirStateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD1745312C55AE6000211FAC /* TargetBehavoirStateModel.swift */; };
@@ -1676,6 +1677,7 @@
 		DD1745252C55526F00211FAC /* SMBSettingsRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SMBSettingsRootView.swift; sourceTree = "<group>"; };
 		DD1745282C55642100211FAC /* SettingInputSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingInputSection.swift; sourceTree = "<group>"; };
 		DD17452A2C556E8100211FAC /* SettingInputHintView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingInputHintView.swift; sourceTree = "<group>"; };
+		DD500A712807000000000100 /* SnoozeAllSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnoozeAllSheet.swift; sourceTree = "<group>"; };
 		DD17452D2C55AE4800211FAC /* TargetBehavoirDataFlow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TargetBehavoirDataFlow.swift; sourceTree = "<group>"; };
 		DD17452F2C55AE5300211FAC /* TargetBehaviorProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TargetBehaviorProvider.swift; sourceTree = "<group>"; };
 		DD1745312C55AE6000211FAC /* TargetBehavoirStateModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TargetBehavoirStateModel.swift; sourceTree = "<group>"; };
@@ -2672,6 +2674,7 @@
 				DD1745282C55642100211FAC /* SettingInputSection.swift */,
 				48B83503461B4F8D97B30115 /* SettingsSearchHighlight.swift */,
 				DD17452A2C556E8100211FAC /* SettingInputHintView.swift */,
+				DD500A712807000000000100 /* SnoozeAllSheet.swift */,
 			);
 			path = Views;
 			sourceTree = "<group>";
@@ -5015,6 +5018,7 @@
 				19D466A729AA2C22004D5F33 /* MealSettingsStateModel.swift in Sources */,
 				AC19EF2C94084B5BA0175D1D /* SettingsSearchHighlight.swift in Sources */,
 				DD17452B2C556E8100211FAC /* SettingInputHintView.swift in Sources */,
+				DD500A712807000000000101 /* SnoozeAllSheet.swift in Sources */,
 				38E44528274E401C00EC9A94 /* Protected.swift in Sources */,
 				DD3F1F8B2D9E08B600DCE7B3 /* NightscoutLoginStepView.swift in Sources */,
 				3811DEB625C9D88300A708ED /* UnlockManager.swift in Sources */,

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

@@ -34,6 +34,7 @@ extension Home {
         @State var selectedTab: Int = 0
         @State var showPumpSelection: Bool = false
         @State var showCGMSelection: Bool = false
+        @State var showSnoozeSheet: Bool = false
         @State var notificationsDisabled = false
         @State var timeButtons: [TimePicker] = [
             TimePicker(active: false, hours: 4),
@@ -142,6 +143,11 @@ extension Home {
                         state.shouldDisplayCGMSetupSheet.toggle()
                     }
                 }
+                .onLongPressGesture {
+                    let impactHeavy = UIImpactFeedbackGenerator(style: .heavy)
+                    impactHeavy.impactOccurred()
+                    showSnoozeSheet = true
+                }
         }
 
         var pumpView: some View {
@@ -986,6 +992,9 @@ extension Home {
             .sheet(isPresented: $state.isLegendPresented) {
                 ChartLegendView(state: state)
             }
+            .sheet(isPresented: $showSnoozeSheet) {
+                SnoozeAllSheet(resolver: resolver, isPresented: $showSnoozeSheet)
+            }
             // PUMP RELATED
             .confirmationDialog("Pump Model", isPresented: $showPumpSelection) {
                 Button("Medtronic") { state.addPump(.minimed) }

+ 1 - 63
Trio/Sources/Modules/Settings/View/Subviews/NotificationsView.swift

@@ -16,7 +16,6 @@ struct NotificationsView: BaseView {
     @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(
@@ -113,7 +112,7 @@ struct NotificationsView: BaseView {
             )
         }
         .sheet(isPresented: $showSnoozeSheet) {
-            snoozeSheet
+            SnoozeAllSheet(resolver: resolver, isPresented: $showSnoozeSheet)
         }
         .scrollContentBackground(.hidden)
         .background(appState.trioBackgroundColor(for: colorScheme))
@@ -163,65 +162,4 @@ extension NotificationsView {
         }
     }
 
-    /// 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
-        }
-    }
 }

+ 73 - 0
Trio/Sources/Views/SnoozeAllSheet.swift

@@ -0,0 +1,73 @@
+import SwiftUI
+import Swinject
+
+/// Shared "Snooze All" sheet. Used from Notifications settings and the home
+/// glucose long-press. Wraps `TrioAlertManager.applySnooze` directly — no
+/// router / module hop.
+struct SnoozeAllSheet: View {
+    let resolver: Resolver
+    @Binding var isPresented: Bool
+
+    @State private var snoozeUntilDate: Date = .distantPast
+
+    @Environment(\.colorScheme) var colorScheme
+    @Environment(AppState.self) var appState
+
+    var body: 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") { isPresented = 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)
+            isPresented = false
+        }
+    }
+}