mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			109 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			109 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Swift
		
	
| 
								 
											7 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								//  Copyright (c) 2019 Open Whisper Systems. All rights reserved.
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import Foundation
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								protocol SelectionHapticFeedbackAdapter {
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    func selectionChanged()
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								class SelectionHapticFeedback: SelectionHapticFeedbackAdapter {
							 | 
						||
| 
								 | 
							
								    let adapter: SelectionHapticFeedbackAdapter
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    init() {
							 | 
						||
| 
								 | 
							
								        if #available(iOS 10, *) {
							 | 
						||
| 
								 | 
							
								            adapter = ModernSelectionHapticFeedbackAdapter()
							 | 
						||
| 
								 | 
							
								        } else {
							 | 
						||
| 
								 | 
							
								            adapter = LegacySelectionHapticFeedbackAdapter()
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    func selectionChanged() {
							 | 
						||
| 
								 | 
							
								        adapter.selectionChanged()
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class LegacySelectionHapticFeedbackAdapter: NSObject, SelectionHapticFeedbackAdapter {
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    func selectionChanged() {
							 | 
						||
| 
								 | 
							
								        // do nothing
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								@available(iOS 10, *)
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								class ModernSelectionHapticFeedbackAdapter: NSObject, SelectionHapticFeedbackAdapter {
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    let selectionFeedbackGenerator: UISelectionFeedbackGenerator
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    override init() {
							 | 
						||
| 
								 | 
							
								        selectionFeedbackGenerator = UISelectionFeedbackGenerator()
							 | 
						||
| 
								 | 
							
								        selectionFeedbackGenerator.prepare()
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    // MARK: HapticAdapter
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    func selectionChanged() {
							 | 
						||
| 
								 | 
							
								        selectionFeedbackGenerator.selectionChanged()
							 | 
						||
| 
								 | 
							
								        selectionFeedbackGenerator.prepare()
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								enum NotificationHapticFeedbackType {
							 | 
						||
| 
								 | 
							
								    case error, success, warning
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								@available(iOS 10.0, *)
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								extension NotificationHapticFeedbackType {
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								    var uiNotificationFeedbackType: UINotificationFeedbackGenerator.FeedbackType {
							 | 
						||
| 
								 
											7 years ago
										 
									 | 
							
								        switch self {
							 | 
						||
| 
								 | 
							
								        case .error: return .error
							 | 
						||
| 
								 | 
							
								        case .success: return .success
							 | 
						||
| 
								 | 
							
								        case .warning: return .warning
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								protocol NotificationHapticFeedbackAdapter {
							 | 
						||
| 
								 | 
							
								    func notificationOccurred(_ notificationType: NotificationHapticFeedbackType)
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class NotificationHapticFeedback: NotificationHapticFeedbackAdapter {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    let adapter: NotificationHapticFeedbackAdapter
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    init() {
							 | 
						||
| 
								 | 
							
								        if #available(iOS 10, *) {
							 | 
						||
| 
								 | 
							
								            adapter = ModernNotificationHapticFeedbackAdapter()
							 | 
						||
| 
								 | 
							
								        } else {
							 | 
						||
| 
								 | 
							
								            adapter = LegacyNotificationHapticFeedbackAdapter()
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    func notificationOccurred(_ notificationType: NotificationHapticFeedbackType) {
							 | 
						||
| 
								 | 
							
								        adapter.notificationOccurred(notificationType)
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								@available(iOS 10.0, *)
							 | 
						||
| 
								 | 
							
								class ModernNotificationHapticFeedbackAdapter: NotificationHapticFeedbackAdapter {
							 | 
						||
| 
								 | 
							
								    let feedbackGenerator = UINotificationFeedbackGenerator()
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    init() {
							 | 
						||
| 
								 | 
							
								        feedbackGenerator.prepare()
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    func notificationOccurred(_ notificationType: NotificationHapticFeedbackType) {
							 | 
						||
| 
								 | 
							
								        feedbackGenerator.notificationOccurred(notificationType.uiNotificationFeedbackType)
							 | 
						||
| 
								 | 
							
								        feedbackGenerator.prepare()
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class LegacyNotificationHapticFeedbackAdapter: NotificationHapticFeedbackAdapter {
							 | 
						||
| 
								 | 
							
								    func notificationOccurred(_ notificationType: NotificationHapticFeedbackType) {
							 | 
						||
| 
								 | 
							
								        vibrate()
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    private func vibrate() {
							 | 
						||
| 
								 | 
							
								        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |