Skip to content

Commit 2064c03

Browse files
committed
Haptic feedback via UIImpactFeedbackGenerator
Avoids code duplication by introducing a helper method, which is placed in Utilities for future purpose (providing haptic feedback from other controllers as well). The generator is made static and only created once to avoid feedback delays. The feedback is now a medium haptic one-time impact which comes right with touching the remote buttons.
1 parent 008ea9c commit 2064c03

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

XBMC Remote/RemoteController.m

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,7 @@ - (IBAction)holdKey:(id)sender {
586586
selector:@selector(longpressKey:)
587587
userInfo:params
588588
repeats:NO];
589-
590-
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
591-
BOOL startVibrate = [userDefaults boolForKey:@"vibrate_preference"];
592-
if (startVibrate) {
593-
[[UIDevice currentDevice] playInputClick];
594-
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
595-
}
589+
[Utilities giveHapticFeedback];
596590
}
597591

598592
- (IBAction)stopHoldKey:(id)sender {
@@ -839,13 +833,7 @@ - (void)processButtonPress:(NSInteger)buttonTag {
839833

840834
- (IBAction)startVibrate:(id)sender {
841835
[self processButtonPress:[sender tag]];
842-
843-
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
844-
BOOL startVibrate = [userDefaults boolForKey:@"vibrate_preference"];
845-
if (startVibrate) {
846-
[[UIDevice currentDevice] playInputClick];
847-
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
848-
}
836+
[Utilities giveHapticFeedback];
849837
[[NSNotificationCenter defaultCenter] postNotificationName:@"Input.OnInputFinished" object:nil userInfo:nil];
850838
}
851839

@@ -929,6 +917,7 @@ - (void)processButtonLongPress:(NSInteger)buttonTag {
929917
- (IBAction)handleButtonLongPress:(UILongPressGestureRecognizer*)gestureRecognizer {
930918
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
931919
[self processButtonLongPress:gestureRecognizer.view.tag];
920+
[Utilities giveHapticFeedback];
932921
}
933922
}
934923

XBMC Remote/Utilities.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ typedef NS_ENUM(NSInteger, LogoBackgroundType) {
9191
+ (CGFloat)getTopPadding;
9292
+ (CGFloat)getTopPaddingWithNavBar:(UINavigationController*)navCtrl;
9393
+ (void)sendXbmcHttp:(NSString*)command;
94+
+ (void)giveHapticFeedback;
9495
+ (NSString*)getAppVersionString;
9596
+ (void)checkForReviewRequest;
9697
+ (void)checkLocalNetworkAccess;

XBMC Remote/Utilities.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,18 @@ + (void)sendXbmcHttp:(NSString*)command {
975975
[[NSURLSession.sharedSession dataTaskWithURL:[NSURL URLWithString:serverHTTP]] resume];
976976
}
977977

978+
+ (void)giveHapticFeedback {
979+
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
980+
BOOL feedbackEnabled = [userDefaults boolForKey:@"vibrate_preference"];
981+
if (feedbackEnabled) {
982+
static UIImpactFeedbackGenerator *generator;
983+
if (!generator) {
984+
generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];
985+
}
986+
[generator impactOccurred];
987+
}
988+
}
989+
978990
+ (NSString*)getAppVersionString {
979991
NSDictionary *infoDict = NSBundle.mainBundle.infoDictionary;
980992
NSString *appVersion = [NSString stringWithFormat:@"v%@ (%@)", infoDict[@"CFBundleShortVersionString"], infoDict[(NSString*)kCFBundleVersionKey]];

0 commit comments

Comments
 (0)