gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-ios] 01/28: Haptics


From: gnunet
Subject: [taler-taler-ios] 01/28: Haptics
Date: Tue, 19 Sep 2023 03:44:20 +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 551285dced3b70bb173b1d8e3a31f162eb7da30e
Author: Marc Stibane <marc@taler.net>
AuthorDate: Tue Sep 5 18:37:13 2023 +0200

    Haptics
---
 TalerWallet1/Controllers/Controller.swift      | 3 +++
 TalerWallet1/Helper/Controller+playSound.swift | 5 +++++
 TalerWallet1/Views/Settings/SettingsView.swift | 8 +++++++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/TalerWallet1/Controllers/Controller.swift 
b/TalerWallet1/Controllers/Controller.swift
index 0dbd42c..35c2c6a 100644
--- a/TalerWallet1/Controllers/Controller.swift
+++ b/TalerWallet1/Controllers/Controller.swift
@@ -7,6 +7,7 @@ import AVFoundation
 import SwiftUI
 import SymLog
 import os.log
+import CoreHaptics
 
 enum BackendState {
     case none
@@ -32,8 +33,10 @@ class Controller: ObservableObject {
     private let symLog = SymLogC()
 
     @Published var backendState: BackendState = .none       // only used for 
launch animation
+    @AppStorage("useHaptics") var useHaptics: 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
     @AppStorage("talerFont") var talerFont: Int = 0         // extension 
mustn't define this, so it must be here
+    let hapticCapability = CHHapticEngine.capabilitiesForHardware()
     let logger = Logger (subsystem: "net.taler.gnu", category: "Controller")
     let player = AVQueuePlayer()
 
diff --git a/TalerWallet1/Helper/Controller+playSound.swift 
b/TalerWallet1/Helper/Controller+playSound.swift
index 31aca38..8374dd1 100644
--- a/TalerWallet1/Helper/Controller+playSound.swift
+++ b/TalerWallet1/Helper/Controller+playSound.swift
@@ -4,12 +4,14 @@
  */
 import Foundation
 import AVFoundation
+import UIKit
 
 extension Controller {
 
     /// 0 = failure, 1 = received, 2 = sent
     func playSound(_ number: Int) {
         var soundID: SystemSoundID = 0
+        let notificationGenerator = useHaptics ? 
UINotificationFeedbackGenerator() : nil
         if number > 9 {
             soundID = UInt32(number)
         } else {
@@ -34,5 +36,8 @@ extension Controller {
                 AudioServicesPlaySystemSound(soundID);
             }
         }
+        if let notificationGenerator {
+            notificationGenerator.notificationOccurred(number == 0 ? .error : 
.success)
+        }
     }
 }
diff --git a/TalerWallet1/Views/Settings/SettingsView.swift 
b/TalerWallet1/Views/Settings/SettingsView.swift
index 6394d07..7dbbbee 100644
--- a/TalerWallet1/Views/Settings/SettingsView.swift
+++ b/TalerWallet1/Views/Settings/SettingsView.swift
@@ -21,11 +21,13 @@ struct SettingsView: View {
     private let symLog = SymLogV(0)
     let navTitle: String
 
+    @EnvironmentObject private var controller: Controller
 #if DEBUG
     @AppStorage("developerMode") var developerMode: Bool = true
 #else
     @AppStorage("developerMode") var developerMode: Bool = false
 #endif
+    @AppStorage("useHaptics") var useHaptics: Bool = false
     @AppStorage("playSounds") var playSounds: Int = 0
     @AppStorage("talerFont") var talerFont: Int = 0
     @AppStorage("developDelay") var developDelay: Bool = false
@@ -81,8 +83,12 @@ struct SettingsView: View {
         let walletCore = WalletCore.shared
         Group {
             List {
+                if controller.hapticCapability.supportsHaptics {
+                    SettingsToggle(name: String(localized: "Haptics"), value: 
$useHaptics,
+                                   description: String(localized: "Vibration 
Feedback"))
+                }
                 SettingsSpeaker(name: String(localized: "Play Payment 
Sounds"), value: $playSounds,
-                                description: String(localized: "After a 
transaction finished"))
+                                description: String(localized: "When a 
transaction finished"))
                 SettingsFont(title: String(localized: "Font:"), value: 
talerFont, action: redraw)
                 SettingsStyle(title: String(localized: "Liststyle:"), 
myListStyle: $myListStyle)
                 if diagnosticModeEnabled {

-- 
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]