aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-04-06 16:59:30 -0700
committerScott Jackson <daneren2005@gmail.com>2016-04-06 16:59:30 -0700
commit8e2ee0646bfe61361081c584b9fcb49f1edb946f (patch)
tree01a6e903f84c53b863e950282f7f0671c40d472a /app/src/main/java
parenta5c45e631cbca4fd8e78d7ddc02ce1c19b973f50 (diff)
downloaddsub-8e2ee0646bfe61361081c584b9fcb49f1edb946f.tar.gz
dsub-8e2ee0646bfe61361081c584b9fcb49f1edb946f.tar.bz2
dsub-8e2ee0646bfe61361081c584b9fcb49f1edb946f.zip
#669 On Audio Books/Podcasts replace back/forward with rewind/fast forward
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java58
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java65
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java21
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java6
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Notifications.java52
5 files changed, 179 insertions, 23 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
index 487ad83c..8273f61c 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
@@ -107,6 +107,10 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
private long lastBackPressTime = 0;
private DownloadFile currentPlaying;
private PlayerState currentState;
+ private ImageButton previousButton;
+ private ImageButton nextButton;
+ private ImageButton rewindButton;
+ private ImageButton fastforwardButton;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -267,7 +271,25 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
trans.commit();
}
- ImageButton previousButton = (ImageButton) findViewById(R.id.download_previous);
+ rewindButton = (ImageButton) findViewById(R.id.download_rewind);
+ rewindButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new SilentBackgroundTask<Void>(SubsonicFragmentActivity.this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ if (getDownloadService() == null) {
+ return null;
+ }
+
+ getDownloadService().rewind();
+ return null;
+ }
+ }.execute();
+ }
+ });
+
+ previousButton = (ImageButton) findViewById(R.id.download_previous);
previousButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -305,7 +327,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
}
});
- ImageButton nextButton = (ImageButton) findViewById(R.id.download_next);
+ nextButton = (ImageButton) findViewById(R.id.download_next);
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -322,6 +344,24 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
}.execute();
}
});
+
+ fastforwardButton = (ImageButton) findViewById(R.id.download_fastforward);
+ fastforwardButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ new SilentBackgroundTask<Void>(SubsonicFragmentActivity.this) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ if (getDownloadService() == null) {
+ return null;
+ }
+
+ getDownloadService().fastForward();
+ return null;
+ }
+ }.execute();
+ }
+ });
}
@Override
@@ -875,6 +915,20 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
}
getImageLoader().loadImage(coverArtView, song, false, height, false);
}
+
+ if(currentPlaying != null && currentPlaying.getSong() != null && (currentPlaying.getSong().isPodcast() || currentPlaying.getSong().isAudioBook())) {
+ previousButton.setVisibility(View.GONE);
+ nextButton.setVisibility(View.GONE);
+
+ rewindButton.setVisibility(View.VISIBLE);
+ fastforwardButton.setVisibility(View.VISIBLE);
+ } else {
+ previousButton.setVisibility(View.VISIBLE);
+ nextButton.setVisibility(View.VISIBLE);
+
+ rewindButton.setVisibility(View.GONE);
+ fastforwardButton.setVisibility(View.GONE);
+ }
}
@Override
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
index 9bca096b..c8e99f51 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
@@ -88,7 +88,6 @@ import java.util.concurrent.ScheduledFuture;
public class NowPlayingFragment extends SubsonicFragment implements OnGestureListener, SectionAdapter.OnItemClickedListener<DownloadFile>, OnSongChangedListener {
private static final String TAG = NowPlayingFragment.class.getSimpleName();
private static final int PERCENTAGE_OF_SCREEN_FOR_SWIPE = 10;
- private static final int INCREMENT_TIME = 5000;
private static final int ACTION_PREVIOUS = 1;
private static final int ACTION_NEXT = 2;
@@ -106,6 +105,8 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
private SeekBar progressBar;
private AutoRepeatButton previousButton;
private AutoRepeatButton nextButton;
+ private AutoRepeatButton rewindButton;
+ private AutoRepeatButton fastforwardButton;
private View pauseButton;
private View stopButton;
private View startButton;
@@ -172,6 +173,8 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
progressBar = (SeekBar)rootView.findViewById(R.id.download_progress_bar);
previousButton = (AutoRepeatButton)rootView.findViewById(R.id.download_previous);
nextButton = (AutoRepeatButton)rootView.findViewById(R.id.download_next);
+ rewindButton = (AutoRepeatButton) rootView.findViewById(R.id.download_rewind);
+ fastforwardButton = (AutoRepeatButton) rootView.findViewById(R.id.download_fastforward);
pauseButton =rootView.findViewById(R.id.download_pause);
stopButton =rootView.findViewById(R.id.download_stop);
startButton =rootView.findViewById(R.id.download_start);
@@ -240,7 +243,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
});
previousButton.setOnRepeatListener(new Runnable() {
public void run() {
- changeProgress(-INCREMENT_TIME);
+ changeProgress(true);
}
});
@@ -260,10 +263,35 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
});
nextButton.setOnRepeatListener(new Runnable() {
public void run() {
- changeProgress(INCREMENT_TIME);
+ changeProgress(false);
}
});
+ rewindButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ changeProgress(true);
+ }
+ });
+ rewindButton.setOnRepeatListener(new Runnable() {
+ public void run() {
+ changeProgress(true);
+ }
+ });
+
+ fastforwardButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ changeProgress(false);
+ }
+ });
+ fastforwardButton.setOnRepeatListener(new Runnable() {
+ public void run() {
+ changeProgress(false);
+ }
+ });
+
+
pauseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -948,31 +976,22 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
}
}
- private void changeProgress(final int ms) {
+ private void changeProgress(final boolean rewind) {
final DownloadService downloadService = getDownloadService();
if(downloadService == null) {
return;
}
new SilentBackgroundTask<Void>(context) {
- boolean isJukeboxEnabled;
- int msPlayed;
- Integer duration;
- PlayerState playerState;
int seekTo;
@Override
protected Void doInBackground() throws Throwable {
- msPlayed = Math.max(0, downloadService.getPlayerPosition());
- duration = downloadService.getPlayerDuration();
- playerState = getDownloadService().getPlayerState();
- int msTotal = duration == null ? 0 : duration;
- if(msPlayed + ms > msTotal) {
- seekTo = msTotal;
+ if(rewind) {
+ seekTo = downloadService.rewind();
} else {
- seekTo = msPlayed + ms;
+ seekTo = downloadService.fastForward();
}
- downloadService.seekTo(seekTo);
return null;
}
@@ -1169,6 +1188,20 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
public void onSongChanged(DownloadFile currentPlaying, int currentPlayingIndex) {
this.currentPlaying = currentPlaying;
setupSubtitle(currentPlayingIndex);
+
+ if(currentPlaying != null && currentPlaying.getSong() != null && (currentPlaying.getSong().isPodcast() || currentPlaying.getSong().isAudioBook())) {
+ previousButton.setVisibility(View.GONE);
+ nextButton.setVisibility(View.GONE);
+
+ rewindButton.setVisibility(View.VISIBLE);
+ fastforwardButton.setVisibility(View.VISIBLE);
+ } else {
+ previousButton.setVisibility(View.VISIBLE);
+ nextButton.setVisibility(View.VISIBLE);
+
+ rewindButton.setVisibility(View.GONE);
+ fastforwardButton.setVisibility(View.GONE);
+ }
}
private void setupSubtitle(int currentPlayingIndex) {
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
index 2d46c1d4..01007b68 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -1131,6 +1131,27 @@ public class DownloadService extends Service {
handleError(x);
}
}
+ public synchronized int rewind() {
+ return seekToWrapper(-REWIND);
+ }
+ public synchronized int fastForward() {
+ return seekToWrapper(FAST_FORWARD);
+ }
+ protected int seekToWrapper(int difference) {
+ int msPlayed = Math.max(0, getPlayerPosition());
+ Integer duration = getPlayerDuration();
+ int msTotal = duration == null ? 0 : duration;
+
+ int seekTo;
+ if(msPlayed + difference > msTotal) {
+ seekTo = msTotal;
+ } else {
+ seekTo = msPlayed + difference;
+ }
+ seekTo(seekTo);
+
+ return seekTo;
+ }
public synchronized void previous() {
int index = getCurrentPlayingIndex();
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 fe75e248..8c61464f 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -408,6 +408,12 @@ public class DownloadServiceLifecycleSupport {
case KeyEvent.KEYCODE_MEDIA_NEXT:
downloadService.next();
break;
+ case KeyEvent.KEYCODE_MEDIA_REWIND:
+ downloadService.rewind();
+ break;
+ case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
+ downloadService.fastForward();
+ break;
case RemoteControlClient.FLAG_KEY_MEDIA_STOP:
case KeyEvent.KEYCODE_MEDIA_STOP:
downloadService.stop();
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
index a59a9766..e4f9edeb 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java
@@ -104,7 +104,7 @@ public final class Notifications {
handler.post(new Runnable() {
@Override
public void run() {
- if(playing) {
+ if (playing) {
downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification);
} else {
playShowing = false;
@@ -121,7 +121,8 @@ public final class Notifications {
DSubWidgetProvider.notifyInstances(context, downloadService, playing);
}
- private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded, boolean playing, boolean remote){
+ private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded, boolean playing, boolean remote) {
+ boolean isLongFile = song.isAudioBook() || song.isPodcast();
// Use the same text for the ticker and the expanded notification
String title = song.getTitle();
@@ -156,20 +157,47 @@ public final class Notifications {
if(persistent) {
if(expanded) {
rv.setImageViewResource(R.id.control_pause, playing ? R.drawable.notification_pause : R.drawable.notification_start);
+
+ if(isLongFile && playing) {
+ rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind);
+ rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward);
+ } else {
+ rv.setImageViewResource(R.id.control_previous, R.drawable.notification_backward);
+ rv.setImageViewResource(R.id.control_next, R.drawable.notification_forward);
+ }
} else {
rv.setImageViewResource(R.id.control_previous, playing ? R.drawable.notification_pause : R.drawable.notification_start);
- rv.setImageViewResource(R.id.control_pause, R.drawable.notification_forward);
+ if(isLongFile && playing) {
+ rv.setImageViewResource(R.id.control_pause, R.drawable.notification_fastforward);
+ } else {
+ rv.setImageViewResource(R.id.control_pause, R.drawable.notification_forward);
+ }
rv.setImageViewResource(R.id.control_next, R.drawable.notification_close);
}
+ } else if(isLongFile) {
+ rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind);
+ rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward);
+ } else {
+ // Necessary for switching back since it appears to re-use the same layout
+ rv.setImageViewResource(R.id.control_previous, R.drawable.notification_backward);
+ rv.setImageViewResource(R.id.control_next, R.drawable.notification_forward);
}
// Create actions for media buttons
PendingIntent pendingIntent;
- int previous = 0, pause = 0, next = 0, close = 0;
+ int previous = 0, pause = 0, next = 0, close = 0, rewind = 0, fastForward = 0;
if(persistent && !expanded) {
pause = R.id.control_previous;
- next = R.id.control_pause;
+ if(isLongFile && playing) {
+ fastForward = R.id.control_pause;
+ } else {
+ next = R.id.control_pause;
+ }
close = R.id.control_next;
+ } else if(isLongFile && (!persistent || (expanded && playing))) {
+ rewind = R.id.control_previous;
+ pause = R.id.control_pause;
+ fastForward = R.id.control_next;
} else {
previous = R.id.control_previous;
pause = R.id.control_pause;
@@ -188,6 +216,13 @@ public final class Notifications {
pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
rv.setOnClickPendingIntent(previous, pendingIntent);
}
+ if(rewind > 0) {
+ Intent rewindIntent = new Intent("KEYCODE_MEDIA_REWIND");
+ rewindIntent.setComponent(new ComponentName(context, DownloadService.class));
+ rewindIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_REWIND));
+ pendingIntent = PendingIntent.getService(context, 0, rewindIntent, 0);
+ rv.setOnClickPendingIntent(rewind, pendingIntent);
+ }
if(pause > 0) {
if(playing) {
Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE");
@@ -210,6 +245,13 @@ public final class Notifications {
pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0);
rv.setOnClickPendingIntent(next, pendingIntent);
}
+ if(fastForward > 0) {
+ Intent fastForwardIntent = new Intent("KEYCODE_MEDIA_FAST_FORWARD");
+ fastForwardIntent.setComponent(new ComponentName(context, DownloadService.class));
+ fastForwardIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD));
+ pendingIntent = PendingIntent.getService(context, 0, fastForwardIntent, 0);
+ rv.setOnClickPendingIntent(fastForward, pendingIntent);
+ }
if(close > 0) {
Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP");
prevIntent.setComponent(new ComponentName(context, DownloadService.class));