taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit 62ed87eb501dee37205576eb6272f653b9a5ba9e
parent 3f137520bac29edf7b7d7b930fe7d0ba8606c6da
Author: Marc Stibane <marc@taler.net>
Date:   Fri, 30 Jun 2023 17:27:43 +0200

playSound

Diffstat:
MTalerWallet1/Backend/WalletCore.swift | 8++++++++
MTalerWallet1/Helper/playSound.swift | 14+++++++++-----
MTalerWallet1/Views/HelperViews/Buttons.swift | 37+++++++++++++++++++++++--------------
MTalerWallet1/Views/Main/MainView.swift | 2+-
MTalerWallet1/Views/Payment/PaymentURIView.swift | 5+----
MTalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift | 1-
MTalerWallet1/Views/WithdrawBankIntegrated/WithdrawAcceptDone.swift | 1-
7 files changed, 42 insertions(+), 26 deletions(-)

diff --git a/TalerWallet1/Backend/WalletCore.swift b/TalerWallet1/Backend/WalletCore.swift @@ -186,6 +186,14 @@ extension WalletCore { do { let decoded = try JSONDecoder().decode(TransactionTransition.self, from: jsonData) if decoded.newTxState != decoded.oldTxState { + if decoded.newTxState.major == .done { + 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) + } + } + } postNotification(.TransactionStateTransition, userInfo: [TRANSACTIONTRANSITION: decoded]) } diff --git a/TalerWallet1/Helper/playSound.swift b/TalerWallet1/Helper/playSound.swift @@ -6,11 +6,15 @@ import Foundation import AVFoundation func playSound(_ number: Int) { - let sound = (number == 0) ? "payment_failure" : - (number == 1) ? "payment_success" : "PaymentReceived" - let fileURL = URL(fileURLWithPath: "/System/Library/Audio/UISounds/" - + sound + ".caf") var soundID: SystemSoundID = 0 - AudioServicesCreateSystemSoundID(fileURL as CFURL, &soundID) + 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) + } AudioServicesPlaySystemSound(soundID); } diff --git a/TalerWallet1/Views/HelperViews/Buttons.swift b/TalerWallet1/Views/HelperViews/Buttons.swift @@ -4,8 +4,6 @@ */ import SwiftUI import Foundation -import AVFoundation - @@ -191,22 +189,33 @@ struct TalerButtonStyle: ButtonStyle { struct Buttons_Previews: PreviewProvider { static var previews: some View { VStack { - HamburgerButton() {} - .padding() - QRButton() {} - .padding() - PlusButton() {} - .padding() + HamburgerButton() { + playSound(1000) + }.padding() + QRButton() { + playSound(1001) + }.padding() + PlusButton() { + playSound(1002) // == 7 + }.padding() + HamburgerButton() { + playSound(1003) + }.padding() + QRButton() { + playSound(1004) + }.padding() + PlusButton() { + playSound(1005) + }.padding() HStack { ReloadButton(disabled: false) { - AudioServicesPlaySystemSound(1000) - } - .padding() - ReloadButton(disabled: true) {} - .padding() + playSound(1006) + }.padding() + ReloadButton(disabled: true) { + }.padding() } Button(String(localized: "Accept"), action: { - AudioServicesPlaySystemSound(1015) + playSound(1008) }) .buttonStyle(TalerButtonStyle(type: .prominent)) .padding(.horizontal) diff --git 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(2) + GNU_Taler.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 @@ -22,10 +22,7 @@ struct PaymentURIView: View { do { let confirmPayResult = try await model.confirmPayM(detailsForUri.proposalId) symLog.log(confirmPayResult as Any) - if confirmPayResult.type == "done" { - GNU_Taler.playSound(1) - // TODO: Show Hints that Payment was successfull - } else { + if confirmPayResult.type != "done" { GNU_Taler.playSound(0) // TODO: show error } diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift @@ -46,7 +46,6 @@ struct P2pAcceptDone: View { _ = try await model.confirmPeerPullDebitM(transactionId) } finished = true - GNU_Taler.playSound( incoming ? 2 : 1) } catch { // TODO: error symLog.log(error.localizedDescription) GNU_Taler.playSound(0) diff --git a/TalerWallet1/Views/WithdrawBankIntegrated/WithdrawAcceptDone.swift b/TalerWallet1/Views/WithdrawBankIntegrated/WithdrawAcceptDone.swift @@ -49,7 +49,6 @@ struct WithdrawAcceptDone: View { let result = try await model.sendAcceptIntWithdrawalM(exchangeBaseUrl, withdrawURL: url.absoluteString) confirmTransferUrl = result!.confirmTransferUrl transactionId = result!.transactionId - GNU_Taler.playSound(2) } } catch { // TODO: error symLog.log(error.localizedDescription)