diff options
author | Marc Stibane <marc@taler.net> | 2023-08-08 12:12:06 +0200 |
---|---|---|
committer | Marc Stibane <marc@taler.net> | 2023-08-08 12:12:06 +0200 |
commit | d25e933457d24e1b2ddc43b0288bd79644e3454b (patch) | |
tree | 25ddad7daa04a24bb6c02e82e88cb3a45e1907bc | |
parent | 9ba37a156cacc4bf14e68e1dbb31f16cd171127e (diff) | |
download | taler-ios-d25e933457d24e1b2ddc43b0288bd79644e3454b.tar.gz taler-ios-d25e933457d24e1b2ddc43b0288bd79644e3454b.tar.bz2 taler-ios-d25e933457d24e1b2ddc43b0288bd79644e3454b.zip |
Payment Sounds by carlo von lynX
-rw-r--r-- | TalerWallet.xcodeproj/project.pbxproj | 16 | ||||
-rw-r--r-- | TalerWallet1/Controllers/Controller.swift | 5 | ||||
-rw-r--r-- | TalerWallet1/Helper/playSound.swift | 19 | ||||
-rw-r--r-- | TalerWallet1/Sounds/payment_received.m4a | bin | 0 -> 68854 bytes | |||
-rw-r--r-- | TalerWallet1/Sounds/payment_sent.m4a | bin | 0 -> 69508 bytes | |||
-rw-r--r-- | TalerWallet1/Views/Settings/SettingsItem.swift | 47 | ||||
-rw-r--r-- | TalerWallet1/Views/Settings/SettingsView.swift | 6 |
7 files changed, 84 insertions, 9 deletions
diff --git a/TalerWallet.xcodeproj/project.pbxproj b/TalerWallet.xcodeproj/project.pbxproj index eae83d9..029de82 100644 --- a/TalerWallet.xcodeproj/project.pbxproj +++ b/TalerWallet.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 4E16E12329F3BB99008B9C86 /* CurrencyFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E16E12229F3BB99008B9C86 /* CurrencyFormatter.swift */; }; + 4E2254972A822B8100E41D29 /* payment_received.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 4E2254952A822B8100E41D29 /* payment_received.m4a */; }; + 4E2254982A822B8100E41D29 /* payment_sent.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 4E2254962A822B8100E41D29 /* payment_sent.m4a */; }; 4E363CBC2A237E0900D7E98C /* URL+id+iban.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E363CBB2A237E0900D7E98C /* URL+id+iban.swift */; }; 4E363CBE2A23CB2100D7E98C /* AnyTransition+backslide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E363CBD2A23CB2100D7E98C /* AnyTransition+backslide.swift */; }; 4E363CC02A24754200D7E98C /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 4E363CBF2A24754200D7E98C /* Settings.bundle */; }; @@ -143,6 +145,8 @@ /* Begin PBXFileReference section */ 4E16E12229F3BB99008B9C86 /* CurrencyFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CurrencyFormatter.swift; sourceTree = "<group>"; }; + 4E2254952A822B8100E41D29 /* payment_received.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = payment_received.m4a; sourceTree = "<group>"; }; + 4E2254962A822B8100E41D29 /* payment_sent.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = payment_sent.m4a; sourceTree = "<group>"; }; 4E363CBB2A237E0900D7E98C /* URL+id+iban.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "URL+id+iban.swift"; sourceTree = "<group>"; }; 4E363CBD2A23CB2100D7E98C /* AnyTransition+backslide.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AnyTransition+backslide.swift"; sourceTree = "<group>"; }; 4E363CBF2A24754200D7E98C /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; }; @@ -282,6 +286,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 4E2254942A822B8100E41D29 /* Sounds */ = { + isa = PBXGroup; + children = ( + 4E2254952A822B8100E41D29 /* payment_received.m4a */, + 4E2254962A822B8100E41D29 /* payment_sent.m4a */, + ); + path = Sounds; + sourceTree = "<group>"; + }; 4E3B4BBF2A41E64000CC88B8 /* P2P_Sheets */ = { isa = PBXGroup; children = ( @@ -321,6 +334,7 @@ 4EB095052989CB7C0043A8A1 /* Helper */, 4EB0950C2989CB9A0043A8A1 /* Quickjs */, 4EB094EF298979D30043A8A1 /* Assets.xcassets */, + 4E2254942A822B8100E41D29 /* Sounds */, 4E8C171B2A6509BB005B2392 /* Atkinson-Hyperlegible */, 4E363CBF2A24754200D7E98C /* Settings.bundle */, 4EB094F529897A9A0043A8A1 /* Preview Content */, @@ -727,8 +741,10 @@ 4E8C17202A6509BB005B2392 /* Atkinson-Hyperlegible-Regular-102.otf in Resources */, 4E8C17222A6509BB005B2392 /* Atkinson-Hyperlegible-Bold-102.otf in Resources */, 4E8C17232A6509BB005B2392 /* Atkinson-Hyperlegible-BoldItalic-102.otf in Resources */, + 4E2254972A822B8100E41D29 /* payment_received.m4a in Resources */, 4E8C17212A6509BB005B2392 /* Atkinson-Hyperlegible-Italic-102.otf in Resources */, 4EB094F0298979D30043A8A1 /* Assets.xcassets in Resources */, + 4E2254982A822B8100E41D29 /* payment_sent.m4a in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/TalerWallet1/Controllers/Controller.swift b/TalerWallet1/Controllers/Controller.swift index 17201f5..d2d3c30 100644 --- a/TalerWallet1/Controllers/Controller.swift +++ b/TalerWallet1/Controllers/Controller.swift @@ -3,6 +3,7 @@ * See LICENSE.md */ import Foundation +import AVFoundation import SwiftUI import SymLog import os.log @@ -22,6 +23,7 @@ enum UrlCommand { case payPull case payPush case payTemplate + case reward } // MARK: - @@ -30,8 +32,9 @@ class Controller: ObservableObject { private let symLog = SymLogC() @Published var backendState: BackendState = .none // only used for launch animation - @AppStorage("playSounds") var playSounds: Bool = false // extension mustn't define this, so it must be here + @AppStorage("playSounds") var playSounds: Int = 0 // extension mustn't define this, so it must be here let logger = Logger (subsystem: "net.taler.gnu", category: "Controller") + let player = AVQueuePlayer() var messageForSheet: String? = nil diff --git a/TalerWallet1/Helper/playSound.swift b/TalerWallet1/Helper/playSound.swift index 0b4c428..14f4077 100644 --- a/TalerWallet1/Helper/playSound.swift +++ b/TalerWallet1/Helper/playSound.swift @@ -9,18 +9,29 @@ extension Controller { func playSound(_ number: Int) { var soundID: SystemSoundID = 0 - if number < 999 { + if number > 9 { + soundID = UInt32(number) + } else { let sound = (number == 0) ? "payment_failure" : (number == 1) ? "payment_success" : "PaymentReceived" let fileURL = URL(fileURLWithPath: "/System/Library/Audio/UISounds/" + sound + ".caf") AudioServicesCreateSystemSoundID(fileURL as CFURL, &soundID) logger.log("\(sound, privacy: .public) \(soundID)") - } else { - soundID = UInt32(number) } - if playSounds { + if number == 0 || number > 9 || playSounds < 0 { AudioServicesPlaySystemSound(soundID); + } else if playSounds > 0 { + if let url = Bundle.main.url(forResource: (number == 1) ? "payment_received" + : "payment_sent", + withExtension: "m4a") { + player.removeAllItems() + player.insert(AVPlayerItem(url: url), after: nil) + logger.log("\(url, privacy: .public) \(soundID)") + player.play() + } else { + AudioServicesPlaySystemSound(soundID); + } } } } diff --git a/TalerWallet1/Sounds/payment_received.m4a b/TalerWallet1/Sounds/payment_received.m4a Binary files differnew file mode 100644 index 0000000..c15ff63 --- /dev/null +++ b/TalerWallet1/Sounds/payment_received.m4a diff --git a/TalerWallet1/Sounds/payment_sent.m4a b/TalerWallet1/Sounds/payment_sent.m4a Binary files differnew file mode 100644 index 0000000..b16372a --- /dev/null +++ b/TalerWallet1/Sounds/payment_sent.m4a diff --git a/TalerWallet1/Views/Settings/SettingsItem.swift b/TalerWallet1/Views/Settings/SettingsItem.swift index b8443fe..df26904 100644 --- a/TalerWallet1/Views/Settings/SettingsItem.swift +++ b/TalerWallet1/Views/Settings/SettingsItem.swift @@ -56,13 +56,58 @@ struct SettingsToggle: View { } } // MARK: - +struct SettingsSpeaker: View { + var name: String + @Binding var value: Int + var description: String? + var action: (_ value: Int) -> Void = {value in } + + var body: some View { + VStack { + let image = (value == 0) ? "speaker.slash" + : (value == 1) ? "speaker.fill" + : "speaker" + HStack { + Text(name) + .font(.title2) + Text(" ") + .font(.largeTitle) + Spacer() + Image(systemName: image) + .font(.largeTitle) + .onTapGesture { + if value > 0 { + value = -1 + } else { + value = value + 1 + } + } + } +// .onChange(of: value) { value in +// action(value) +// } + + if let desc = description { + Text(desc) + .frame(maxWidth: .infinity, alignment: .leading) + .font(.caption) + } + }.padding([.bottom], 4) + } +} +// MARK: - #if DEBUG struct SettingsItemPreview : View { @State var developerMode: Bool = false + @State var playSounds: Int = 0 var body: some View { VStack { - SettingsToggle(name: "Developer Mode", value: $developerMode, description: "More information intended for debugging") + SettingsToggle(name: "Developer Mode", value: $developerMode, + description: "More information intended for debugging") + SettingsSpeaker(name: String(localized: "Play Payment Sounds"), value: $playSounds, + description: String(localized: "After a transaction finished")) + } } } diff --git a/TalerWallet1/Views/Settings/SettingsView.swift b/TalerWallet1/Views/Settings/SettingsView.swift index ee7d4e6..e9c458b 100644 --- a/TalerWallet1/Views/Settings/SettingsView.swift +++ b/TalerWallet1/Views/Settings/SettingsView.swift @@ -26,7 +26,7 @@ struct SettingsView: View { #else @AppStorage("developerMode") var developerMode: Bool = false #endif - @AppStorage("playSounds") var playSounds: Bool = false + @AppStorage("playSounds") var playSounds: Int = 0 @AppStorage("developDelay") var developDelay: Bool = false @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic @@ -73,8 +73,8 @@ struct SettingsView: View { let walletCore = WalletCore.shared Group { List { - SettingsToggle(name: String(localized: "Play Payment Sounds"), value: $playSounds, - description: String(localized: "After a transaction finished")) + SettingsSpeaker(name: String(localized: "Play Payment Sounds"), value: $playSounds, + description: String(localized: "After a transaction finished")) HStack { Text("Liststyle:") .font(.title2) |