From 079221eafb8c44b96bd4394f6068e7f63ef0a27c Mon Sep 17 00:00:00 2001 From: Christopher Eby Date: Sun, 28 Feb 2010 19:38:37 -0600 Subject: [PATCH] Unify next/previous in CoverView --- src/org/kreed/vanilla/CoverView.java | 45 +++++++++------------ src/org/kreed/vanilla/IPlaybackService.aidl | 3 +- src/org/kreed/vanilla/PlaybackService.java | 9 +---- 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/src/org/kreed/vanilla/CoverView.java b/src/org/kreed/vanilla/CoverView.java index db6258c8..7f9bf064 100644 --- a/src/org/kreed/vanilla/CoverView.java +++ b/src/org/kreed/vanilla/CoverView.java @@ -251,42 +251,37 @@ public class CoverView extends View { mHandler.sendEmptyMessage(0); } - public void nextCover() + private void shiftCover(int delta) { if (mService == null) return; try { - mService.nextSong(); + mService.setCurrentSong(delta); - System.arraycopy(mSongs, 1, mSongs, 0, STORE_SIZE - 1); - System.arraycopy(mBitmaps, 1, mBitmaps, 0, STORE_SIZE - 1); - mSongs[STORE_SIZE - 1] = null; - mBitmaps[STORE_SIZE - 1] = null; + int from = delta > 0 ? 1 : 0; + int to = delta > 0 ? 0 : 1; + int i = delta > 0 ? STORE_SIZE - 1 : 0; + + System.arraycopy(mSongs, from, mSongs, to, STORE_SIZE - 1); + System.arraycopy(mBitmaps, from, mBitmaps, to, STORE_SIZE - 1); + mSongs[i] = null; + mBitmaps[i] = null; reset(); - mHandler.sendEmptyMessage(2); + mHandler.sendEmptyMessage(i); } catch (RemoteException e) { } } + public void nextCover() + { + shiftCover(1); + } + public void previousCover() { - if (mService == null) - return; - - try { - mService.previousSong(); - - System.arraycopy(mSongs, 0, mSongs, 1, STORE_SIZE - 1); - System.arraycopy(mBitmaps, 0, mBitmaps, 1, STORE_SIZE - 1); - mSongs[0] = null; - mBitmaps[0] = null; - reset(); - - mHandler.sendEmptyMessage(0); - } catch (RemoteException e) { - } + shiftCover(-1); } public void togglePlayback() @@ -418,11 +413,7 @@ public class CoverView extends View { scrollTo(mScroller.getCurrX(), mScroller.getCurrY()); postInvalidate(); } else if (mTentativeCover != -1) { - if (mTentativeCover == 2) - nextCover(); - else if (mTentativeCover == 0) - previousCover(); - + shiftCover(mTentativeCover - 1); mTentativeCover = -1; } } diff --git a/src/org/kreed/vanilla/IPlaybackService.aidl b/src/org/kreed/vanilla/IPlaybackService.aidl index 04148988..fb1d9f4c 100644 --- a/src/org/kreed/vanilla/IPlaybackService.aidl +++ b/src/org/kreed/vanilla/IPlaybackService.aidl @@ -31,8 +31,7 @@ interface IPlaybackService { int getPosition(); int getDuration(); - void previousSong(); + void setCurrentSong(int delta); void togglePlayback(); - void nextSong(); void seekToProgress(int progress); } \ No newline at end of file diff --git a/src/org/kreed/vanilla/PlaybackService.java b/src/org/kreed/vanilla/PlaybackService.java index 793b63ac..e18f19c7 100644 --- a/src/org/kreed/vanilla/PlaybackService.java +++ b/src/org/kreed/vanilla/PlaybackService.java @@ -103,14 +103,9 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On } } - public void nextSong() + public void setCurrentSong(int delta) { - setCurrentSong(1); - } - - public void previousSong() - { - setCurrentSong(-1); + PlaybackService.this.setCurrentSong(delta); } public void togglePlayback()