diff options
Diffstat (limited to 'app/src/main/java/github')
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<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 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<DownloadFile> getDownloads() { List<DownloadFile> temp = new ArrayList<DownloadFile>(); 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<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 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; |