From 6a36dc787df6126ecc3dc3ca28237190d383bf95 Mon Sep 17 00:00:00 2001 From: codebymini Date: Fri, 14 Aug 2026 14:31:38 +0200 Subject: [PATCH 1/2] Refactor OverrideActivationModal to simplify duration handling and make duration settings available for all overrides --- .../Remote/LoopAPNS/OverridePresetsView.swift | 89 ++++++++----------- 1 file changed, 39 insertions(+), 50 deletions(-) diff --git a/LoopFollow/Remote/LoopAPNS/OverridePresetsView.swift b/LoopFollow/Remote/LoopAPNS/OverridePresetsView.swift index 4d29aa6f6..894483f05 100644 --- a/LoopFollow/Remote/LoopAPNS/OverridePresetsView.swift +++ b/LoopFollow/Remote/LoopAPNS/OverridePresetsView.swift @@ -215,10 +215,11 @@ struct OverrideActivationModal: View { // Initialize state based on preset duration if preset.duration == 0 { - // Indefinite override - allow user to choose + // Indefinite override defaults to indefinite. _enableIndefinitely = State(initialValue: true) + _durationHours = State(initialValue: 1.0) } else { - // Override with predefined duration - use preset duration + // Predefined-duration override defaults to the preset duration, but remains editable. _enableIndefinitely = State(initialValue: false) _durationHours = State(initialValue: preset.duration / 3600) } @@ -251,69 +252,57 @@ struct OverrideActivationModal: View { .foregroundColor(.secondary) } - // Only show duration for overrides with predefined duration - if preset.duration != 0 { - Text("Duration: \(preset.durationDescription)") - .font(.subheadline) - .foregroundColor(.secondary) - } + Text("Preset: \(preset.durationDescription)") + .font(.subheadline) + .foregroundColor(.secondary) } .padding(.top) Spacer() - // Duration Settings (only show for overrides without predefined duration) - if preset.duration == 0 { - VStack(spacing: 16) { - // Duration Input (only show when not indefinite) - if !enableIndefinitely { - VStack(spacing: 8) { - HStack { - Text("Duration") - .font(.headline) - Spacer() - Text(formatDuration(durationHours)) - .font(.headline) - .foregroundColor(.blue) - } - - Slider(value: $durationHours, in: 0.25 ... 24.0, step: 0.25) - .accentColor(.blue) - HStack { - Text("15m") - .font(.caption) - .foregroundColor(.secondary) - .frame(width: 80, alignment: .leading) - Spacer() - Text("24h") - .font(.caption) - .foregroundColor(.secondary) - .frame(width: 80, alignment: .trailing) - } + // Duration Settings (available for all overrides) + VStack(spacing: 16) { + // Duration Input (only show when not indefinite) + if !enableIndefinitely { + VStack(spacing: 8) { + HStack { + Text("Duration") + .font(.headline) + Spacer() + Text(formatDuration(durationHours)) + .font(.headline) + .foregroundColor(.blue) } - .padding(.horizontal) - } - // Indefinitely Toggle - HStack { - Toggle("Enable indefinitely", isOn: $enableIndefinitely) - Spacer() + Slider(value: $durationHours, in: 0.25 ... 24.0, step: 0.25) + .accentColor(.blue) + HStack { + Text("15m") + .font(.caption) + .foregroundColor(.secondary) + .frame(width: 80, alignment: .leading) + Spacer() + Text("24h") + .font(.caption) + .foregroundColor(.secondary) + .frame(width: 80, alignment: .trailing) + } } .padding(.horizontal) } + + // Indefinitely Toggle + HStack { + Toggle("Enable indefinitely", isOn: $enableIndefinitely) + Spacer() + } + .padding(.horizontal) } // Action Buttons VStack(spacing: 12) { Button(action: { - let duration: TimeInterval? - if preset.duration == 0 { - // For indefinite overrides, use user selection - duration = enableIndefinitely ? nil : (durationHours * 3600) - } else { - // For overrides with predefined duration, use preset duration - duration = preset.duration - } + let duration: TimeInterval? = enableIndefinitely ? nil : (durationHours * 3600) onActivate(duration) }) { Text("Activate Override") From 8d948bfeb49e9269ec2f5e0f808a4ae6510d8b21 Mon Sep 17 00:00:00 2001 From: codebymini Date: Fri, 14 Aug 2026 16:37:59 +0200 Subject: [PATCH 2/2] Fix duration handling in OverrideActivationModal to use zero for indefinite activation --- LoopFollow/Remote/LoopAPNS/LoopAPNSService.swift | 2 +- LoopFollow/Remote/LoopAPNS/OverridePresetsView.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LoopFollow/Remote/LoopAPNS/LoopAPNSService.swift b/LoopFollow/Remote/LoopAPNS/LoopAPNSService.swift index 2a13dd081..38dc4fb23 100644 --- a/LoopFollow/Remote/LoopAPNS/LoopAPNSService.swift +++ b/LoopFollow/Remote/LoopAPNS/LoopAPNSService.swift @@ -682,7 +682,7 @@ class LoopAPNSService { "alert": alertText, ] - if let duration = duration, duration > 0 { + if let duration = duration { payload["override-duration-minutes"] = Int(duration / 60) } diff --git a/LoopFollow/Remote/LoopAPNS/OverridePresetsView.swift b/LoopFollow/Remote/LoopAPNS/OverridePresetsView.swift index 894483f05..6ed39e5bc 100644 --- a/LoopFollow/Remote/LoopAPNS/OverridePresetsView.swift +++ b/LoopFollow/Remote/LoopAPNS/OverridePresetsView.swift @@ -302,7 +302,7 @@ struct OverrideActivationModal: View { // Action Buttons VStack(spacing: 12) { Button(action: { - let duration: TimeInterval? = enableIndefinitely ? nil : (durationHours * 3600) + let duration: TimeInterval? = enableIndefinitely ? 0 : (durationHours * 3600) onActivate(duration) }) { Text("Activate Override")