From 218fa29d8d8e365fc6ec47cc856e25cbda91f1b3 Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 16 Feb 2023 12:29:28 +0100 Subject: [PATCH] silent mode alert --- LeCountdown.xcodeproj/project.pbxproj | 4 ++++ LeCountdown/Utils/Preferences.swift | 24 ++++++++++++++++++++++++ LeCountdown/Views/DialView.swift | 16 +++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 LeCountdown/Utils/Preferences.swift diff --git a/LeCountdown.xcodeproj/project.pbxproj b/LeCountdown.xcodeproj/project.pbxproj index 40a7f2b..030aae5 100644 --- a/LeCountdown.xcodeproj/project.pbxproj +++ b/LeCountdown.xcodeproj/project.pbxproj @@ -108,6 +108,7 @@ C4BA2B22299BE82E00CB4FBA /* AbstractSoundTimer+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2AEF2996A11900CB4FBA /* AbstractSoundTimer+CoreDataProperties.swift */; }; C4BA2B23299BE82E00CB4FBA /* AbstractSoundTimer+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2AEF2996A11900CB4FBA /* AbstractSoundTimer+CoreDataProperties.swift */; }; C4BA2B25299D35C100CB4FBA /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2B24299D35C100CB4FBA /* HomeView.swift */; }; + C4BA2B2D299E2DEE00CB4FBA /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2B2C299E2DEE00CB4FBA /* Preferences.swift */; }; C4F8B1532987FE6F005C86A5 /* LaunchWidgetLiveActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C7D72981216200BF3EF9 /* LaunchWidgetLiveActivity.swift */; }; C4F8B15729891271005C86A5 /* Conductor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B15629891271005C86A5 /* Conductor.swift */; }; C4F8B15929891528005C86A5 /* forest_stream.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = C4F8B15829891528005C86A5 /* forest_stream.mp3 */; }; @@ -289,6 +290,7 @@ C4BA2B0D299BE61E00CB4FBA /* IntervalGroup+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "IntervalGroup+CoreDataProperties.swift"; sourceTree = ""; }; C4BA2B0E299BE61E00CB4FBA /* Countdown+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Countdown+CoreDataProperties.swift"; sourceTree = ""; }; C4BA2B24299D35C100CB4FBA /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = ""; }; + C4BA2B2C299E2DEE00CB4FBA /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = ""; }; C4F8B15629891271005C86A5 /* Conductor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Conductor.swift; sourceTree = ""; }; C4F8B15829891528005C86A5 /* forest_stream.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = forest_stream.mp3; sourceTree = ""; }; C4F8B15E298961A7005C86A5 /* ReorderableForEach.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReorderableForEach.swift; sourceTree = ""; }; @@ -493,6 +495,7 @@ children = ( C4BA2AFC299A3A3700CB4FBA /* AppleMusicPlayer.swift */, C4742B5629840F6400D5D950 /* CoolPic.swift */, + C4BA2B2C299E2DEE00CB4FBA /* Preferences.swift */, C438C81029829EAF00BF3EF9 /* PropertyWrappers.swift */, C40FDB612992985C0042A390 /* TextToSpeechRecorder.swift */, C4060DF4297AE9A7003FAB80 /* TimeInterval+Extensions.swift */, @@ -860,6 +863,7 @@ C445FA8F2987B83B0054D761 /* SoundPlayer.swift in Sources */, C4F8B1A7298AC2FC005C86A5 /* AbstractSoundTimer+CoreDataClass.swift in Sources */, C438C7C929803CA000BF3EF9 /* AppDelegate.swift in Sources */, + C4BA2B2D299E2DEE00CB4FBA /* Preferences.swift in Sources */, C4F8B185298AC234005C86A5 /* AbstractTimer+CoreDataProperties.swift in Sources */, C4F8B169298AA236005C86A5 /* StopwatchFormView.swift in Sources */, C4F8B1BD298AC8DE005C86A5 /* AlarmDialView.swift in Sources */, diff --git a/LeCountdown/Utils/Preferences.swift b/LeCountdown/Utils/Preferences.swift new file mode 100644 index 0000000..a71da9b --- /dev/null +++ b/LeCountdown/Utils/Preferences.swift @@ -0,0 +1,24 @@ +// +// Preferences.swift +// LeCountdown +// +// Created by Laurent Morvillier on 16/02/2023. +// + +import Foundation + +enum PreferenceKey: String { + case showSilentModeAlert +} + +class Preferences { + + static var hideSilentModeAlerts: Bool { + return UserDefaults.standard.bool(forKey: PreferenceKey.showSilentModeAlert.rawValue) + } + + static func hideSilentModeAlerts(_ hide: Bool) { + UserDefaults.standard.setValue(true, forKey: PreferenceKey.showSilentModeAlert.rawValue) + } + +} diff --git a/LeCountdown/Views/DialView.swift b/LeCountdown/Views/DialView.swift index 115c1a4..8a0d10e 100644 --- a/LeCountdown/Views/DialView.swift +++ b/LeCountdown/Views/DialView.swift @@ -17,6 +17,8 @@ struct DialView: View { @State var timer: AbstractTimer var isEditingBinding: Binding + @State var showSilentModeAlert: Bool = false + var frameSize: CGFloat var body: some View { @@ -27,7 +29,11 @@ struct DialView: View { switch self.isEditingBinding.wrappedValue { case false: Button { - self._launchTimer() + if Preferences.hideSilentModeAlerts { + self._launchTimer() + } else { + self.showSilentModeAlert = true + } } label: { VStack { Spacer() @@ -58,6 +64,14 @@ struct DialView: View { } .frame(width: frameSize, height: 80.0) .cornerRadius(20.0) + .alert("Make sure your device is not on silent mode", isPresented: $showSilentModeAlert) { + Button("OK", role: .cancel) { self._launchTimer() + } + Button("Don't show this again", role: .destructive) { + self._launchTimer() + Preferences.hideSilentModeAlerts(true) + } + } } @ViewBuilder