From 6946b212e47f8fd956c7f49280ae2beaf8919d48 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 19 May 2016 17:24:25 -0700 Subject: Debounce next/previous so bad devices can't spam it --- .../dsub/service/DownloadServiceLifecycleSupport.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index ce2c81f2..78b6c78e 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -56,6 +56,7 @@ import static github.daneren2005.dsub.domain.PlayerState.PREPARING; public class DownloadServiceLifecycleSupport { private static final String TAG = DownloadServiceLifecycleSupport.class.getSimpleName(); public static final String FILENAME_DOWNLOADS_SER = "downloadstate2.ser"; + private static final int DEBOUNCE_TIME = 200; private final DownloadService downloadService; private Looper eventLooper; @@ -413,11 +414,17 @@ public class DownloadServiceLifecycleSupport { break; case RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS: case KeyEvent.KEYCODE_MEDIA_PREVIOUS: - downloadService.previous(); + if(lastPressTime < (System.currentTimeMillis() - DEBOUNCE_TIME)) { + lastPressTime = System.currentTimeMillis(); + downloadService.previous(); + } break; case RemoteControlClient.FLAG_KEY_MEDIA_NEXT: case KeyEvent.KEYCODE_MEDIA_NEXT: - downloadService.next(); + if(lastPressTime < (System.currentTimeMillis() - DEBOUNCE_TIME)) { + lastPressTime = System.currentTimeMillis(); + downloadService.next(); + } break; case KeyEvent.KEYCODE_MEDIA_REWIND: downloadService.rewind(); -- cgit v1.2.3