Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Play next" for artists and albums #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ interface IOdysseyPlaybackService {
void playPlaylist(in PlaylistModel playlist, int position);

// enqueue all tracks of an album from mediastore
void enqueueAlbum(long albumId, String orderKey);
void enqueueAlbum(long albumId, String orderKey, boolean asNext);
void playAlbum(long albumId, String orderKey, int position);

void enqueueRecentAlbums();
void playRecentAlbums();

// enqueue all tracks of an artist from mediastore
void enqueueArtist(long artistId, String albumOrderKey, String trackOrderKey);
void enqueueArtist(long artistId, String albumOrderKey, String trackOrderKey, boolean asNext);
void playArtist(long artistId, String albumOrderKey, String trackOrderKey);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private void enqueueAlbum() {
String trackOrderKey = sharedPref.getString(getString(R.string.pref_album_tracks_sort_order_key), getString(R.string.pref_album_tracks_sort_default));

try {
((GenericActivity) requireActivity()).getPlaybackService().enqueueAlbum(mAlbum.getAlbumId(), trackOrderKey);
((GenericActivity) requireActivity()).getPlaybackService().enqueueAlbum(mAlbum.getAlbumId(), trackOrderKey, false);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ public boolean onContextItemSelected(@NonNull MenuItem item) {
final int itemId = item.getItemId();

if (itemId == R.id.fragment_albums_action_enqueue) {
enqueueAlbum(info.position);
enqueueAlbum(info.position, false);
return true;
} else if (itemId == R.id.fragment_albums_action_enqueueasnext) {
enqueueAlbum(info.position, true);
return true;
} else if (itemId == R.id.fragment_albums_action_play) {
playAlbum(info.position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ public void onItemClick(int position) {
* Call the PBS to enqueue the selected album.
*
* @param position the position of the selected album in the adapter
* @param asNext
*/
protected void enqueueAlbum(int position) {
protected void enqueueAlbum(int position, boolean asNext) {
// identify current album
AlbumModel clickedAlbum = mRecyclerAdapter.getItem(position);
long albumId = clickedAlbum.getAlbumId();
Expand All @@ -302,7 +303,7 @@ protected void enqueueAlbum(int position) {

// enqueue album
try {
((GenericActivity) requireActivity()).getPlaybackService().enqueueAlbum(albumId, trackOrderKey);
((GenericActivity) requireActivity()).getPlaybackService().enqueueAlbum(albumId, trackOrderKey, asNext);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down Expand Up @@ -359,11 +360,15 @@ public boolean onContextItemSelected(@NonNull MenuItem item) {
}

final int itemId = item.getItemId();

if (itemId == R.id.fragment_artist_albums_action_enqueue) {
enqueueAlbum(info.position);
enqueueAlbum(info.position, false);
return true;

} else if (itemId == R.id.fragment_artist_albums_action_enqueueasnext) {
enqueueAlbum(info.position, true);
return true;
} else if (itemId == R.id.fragment_artist_albums_action_play) {
}
else if (itemId == R.id.fragment_artist_albums_action_play) {
playAlbum(info.position);
return true;
}
Expand Down Expand Up @@ -433,7 +438,7 @@ private void enqueueArtist() {

// enqueue artist
try {
((GenericActivity) requireActivity()).getPlaybackService().enqueueArtist(mArtist.getArtistID(), albumOrderKey, trackOrderKey);
((GenericActivity) requireActivity()).getPlaybackService().enqueueArtist(mArtist.getArtistID(), albumOrderKey, trackOrderKey, false);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ public boolean onContextItemSelected(@NonNull MenuItem item) {
final int itemId = item.getItemId();

if (itemId == R.id.fragment_artist_action_enqueue) {
enqueueArtist(info.position);
enqueueArtist(info.position, false);
return true;
} else if (itemId == R.id.fragment_artist_action_enqueueasnext) {
enqueueArtist(info.position, true);
return true;
} else if (itemId == R.id.fragment_artist_action_play) {
playArtist(info.position);
Expand All @@ -238,8 +241,9 @@ public boolean onContextItemSelected(@NonNull MenuItem item) {
* Call the PBS to enqueue the selected artist
*
* @param position the position of the selected artist in the adapter
* @param asNext
*/
private void enqueueArtist(int position) {
private void enqueueArtist(int position, boolean asNext) {

// identify current artist
ArtistModel currentArtist = mAdapter.getItem(position);
Expand All @@ -259,7 +263,7 @@ private void enqueueArtist(int position) {

// enqueue artist
try {
((GenericActivity) requireActivity()).getPlaybackService().enqueueArtist(artistId, albumOrderKey, trackOrderKey);
((GenericActivity) requireActivity()).getPlaybackService().enqueueArtist(artistId, albumOrderKey, trackOrderKey, asNext);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
* Call the PBS to enqueue the selected album.
*
* @param position the position of the selected album in the adapter
* @param asNext
*/
protected void enqueueAlbum(int position) {
protected void enqueueAlbum(int position, boolean asNext) {
// identify current album
AlbumModel clickedAlbum = mAdapter.getItem(position);
long albumId = clickedAlbum.getAlbumId();
Expand All @@ -186,7 +187,7 @@ protected void enqueueAlbum(int position) {

// enqueue album
try {
((GenericActivity) requireActivity()).getPlaybackService().enqueueAlbum(albumId, trackOrderKey);
((GenericActivity) requireActivity()).getPlaybackService().enqueueAlbum(albumId, trackOrderKey, asNext);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@ public boolean onContextItemSelected(@NonNull MenuItem item) {
final int itemId = item.getItemId();

if (itemId == R.id.fragment_albums_action_enqueue) {
enqueueAlbum(info.position);
enqueueAlbum(info.position, false);
return true;
} else if (itemId == R.id.fragment_albums_action_play) {
} else if (itemId == R.id.fragment_albums_action_enqueueasnext) {
enqueueAlbum(info.position, true);
return true;
}
else if (itemId == R.id.fragment_albums_action_play) {
playAlbum(info.position);
return true;
} else if (itemId == R.id.fragment_albums_action_showartist) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public ControlObject(PLAYBACK_ACTION action, long longParam, String param) {
mAction = action;
}

public ControlObject(PLAYBACK_ACTION action, long longParam, String param, boolean asNext) {
mLongParam = longParam;
mStringparam = param;
mBoolparam = asNext;
mAction = action;
}

public ControlObject(PLAYBACK_ACTION action, long longParam, String param, int intParam) {
mLongParam = longParam;
mStringparam = param;
Expand Down Expand Up @@ -128,6 +135,14 @@ public ControlObject(PLAYBACK_ACTION action, long longParam, String stringParam,
mSecondStringParam = stringParam2;
}

public ControlObject(PLAYBACK_ACTION action, long longParam, String stringParam, String stringParam2, boolean boolParam) {
mAction = action;
mLongParam = longParam;
mStringparam = stringParam;
mSecondStringParam = stringParam2;
mBoolparam = boolParam;
}

public ControlObject(PLAYBACK_ACTION action, String stringParam, int intParam) {
mAction = action;
mStringparam = stringParam;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,10 @@ public void playPlaylist(PlaylistModel playlist, int position) throws RemoteExce
mService.get().getHandler().sendMessage(msg);
}


@Override
public void enqueueAlbum(long albumId, String orderKey) {
ControlObject obj = new ControlObject(ControlObject.PLAYBACK_ACTION.ODYSSEY_ENQUEUEALBUM, albumId, orderKey);
public void enqueueAlbum(long albumId, String orderKey, boolean asNext) {
ControlObject obj = new ControlObject(ControlObject .PLAYBACK_ACTION.ODYSSEY_ENQUEUEALBUM, albumId, orderKey, asNext);
Message msg = mService.get().getHandler().obtainMessage();
msg.obj = obj;
mService.get().getHandler().sendMessage(msg);
Expand Down Expand Up @@ -307,8 +308,8 @@ public void playRecentAlbums() {
}

@Override
public void enqueueArtist(long artistId, String albumOrderKey, String trackOrderKey) {
ControlObject obj = new ControlObject(ControlObject.PLAYBACK_ACTION.ODYSSEY_ENQUEUEARTIST, artistId, albumOrderKey, trackOrderKey);
public void enqueueArtist(long artistId, String albumOrderKey, String trackOrderKey, boolean asNext) {
ControlObject obj = new ControlObject(ControlObject.PLAYBACK_ACTION.ODYSSEY_ENQUEUEARTIST, artistId, albumOrderKey, trackOrderKey, asNext);
Message msg = mService.get().getHandler().obtainMessage();
msg.obj = obj;
mService.get().getHandler().sendMessage(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,21 +968,57 @@ public void enqueueTracks(List<TrackModel> tracklist) {
*
* @param albumId The id of the album
* @param orderKey String to specify the order of the tracks
* @param asNext flag if the tracks should be enqueued as next
*/
public void enqueueAlbum(long albumId, String orderKey) {
public void enqueueAlbum(long albumId, String orderKey, boolean asNext) {
mPlaybackServiceStatusHelper.broadcastPlaybackServiceState(PLAYBACKSERVICESTATE.WORKING);
mBusy = true;

// get all tracks for the current albumId from mediastore
List<TrackModel> tracks = MusicLibraryHelper.getTracksForAlbum(albumId, orderKey, getApplicationContext());

// add tracks to current playlist
enqueueTracks(tracks);
if(asNext){
enqueueAsNextTracks(tracks);
}else{
enqueueTracks(tracks);
}



mPlaybackServiceStatusHelper.broadcastPlaybackServiceState(PLAYBACKSERVICESTATE.IDLE);
mBusy = false;
}

private void enqueueAsNextTracks(List<TrackModel> tracklist) {
// Saved to check if we played the last song of the list
int oldSize = mCurrentList.size();

// Add the tracks to the actual list
if(mCurrentPlayingIndex >= 0){
// Enqueue in list structure
mCurrentList.addAll(mCurrentPlayingIndex + 1, tracklist);
mNextPlayingIndex = mCurrentPlayingIndex + 1;
setNextTrackForMP();
} else {
// If track is the first to be added, set playing index to 0
mCurrentList.addAll(0, tracklist);
mCurrentPlayingIndex = 0;
}

if (mCurrentPlayingIndex == oldSize - 1) {
// Next song for MP has to be set for gapless mediaplayback
mNextPlayingIndex = mCurrentPlayingIndex + 1;
setNextTrackForMP();
}

// Inform the helper that the state has changed
mPlaybackServiceStatusHelper.updateStatus();

// update trackRandomGenerator
updateTrackRandomGenerator();
}

/**
* Play all tracks of an album identified by the albumId.
* A previous playlist will be cleared.
Expand All @@ -994,7 +1030,7 @@ public void enqueueAlbum(long albumId, String orderKey) {
public void playAlbum(long albumId, String orderKey, int position) {
clearPlaylist();

enqueueAlbum(albumId, orderKey);
enqueueAlbum(albumId, orderKey, false);

jumpToIndex(position);
}
Expand Down Expand Up @@ -1032,16 +1068,21 @@ public void playRecentAlbums() {
* @param artistId The id of the artist
* @param albumOrderKey String to specify the order of the artist albums
* @param trackOrderKey String to specify the order of the tracks
* @param asNext
*/
public void enqueueArtist(long artistId, String albumOrderKey, String trackOrderKey) {
public void enqueueArtist(long artistId, String albumOrderKey, String trackOrderKey, boolean asNext) {
mPlaybackServiceStatusHelper.broadcastPlaybackServiceState(PLAYBACKSERVICESTATE.WORKING);
mBusy = true;

// get all tracks for the current artistId from mediastore
List<TrackModel> tracks = MusicLibraryHelper.getTracksForArtist(artistId, albumOrderKey, trackOrderKey, getApplicationContext());

// add tracks to current playlist
enqueueTracks(tracks);
if(asNext){
enqueueAsNextTracks(tracks);
} else {
enqueueTracks(tracks);
}

mPlaybackServiceStatusHelper.broadcastPlaybackServiceState(PLAYBACKSERVICESTATE.IDLE);
mBusy = false;
Expand All @@ -1058,7 +1099,7 @@ public void enqueueArtist(long artistId, String albumOrderKey, String trackOrder
public void playArtist(long artistId, String albumOrderKey, String trackOrderKey) {
clearPlaylist();

enqueueArtist(artistId, albumOrderKey, trackOrderKey);
enqueueArtist(artistId, albumOrderKey, trackOrderKey, false);

jumpToIndex(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ public void handleMessage(@Nullable Message msg) {
mService.get().playDirectoryAndSubDirectories(msgObj.getStringParam(), msgObj.getSecondStringParam());
break;
case ODYSSEY_ENQUEUEALBUM:
mService.get().enqueueAlbum(msgObj.getLongParam(), msgObj.getStringParam());
mService.get().enqueueAlbum(msgObj.getLongParam(), msgObj.getStringParam(), msgObj.getBoolParam());
break;
case ODYSSEY_PLAYALBUM:
mService.get().playAlbum(msgObj.getLongParam(), msgObj.getStringParam(), msgObj.getIntParam());
break;
case ODYSSEY_ENQUEUEARTIST:
mService.get().enqueueArtist(msgObj.getLongParam(), msgObj.getStringParam(), msgObj.getSecondStringParam());
mService.get().enqueueArtist(msgObj.getLongParam(), msgObj.getStringParam(), msgObj.getSecondStringParam(),msgObj.getBoolParam());
break;
case ODYSSEY_PLAYARTIST:
mService.get().playArtist(msgObj.getLongParam(), msgObj.getStringParam(), msgObj.getSecondStringParam());
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/menu/context_menu_albums_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@
android:title="@string/context_menu_action_enqueue"
app:showAsAction="never" />

<item
android:id="@+id/fragment_albums_action_enqueueasnext"
android:title="@string/context_menu_action_enqueueasnext"
app:showAsAction="never" />

<item
android:id="@+id/fragment_albums_action_play"
android:title="@string/context_menu_action_playalbum"
app:showAsAction="never" />




<item
android:id="@+id/fragment_albums_action_showartist"
android:title="@string/context_menu_action_showartist"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/context_menu_artist_albums_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
app:showAsAction="never"
android:title="@string/context_menu_action_enqueue" />

<item
android:id="@+id/fragment_artist_albums_action_enqueueasnext"
android:title="@string/context_menu_action_enqueueasnext"
app:showAsAction="never" />

<item
android:id="@+id/fragment_artist_albums_action_play"
app:showAsAction="never"
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/menu/context_menu_artists_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
android:id="@+id/fragment_artist_action_enqueue"
app:showAsAction="never"
android:title="@string/context_menu_action_enqueue" />

<item
android:id="@+id/fragment_artist_action_enqueueasnext"
android:title="@string/context_menu_action_enqueueasnext"
app:showAsAction="never" />
<item
android:id="@+id/fragment_artist_action_play"
app:showAsAction="never"
Expand Down