From cbe2f2058f391cef78315253dbea3524aba7d81a Mon Sep 17 00:00:00 2001 From: "Kevin T. Berstene" Date: Sun, 11 Jun 2017 21:24:37 -0400 Subject: Fixed previous and next button behavior while long song is paused --- .../daneren2005/dsub/service/DownloadService.java | 4 +- .../daneren2005/dsub/util/Notifications.java | 46 +++++++++++++--------- 2 files changed, 29 insertions(+), 21 deletions(-) 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..4d3107b3 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -1202,7 +1202,7 @@ public class DownloadService extends Service { } // If only one song, just skip within song - if(size() == 1 || (currentPlaying != null && !currentPlaying.isSong())) { + if(size() == 1) { rewind(); return; } @@ -1228,7 +1228,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(size() == 1) { fastForward(); return; } else if(playerState == PREPARING || playerState == PREPARED) { 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..7444911f 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java @@ -200,31 +200,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 (isLongFile && playing) { + 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(isLongFile && playing) { + 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 +253,7 @@ public final class Notifications { } } + PendingIntent pendingIntent; if(previous > 0) { Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS"); prevIntent.setComponent(new ComponentName(context, DownloadService.class)); -- cgit v1.2.3 From 3785b69190519824771cdc1c5a6ce8cbd50394d3 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 14 Jun 2017 17:45:06 -0700 Subject: Make sure to always show correct fast foward or next buttons --- .../dsub/activity/SubsonicFragmentActivity.java | 17 +++++++++---- .../dsub/fragments/NowPlayingFragment.java | 20 +++++++++------ .../daneren2005/dsub/service/DownloadService.java | 29 +++++++++++----------- .../daneren2005/dsub/util/Notifications.java | 19 +++++++------- 4 files changed, 48 insertions(+), 37 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 songs, DownloadFile currentPlaying, int currentPlayingIndex) { + public void onSongsChanged(List 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 songs, DownloadFile currentPlaying, int currentPlayingIndex) { + public void onSongsChanged(List 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 4d3107b3..6d11db9b 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 getDownloads() { List temp = new ArrayList(); temp.addAll(downloadList); @@ -1196,18 +1200,15 @@ public class DownloadService extends Service { } public synchronized void previous() { - int index = getCurrentPlayingIndex(); - if (index == -1) { + if(playerState == PREPARING || playerState == PREPARED) { return; } - // If only one song, just skip within song - if(size() == 1) { - rewind(); + int index = getCurrentPlayingIndex(); + if (index == -1) { return; } - // Restart song if played more than five seconds. if (getPlayerPosition() > 5000 || (index == 0 && getRepeatMode() != RepeatMode.ALL)) { seekTo(0); @@ -1227,11 +1228,7 @@ public class DownloadService extends Service { next(forceCutoff, false); } public synchronized void next(boolean forceCutoff, boolean forceStart) { - // If only one song, just skip within song - if(size() == 1) { - fastForward(); - return; - } else if(playerState == PREPARING || playerState == PREPARED) { + if(playerState == PREPARING || playerState == PREPARED) { return; } @@ -2819,12 +2816,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 +2844,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 +3050,8 @@ public class DownloadService extends Service { } public interface OnSongChangedListener { - void onSongChanged(DownloadFile currentPlaying, int currentPlayingIndex); - void onSongsChanged(List songs, DownloadFile currentPlaying, int currentPlayingIndex); + void onSongChanged(DownloadFile currentPlaying, int currentPlayingIndex, boolean shouldFastForward); + void onSongsChanged(List 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 7444911f..af3b7704 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 && playing) { 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 && 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) { + } else if(shouldFastForward) { rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind); rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward); } else { @@ -202,7 +201,7 @@ public final class Notifications { // Create actions for media buttons int previous = 0, pause = 0, next = 0, close = 0, rewind = 0, fastForward = 0; if (expanded) { - if (isLongFile && playing) { + if (shouldFastForward && playing) { rewind = R.id.control_previous; pause = R.id.control_pause; fastForward = R.id.control_next; @@ -219,7 +218,7 @@ public final class Notifications { } else { if (persistent) { pause = R.id.control_previous; - if(isLongFile && playing) { + if(shouldFastForward && playing) { fastForward = R.id.control_pause; } else { next = R.id.control_pause; -- cgit v1.2.3 From 807af83a4be6870daf3feb9de6273696d3a68587 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 14 Jun 2017 17:48:23 -0700 Subject: Fix persistent notification showing different action when paused --- app/src/main/java/github/daneren2005/dsub/util/Notifications.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 af3b7704..750ab40c 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Notifications.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Notifications.java @@ -173,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(shouldFastForward && playing) { + if(shouldFastForward) { rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind); rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward); } else { @@ -182,7 +182,7 @@ public final class Notifications { } } else { rv.setImageViewResource(R.id.control_previous, playing ? R.drawable.notification_pause : R.drawable.notification_start); - if(shouldFastForward && playing) { + if(shouldFastForward) { rv.setImageViewResource(R.id.control_pause, R.drawable.notification_fastforward); } else { rv.setImageViewResource(R.id.control_pause, R.drawable.notification_forward); @@ -201,7 +201,7 @@ public final class Notifications { // Create actions for media buttons int previous = 0, pause = 0, next = 0, close = 0, rewind = 0, fastForward = 0; if (expanded) { - if (shouldFastForward && playing) { + if (shouldFastForward) { rewind = R.id.control_previous; pause = R.id.control_pause; fastForward = R.id.control_next; @@ -218,7 +218,7 @@ public final class Notifications { } else { if (persistent) { pause = R.id.control_previous; - if(shouldFastForward && playing) { + if(shouldFastForward) { fastForward = R.id.control_pause; } else { next = R.id.control_pause; -- cgit v1.2.3 From a1f8a4eddd2593f4ce5e23ab0c1eea3f6a93af6f Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 14 Jun 2017 17:51:57 -0700 Subject: Put the rewind/fastforward fallbacks back for bluetooth buttons and such --- .../github/daneren2005/dsub/service/DownloadService.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 6d11db9b..5ef629d0 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -1209,6 +1209,14 @@ public class DownloadService extends Service { return; } + // If only one song, just skip within song + 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 +1236,11 @@ public class DownloadService extends Service { next(forceCutoff, false); } public synchronized void next(boolean forceCutoff, boolean forceStart) { - if(playerState == PREPARING || playerState == PREPARED) { + // If only one song, just skip within song + if(shouldFastForward()) { + fastForward(); + return; + } else if(playerState == PREPARING || playerState == PREPARED) { return; } -- cgit v1.2.3 From 4c021cf9b36f91146ce0c25a05f9c4c9140f91e9 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 14 Jun 2017 17:54:06 -0700 Subject: Remove duplicate check --- .../main/java/github/daneren2005/dsub/service/DownloadService.java | 4 ---- 1 file changed, 4 deletions(-) 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 5ef629d0..8213a7d4 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -1200,10 +1200,6 @@ public class DownloadService extends Service { } public synchronized void previous() { - if(playerState == PREPARING || playerState == PREPARED) { - return; - } - int index = getCurrentPlayingIndex(); if (index == -1) { return; -- cgit v1.2.3