diff --git a/Nextcloud Cookbook iOS Client.xcodeproj/project.pbxproj b/Nextcloud Cookbook iOS Client.xcodeproj/project.pbxproj index 35f3cfb..c71e326 100644 --- a/Nextcloud Cookbook iOS Client.xcodeproj/project.pbxproj +++ b/Nextcloud Cookbook iOS Client.xcodeproj/project.pbxproj @@ -50,6 +50,7 @@ A9CA6CEF2B4C086100F78AB5 /* RecipeExporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA6CEE2B4C086100F78AB5 /* RecipeExporter.swift */; }; A9CA6CF62B4C63F200F78AB5 /* TPPDF in Frameworks */ = {isa = PBXBuildFile; productRef = A9CA6CF52B4C63F200F78AB5 /* TPPDF */; }; A9D89AB02B4FE97800F49D92 /* TimerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9D89AAF2B4FE97800F49D92 /* TimerView.swift */; }; + A9FA2AB62B5079B200A43702 /* alarm_sound_0.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = A9FA2AB52B5079B200A43702 /* alarm_sound_0.mp3 */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -115,6 +116,7 @@ A7FB0D7D2B25C6A200A3469E /* V2LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = V2LoginView.swift; sourceTree = ""; }; A9CA6CEE2B4C086100F78AB5 /* RecipeExporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeExporter.swift; sourceTree = ""; }; A9D89AAF2B4FE97800F49D92 /* TimerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerView.swift; sourceTree = ""; }; + A9FA2AB52B5079B200A43702 /* alarm_sound_0.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = alarm_sound_0.mp3; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -147,6 +149,7 @@ A70171752AA8E71900064C43 = { isa = PBXGroup; children = ( + A9FA2AB42B50798800A43702 /* Resources */, A781E75E2AE9133B00452F6F /* Screenshots */, A70171802AA8E71900064C43 /* Nextcloud Cookbook iOS Client */, A70171922AA8E72000064C43 /* Nextcloud Cookbook iOS ClientTests */, @@ -323,6 +326,14 @@ path = RecipeExport; sourceTree = ""; }; + A9FA2AB42B50798800A43702 /* Resources */ = { + isa = PBXGroup; + children = ( + A9FA2AB52B5079B200A43702 /* alarm_sound_0.mp3 */, + ); + path = Resources; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -438,6 +449,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + A9FA2AB62B5079B200A43702 /* alarm_sound_0.mp3 in Resources */, A701718A2AA8E71F00064C43 /* Preview Assets.xcassets in Resources */, A70171862AA8E71F00064C43 /* Assets.xcassets in Resources */, A7AEAE642AD5521400135378 /* Localizable.xcstrings in Resources */, diff --git a/Nextcloud Cookbook iOS Client.xcodeproj/project.xcworkspace/xcuserdata/vincie.xcuserdatad/UserInterfaceState.xcuserstate b/Nextcloud Cookbook iOS Client.xcodeproj/project.xcworkspace/xcuserdata/vincie.xcuserdatad/UserInterfaceState.xcuserstate index 2a3afbe..b542845 100644 Binary files a/Nextcloud Cookbook iOS Client.xcodeproj/project.xcworkspace/xcuserdata/vincie.xcuserdatad/UserInterfaceState.xcuserstate and b/Nextcloud Cookbook iOS Client.xcodeproj/project.xcworkspace/xcuserdata/vincie.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Nextcloud Cookbook iOS Client/Localizable.xcstrings b/Nextcloud Cookbook iOS Client/Localizable.xcstrings index 4454279..2b795e2 100644 --- a/Nextcloud Cookbook iOS Client/Localizable.xcstrings +++ b/Nextcloud Cookbook iOS Client/Localizable.xcstrings @@ -2853,6 +2853,9 @@ } } } + }, + "Timer alert!" : { + }, "Title" : { "localizations" : { @@ -3161,6 +3164,9 @@ } } } + }, + "Your timer is expired!" : { + } }, "version" : "1.0" diff --git a/Nextcloud Cookbook iOS Client/ViewModels/MainViewModel.swift b/Nextcloud Cookbook iOS Client/ViewModels/MainViewModel.swift index cb5be79..cf25dda 100644 --- a/Nextcloud Cookbook iOS Client/ViewModels/MainViewModel.swift +++ b/Nextcloud Cookbook iOS Client/ViewModels/MainViewModel.swift @@ -623,4 +623,8 @@ extension MainViewModel { func getTimer(forRecipe recipeId: String, duration: DurationComponents) -> RecipeTimer { return timers[recipeId] ?? createTimer(forRecipe: recipeId, duration: duration) } + + func deleteTimer(forRecipe recipeId: String) { + timers.removeValue(forKey: recipeId) + } } diff --git a/Nextcloud Cookbook iOS Client/Views/TimerView.swift b/Nextcloud Cookbook iOS Client/Views/TimerView.swift index 5a81a4a..aa89f2b 100644 --- a/Nextcloud Cookbook iOS Client/Views/TimerView.swift +++ b/Nextcloud Cookbook iOS Client/Views/TimerView.swift @@ -8,10 +8,13 @@ import Foundation import SwiftUI import Combine +import AVFoundation struct TimerView: View { @ObservedObject var timer: RecipeTimer + @State var audioPlayer: AVAudioPlayer? + @State var presentTimerAlert: Bool = false var body: some View { HStack { @@ -56,6 +59,31 @@ struct TimerView: View { RoundedRectangle(cornerRadius: 20) .foregroundStyle(.ultraThickMaterial) } + .alert("Timer alert!", isPresented: $timer.timerExpired) { + Button { + timer.timerExpired = false + audioPlayer?.stop() + } label: { + Text("Your timer is expired!") + } + .onAppear { + playSound() + } + } + } + + func playSound() { + if let path = Bundle.main.path(forResource: "alarm_sound_0", ofType: "mp3") { + do { + audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path)) + audioPlayer?.prepareToPlay() + } catch { + // Handle the error + print("Error loading sound file.") + return + } + } + audioPlayer?.play() } } @@ -68,6 +96,7 @@ class RecipeTimer: ObservableObject { private var pauseDate: Date? @Published var timeElapsed: Double = 0 @Published var isRunning: Bool = false + @Published var timerExpired: Bool = false private var timer: Timer.TimerPublisher? private var timerCancellable: Cancellable? @@ -95,6 +124,7 @@ class RecipeTimer: ObservableObject { self.timeElapsed = elapsed self.duration.fromSeconds(Int(self.timeTotal - self.timeElapsed)) } else { + self.timerExpired = true self.timeElapsed = self.timeTotal self.duration.fromSeconds(Int(self.timeTotal - self.timeElapsed)) self.pause() diff --git a/Resources/alarm_sound_0.mp3 b/Resources/alarm_sound_0.mp3 new file mode 100644 index 0000000..8662518 Binary files /dev/null and b/Resources/alarm_sound_0.mp3 differ