diff options
author | Scott Jackson <daneren2005@users.noreply.github.com> | 2017-06-19 11:37:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-19 11:37:47 -0700 |
commit | e41dfa468d47f4ae6b06117040e9903b62fe9aaa (patch) | |
tree | 7cee15551a6d12660a4bbf9158eae4c10f289294 | |
parent | df7e77a3e658a3a41b2066dec81c06bb51c41daf (diff) | |
parent | 4c021cf9b36f91146ce0c25a05f9c4c9140f91e9 (diff) | |
download | dsub-e41dfa468d47f4ae6b06117040e9903b62fe9aaa.tar.gz dsub-e41dfa468d47f4ae6b06117040e9903b62fe9aaa.tar.bz2 dsub-e41dfa468d47f4ae6b06117040e9903b62fe9aaa.zip |
Merge pull request #805 from KBerstene/bugfix/playbackcontrols
Bugfix: Previous and next button behavior while long song is paused
4 files changed, 73 insertions, 46 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 08cbf150..803e6f72 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -920,7 +920,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo } @Override - public void onSongChanged(DownloadFile currentPlaying, int currentPlayingIndex) { + public void onSongChanged(DownloadFile currentPlaying, int currentPlayingIndex, boolean shouldFastForward) { this.currentPlaying = currentPlaying; MusicDirectory.Entry song = null; @@ -950,13 +950,18 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo getImageLoader().loadImage(coverArtView, song, false, height, false); } - if(getDownloadService().isCurrentPlayingSingle()) { + updateMediaButtons(shouldFastForward); + } + + private void updateMediaButtons(boolean shouldFastForward) { + DownloadService downloadService = getDownloadService(); + if(downloadService.isCurrentPlayingSingle()) { previousButton.setVisibility(View.GONE); nextButton.setVisibility(View.GONE); rewindButton.setVisibility(View.GONE); fastforwardButton.setVisibility(View.GONE); } else { - if (currentPlaying != null && currentPlaying.getSong() != null && (currentPlaying.getSong().isPodcast() || currentPlaying.getSong().isAudioBook())) { + if (shouldFastForward) { previousButton.setVisibility(View.GONE); nextButton.setVisibility(View.GONE); @@ -973,9 +978,11 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo } @Override - public void onSongsChanged(List<DownloadFile> songs, DownloadFile currentPlaying, int currentPlayingIndex) { + public void onSongsChanged(List<DownloadFile> songs, DownloadFile currentPlaying, int currentPlayingIndex, boolean shouldFastForward) { if(this.currentPlaying != currentPlaying || this.currentPlaying == null) { - onSongChanged(currentPlaying, currentPlayingIndex); + onSongChanged(currentPlaying, currentPlayingIndex, shouldFastForward); + } else { + updateMediaButtons(shouldFastForward); } } 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 19df9bfb..10623b4e 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -1222,17 +1222,24 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis } @Override - public void onSongChanged(DownloadFile currentPlaying, int currentPlayingIndex) { + public void onSongChanged(DownloadFile currentPlaying, int currentPlayingIndex, boolean shouldFastForward) { this.currentPlaying = currentPlaying; setupSubtitle(currentPlayingIndex); - if(getDownloadService().isCurrentPlayingSingle()) { + updateMediaButton(shouldFastForward); + updateTitle(); + setPlaybackSpeed(); + } + + private void updateMediaButton(boolean shouldFastForward) { + DownloadService downloadService = getDownloadService(); + if(downloadService.isCurrentPlayingSingle()) { previousButton.setVisibility(View.GONE); nextButton.setVisibility(View.GONE); rewindButton.setVisibility(View.GONE); fastforwardButton.setVisibility(View.GONE); } else { - if (currentPlaying != null && !currentPlaying.isSong()) { + if (downloadService.shouldFastForward()) { previousButton.setVisibility(View.GONE); nextButton.setVisibility(View.GONE); @@ -1246,8 +1253,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis fastforwardButton.setVisibility(View.GONE); } } - updateTitle(); - setPlaybackSpeed(); } private void setupSubtitle(int currentPlayingIndex) { @@ -1274,7 +1279,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis } @Override - public void onSongsChanged(List<DownloadFile> songs, DownloadFile currentPlaying, int currentPlayingIndex) { + public void onSongsChanged(List<DownloadFile> songs, DownloadFile currentPlaying, int currentPlayingIndex, boolean shouldFastForward) { currentPlayingSize = songs.size(); DownloadService downloadService = getDownloadService(); @@ -1303,9 +1308,10 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis } if(this.currentPlaying != currentPlaying) { - onSongChanged(currentPlaying, currentPlayingIndex); + onSongChanged(currentPlaying, currentPlayingIndex, shouldFastForward); onMetadataUpdate(currentPlaying != null ? currentPlaying.getSong() : null, DownloadService.METADATA_UPDATED_ALL); } else { + updateMediaButton(shouldFastForward); setupSubtitle(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 636745d6..8213a7d4 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -1027,6 +1027,10 @@ public class DownloadService extends Service { } } + public synchronized boolean shouldFastForward() { + return size() == 1 || (currentPlaying != null && !currentPlaying.isSong()); + } + public synchronized List<DownloadFile> getDownloads() { List<DownloadFile> temp = new ArrayList<DownloadFile>(); temp.addAll(downloadList); @@ -1202,12 +1206,13 @@ public class DownloadService extends Service { } // If only one song, just skip within song - if(size() == 1 || (currentPlaying != null && !currentPlaying.isSong())) { + if(shouldFastForward()) { rewind(); return; + } else if(playerState == PREPARING || playerState == PREPARED) { + return; } - // Restart song if played more than five seconds. if (getPlayerPosition() > 5000 || (index == 0 && getRepeatMode() != RepeatMode.ALL)) { seekTo(0); @@ -1228,7 +1233,7 @@ public class DownloadService extends Service { } public synchronized void next(boolean forceCutoff, boolean forceStart) { // If only one song, just skip within song - if(size() == 1 || (currentPlaying != null && !currentPlaying.isSong())) { + if(shouldFastForward()) { fastForward(); return; } else if(playerState == PREPARING || playerState == PREPARED) { @@ -2819,12 +2824,13 @@ public class DownloadService extends Service { private void onSongChanged() { final long atRevision = revision; synchronized(onSongChangedListeners) { + final boolean shouldFastForward = shouldFastForward(); for (final OnSongChangedListener listener : onSongChangedListeners) { handler.post(new Runnable() { @Override public void run() { if (revision == atRevision && instance != null) { - listener.onSongChanged(currentPlaying, currentPlayingIndex); + listener.onSongChanged(currentPlaying, currentPlayingIndex, shouldFastForward); MusicDirectory.Entry entry = currentPlaying != null ? currentPlaying.getSong() : null; listener.onMetadataUpdate(entry, METADATA_UPDATED_ALL); @@ -2846,12 +2852,13 @@ public class DownloadService extends Service { private void onSongsChanged() { final long atRevision = revision; synchronized(onSongChangedListeners) { + final boolean shouldFastForward = shouldFastForward(); for (final OnSongChangedListener listener : onSongChangedListeners) { handler.post(new Runnable() { @Override public void run() { if (revision == atRevision && instance != null) { - listener.onSongsChanged(downloadList, currentPlaying, currentPlayingIndex); + listener.onSongsChanged(downloadList, currentPlaying, currentPlayingIndex, shouldFastForward); } } }); @@ -3051,8 +3058,8 @@ public class DownloadService extends Service { } public interface OnSongChangedListener { - void onSongChanged(DownloadFile currentPlaying, int currentPlayingIndex); - void onSongsChanged(List<DownloadFile> songs, DownloadFile currentPlaying, int currentPlayingIndex); + void onSongChanged(DownloadFile currentPlaying, int currentPlayingIndex, boolean shouldFastForward); + void onSongsChanged(List<DownloadFile> songs, DownloadFile currentPlaying, int currentPlayingIndex, boolean shouldFastForward); void onSongProgress(DownloadFile currentPlaying, int millisPlayed, Integer duration, boolean isSeekable); void onStateUpdate(DownloadFile downloadFile, PlayerState playerState); void onMetadataUpdate(MusicDirectory.Entry entry, int fieldChange); 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 d6a92b07..750ab40c 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java @@ -68,9 +68,10 @@ public final class Notifications { } boolean remote = downloadService.isRemoteEnabled(); boolean isSingle = downloadService.isCurrentPlayingSingle(); + boolean shouldFastForward = downloadService.shouldFastForward(); if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.JELLY_BEAN){ RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded); - setupViews(expandedContentView ,context, song, true, playing, remote, isSingle); + setupViews(expandedContentView ,context, song, true, playing, remote, isSingle, shouldFastForward); notification.bigContentView = expandedContentView; notification.priority = Notification.PRIORITY_HIGH; } @@ -83,7 +84,7 @@ public final class Notifications { } RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification); - setupViews(smallContentView, context, song, false, playing, remote, isSingle); + setupViews(smallContentView, context, song, false, playing, remote, isSingle, shouldFastForward); notification.contentView = smallContentView; Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class); @@ -137,9 +138,7 @@ 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, boolean isSingleFile) { - boolean isLongFile = song.isAudioBook() || song.isPodcast(); - + private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded, boolean playing, boolean remote, boolean isSingleFile, boolean shouldFastForward) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String arist = song.getArtist(); @@ -174,7 +173,7 @@ public final class Notifications { if(expanded) { rv.setImageViewResource(R.id.control_pause, playing ? R.drawable.notification_pause : R.drawable.notification_start); - if(isLongFile && playing) { + if(shouldFastForward) { rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind); rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward); } else { @@ -183,14 +182,14 @@ public final class Notifications { } } else { rv.setImageViewResource(R.id.control_previous, playing ? R.drawable.notification_pause : R.drawable.notification_start); - if(isLongFile && playing) { + if(shouldFastForward) { 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) { + } else if(shouldFastForward) { rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind); rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward); } else { @@ -200,31 +199,38 @@ public final class Notifications { } // Create actions for media buttons - PendingIntent pendingIntent; int previous = 0, pause = 0, next = 0, close = 0, rewind = 0, fastForward = 0; - if(persistent && !expanded) { - pause = R.id.control_previous; - if(isLongFile && playing) { - fastForward = R.id.control_pause; + if (expanded) { + if (shouldFastForward) { + rewind = R.id.control_previous; + pause = R.id.control_pause; + fastForward = R.id.control_next; } else { - next = R.id.control_pause; + previous = R.id.control_previous; + pause = R.id.control_pause; + next = R.id.control_next; + } + + if (remote || persistent) { + close = R.id.notification_close; + rv.setViewVisibility(close, View.VISIBLE); } - 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; - next = R.id.control_next; + if (persistent) { + pause = R.id.control_previous; + if(shouldFastForward) { + fastForward = R.id.control_pause; + } else { + next = R.id.control_pause; + } + close = R.id.control_next; + } else { + rewind = R.id.control_previous; + pause = R.id.control_pause; + fastForward = R.id.control_next; + } } - if((remote || persistent) && close == 0 && expanded) { - close = R.id.notification_close; - rv.setViewVisibility(close, View.VISIBLE); - } - if(isSingleFile) { if(previous > 0) { rv.setViewVisibility(previous, View.GONE); @@ -246,6 +252,7 @@ public final class Notifications { } } + PendingIntent pendingIntent; if(previous > 0) { Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); |