gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-ios] 52/54: playSound


From: gnunet
Subject: [taler-taler-ios] 52/54: playSound
Date: Fri, 30 Jun 2023 22:34:24 +0200

This is an automated email from the git hooks/post-receive script.

marc-stibane pushed a commit to branch master
in repository taler-ios.

commit 974db16a4d1e153415d77bb6d97817ee799abb4d
Author: Marc Stibane <marc@taler.net>
AuthorDate: Fri Jun 30 20:06:11 2023 +0200

    playSound
---
 TalerWallet1/Backend/WalletCore.swift              |  2 +-
 TalerWallet1/Controllers/Controller.swift          |  1 +
 TalerWallet1/Helper/playSound.swift                | 27 +++++++++++++---------
 TalerWallet1/Views/HelperViews/Buttons.swift       | 16 ++++++-------
 TalerWallet1/Views/Main/MainView.swift             |  2 +-
 TalerWallet1/Views/Payment/PaymentURIView.swift    |  6 +++--
 TalerWallet1/Views/Settings/SettingsView.swift     |  3 +++
 .../Views/Sheets/P2P_Sheets/P2pAcceptDone.swift    |  3 ++-
 .../WithdrawAcceptDone.swift                       |  3 ++-
 9 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/TalerWallet1/Backend/WalletCore.swift 
b/TalerWallet1/Backend/WalletCore.swift
index 2bbe07d..6e0b045 100644
--- a/TalerWallet1/Backend/WalletCore.swift
+++ b/TalerWallet1/Backend/WalletCore.swift
@@ -190,7 +190,7 @@ extension WalletCore {
                     let components = 
decoded.transactionId.components(separatedBy: [":"])
                     if components.count >= 3 {  // txn:$txtype:$uid
                         if let type = TransactionType(rawValue: components[1]) 
{
-                            playSound(type.isIncoming ? 2 : 1)
+                            Controller.shared.playSound(type.isIncoming ? 2 : 
1)
                         }
                     }
                 }
