Skip to content

Commit

Permalink
Debounce next/previous so bad devices can't spam it
Browse files Browse the repository at this point in the history
  • Loading branch information
daneren2005 committed May 20, 2016
1 parent 7ee9cd9 commit 6946b21
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
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;
Expand Down Expand Up @@ -413,11 +414,17 @@ private void handleKeyEvent(KeyEvent event) {
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();
Expand Down

0 comments on commit 6946b21

Please sign in to comment.