aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2017-06-19 11:38:58 -0700
committerScott Jackson <daneren2005@gmail.com>2017-06-19 11:38:58 -0700
commitf863540f073fec131977d071605430b9770d57ae (patch)
treec79602121520cb90fb5ed289df76f5494a903b4d
parentb0e0ab17a5689e726efb51a0a6a56da634aaa79f (diff)
parente41dfa468d47f4ae6b06117040e9903b62fe9aaa (diff)
downloaddsub-f863540f073fec131977d071605430b9770d57ae.tar.gz
dsub-f863540f073fec131977d071605430b9770d57ae.tar.bz2
dsub-f863540f073fec131977d071605430b9770d57ae.zip
Merge branch 'master' into edge
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java17
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java20
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java21
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Notifications.java61
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 2ad6c14c..a813fce2 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 fe18ede0..4b8d9db3 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -1025,6 +1025,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);
@@ -1200,12 +1204,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);
@@ -1226,7 +1231,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) {
@@ -2817,12 +2822,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);
@@ -2844,12 +2850,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);
}
}
});
@@ -3049,8 +3056,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));