diff --git a/TalerWallet1/Controllers/Controller.swift 
b/TalerWallet1/Controllers/Controller.swift
index 8752996..c95c5a9 100644
--- a/TalerWallet1/Controllers/Controller.swift
+++ b/TalerWallet1/Controllers/Controller.swift
@@ -28,6 +28,7 @@ class Controller: ObservableObject {
     private let symLog = SymLogC()
 
     @Published var backendState: BackendState = .none       // only used for 
launch animation
+    @AppStorage("playSounds") var playSounds: Bool = false
 
     var messageForSheet: String? = nil
 
diff --git a/TalerWallet1/Helper/playSound.swift 
b/TalerWallet1/Helper/playSound.swift
index ede020f..ed39bef 100644
--- a/TalerWallet1/Helper/playSound.swift
+++ b/TalerWallet1/Helper/playSound.swift
@@ -5,16 +5,21 @@
 import Foundation
 import AVFoundation
 
-func playSound(_ number: Int) {
-    var soundID: SystemSoundID = 0
-    if number < 999 {
-        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)
-    } else {
-        soundID = UInt32(number)
+extension Controller {
+
+    func playSound(_ number: Int) {
+        var soundID: SystemSoundID = 0
+        if number < 999 {
+            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)
+        } else {
+            soundID = UInt32(number)
+        }
+        if playSounds {
+            AudioServicesPlaySystemSound(soundID);
+        }
     }
-    AudioServicesPlaySystemSound(soundID);
 }
diff --git a/TalerWallet1/Views/HelperViews/Buttons.swift 
b/TalerWallet1/Views/HelperViews/Buttons.swift
index c3d0fe8..294e57b 100644
--- a/TalerWallet1/Views/HelperViews/Buttons.swift
+++ b/TalerWallet1/Views/HelperViews/Buttons.swift
@@ -191,32 +191,32 @@ struct Buttons_Previews: PreviewProvider {
     static var previews: some View {
         VStack {
             HamburgerButton() {
-                playSound(1000)
+                Controller.shared.playSound(1000)
             }.padding()
             QRButton() {
-                playSound(1001)
+                Controller.shared.playSound(1001)
             }.padding()
             PlusButton() {
-                playSound(1002) // == 7
+                Controller.shared.playSound(1002) // == 7
             }.padding()
             HamburgerButton() {
-                playSound(1003)
+                Controller.shared.playSound(1003)
             }.padding()
             QRButton() {
-                playSound(1004)
+                Controller.shared.playSound(1004)
             }.padding()
             PlusButton() {
-                playSound(1005)
+                Controller.shared.playSound(1005)
             }.padding()
             HStack {
                 ReloadButton(disabled: false) {
-                    playSound(1006)
+                    Controller.shared.playSound(1006)
                 }.padding()
                 ReloadButton(disabled: true) {
                 }.padding()
             }
             Button(String(localized: "Accept"), action: {
-                playSound(1008)
+                Controller.shared.playSound(1008)
             })
                 .buttonStyle(TalerButtonStyle(type: .prominent))
                 .padding(.horizontal)
diff --git a/TalerWallet1/Views/Main/MainView.swift 
b/TalerWallet1/Views/Main/MainView.swift
index eba9801..810e052 100644
--- a/TalerWallet1/Views/Main/MainView.swift
+++ b/TalerWallet1/Views/Main/MainView.swift
@@ -35,7 +35,7 @@ struct MainView: View {
                 // any change to rootViewId triggers popToRootView behaviour
                     .id(viewState.rootViewId)
                     .onAppear() {
-                        GNU_Taler.playSound(1008)     // TODO: Startup chime
+                        controller.playSound(1008)     // TODO: Startup chime
                         soundPlayed = true
                     }
             } else if controller.backendState == .error {
diff --git a/TalerWallet1/Views/Payment/PaymentURIView.swift 
b/TalerWallet1/Views/Payment/PaymentURIView.swift
index 6570737..1bb19c2 100644
--- a/TalerWallet1/Views/Payment/PaymentURIView.swift
+++ b/TalerWallet1/Views/Payment/PaymentURIView.swift
@@ -12,6 +12,8 @@ struct PaymentURIView: View {
     private let symLog = SymLogV()
     let navTitle = String(localized: "Confirm Payment", comment:"pay merchant")
 
+    @EnvironmentObject private var controller: Controller
+
     // the scanned URL
     let url: URL
 
@@ -23,11 +25,11 @@ struct PaymentURIView: View {
                 let confirmPayResult = try await 
model.confirmPayM(detailsForUri.proposalId)
                 symLog.log(confirmPayResult as Any)
                 if confirmPayResult.type != "done" {
-                    GNU_Taler.playSound(0)
+                    controller.playSound(0)
                     // TODO: show error
                 }
             } catch {
-                GNU_Taler.playSound(0)
+                controller.playSound(0)
                 // TODO: error
                 symLog.log(error.localizedDescription)
             }
diff --git a/TalerWallet1/Views/Settings/SettingsView.swift 
b/TalerWallet1/Views/Settings/SettingsView.swift
index e569daf..51cedff 100644
--- a/TalerWallet1/Views/Settings/SettingsView.swift
+++ b/TalerWallet1/Views/Settings/SettingsView.swift
@@ -26,6 +26,7 @@ struct SettingsView: View {
 #else
     @AppStorage("developerMode") var developerMode: Bool = false
 #endif
+    @AppStorage("playSounds") var playSounds: Bool = false
     @AppStorage("developDelay") var developDelay: Bool = false
     @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
 
@@ -50,6 +51,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"))
                 HStack {
                     Text("Liststyle:")
                         .font(.title2)
diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift 
b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift
index 1ceca54..6eb706d 100644
--- a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift
+++ b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift
@@ -13,6 +13,7 @@ struct P2pAcceptDone: View {
     let incoming: Bool
 
     @EnvironmentObject private var model: WalletModel
+    @EnvironmentObject private var controller: Controller
 
     @State private var finished: Bool = false
 
@@ -48,7 +49,7 @@ struct P2pAcceptDone: View {
                 finished = true
             } catch {    // TODO: error
                 symLog.log(error.localizedDescription)
-                GNU_Taler.playSound(0)
+                controller.playSound(0)
             }
         }
       }
diff --git a/TalerWallet1/Views/WithdrawBankIntegrated/WithdrawAcceptDone.swift 
b/TalerWallet1/Views/WithdrawBankIntegrated/WithdrawAcceptDone.swift
index 039e28b..1a802f1 100644
--- a/TalerWallet1/Views/WithdrawBankIntegrated/WithdrawAcceptDone.swift
+++ b/TalerWallet1/Views/WithdrawBankIntegrated/WithdrawAcceptDone.swift
@@ -14,6 +14,7 @@ struct WithdrawAcceptDone: View {
     let url: URL
 
     @EnvironmentObject private var model: WalletModel
+    @EnvironmentObject private var controller: Controller
 
     @State private var transactionId: String? = nil
 
@@ -52,7 +53,7 @@ struct WithdrawAcceptDone: View {
                 }
             } catch {    // TODO: error
                 symLog.log(error.localizedDescription)
-                GNU_Taler.playSound(0)
+                controller.playSound(0)
             }
         }
       }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]