move adapter-selection logic into pickSongs()

This commit is contained in:
Adrian Ulrich 2016-06-01 21:53:16 +02:00
parent c9ab3e2461
commit db5546cc6b

View File

@ -373,11 +373,11 @@ public class LibraryActivity
private void pickSongs(Intent intent, int action) private void pickSongs(Intent intent, int action)
{ {
long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID); long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID);
int type = intent.getIntExtra("type", MediaUtils.TYPE_INVALID);
boolean all = false; boolean all = false;
int mode = action; int mode = action;
if (action == ACTION_PLAY_ALL || action == ACTION_ENQUEUE_ALL) { if (action == ACTION_PLAY_ALL || action == ACTION_ENQUEUE_ALL) {
int type = mCurrentAdapter.getMediaType();
boolean notPlayAllAdapter = type > MediaUtils.TYPE_SONG || id == LibraryAdapter.HEADER_ID; boolean notPlayAllAdapter = type > MediaUtils.TYPE_SONG || id == LibraryAdapter.HEADER_ID;
if (mode == ACTION_ENQUEUE_ALL && notPlayAllAdapter) { if (mode == ACTION_ENQUEUE_ALL && notPlayAllAdapter) {
mode = ACTION_ENQUEUE; mode = ACTION_ENQUEUE;
@ -387,8 +387,8 @@ public class LibraryActivity
all = true; all = true;
} }
} }
MediaAdapter adapterSource = (all || id == LibraryAdapter.HEADER_ID ? (MediaAdapter)mPagerAdapter.mAdapters[type] : null);
QueryTask query = buildQueryFromIntent(intent, false, all); QueryTask query = buildQueryFromIntent(intent, false, adapterSource);
query.mode = modeForAction[mode]; query.mode = modeForAction[mode];
PlaybackService.get(this).addSongs(query); PlaybackService.get(this).addSongs(query);
@ -593,10 +593,9 @@ public class LibraryActivity
* @param intent An intent created with * @param intent An intent created with
* {@link LibraryAdapter#createData(View)}. * {@link LibraryAdapter#createData(View)}.
* @param empty If true, use the empty projection (only query id). * @param empty If true, use the empty projection (only query id).
* @param all If true query all songs in the adapter; otherwise query based * @param adapterSource query all songs from this adapter if not null.
* on the row selected.
*/ */
private QueryTask buildQueryFromIntent(Intent intent, boolean empty, boolean all) private QueryTask buildQueryFromIntent(Intent intent, boolean empty, MediaAdapter adapterSource)
{ {
int type = intent.getIntExtra("type", MediaUtils.TYPE_INVALID); int type = intent.getIntExtra("type", MediaUtils.TYPE_INVALID);
@ -610,8 +609,8 @@ public class LibraryActivity
QueryTask query; QueryTask query;
if (type == MediaUtils.TYPE_FILE) { if (type == MediaUtils.TYPE_FILE) {
query = MediaUtils.buildFileQuery(intent.getStringExtra("file"), projection); query = MediaUtils.buildFileQuery(intent.getStringExtra("file"), projection);
} else if (all || id == LibraryAdapter.HEADER_ID) { } else if (adapterSource != null) {
query = ((MediaAdapter)mPagerAdapter.mAdapters[type]).buildSongQuery(projection); query = adapterSource.buildSongQuery(projection);
query.data = id; query.data = id;
} else { } else {
query = MediaUtils.buildQuery(type, id, projection, null); query = MediaUtils.buildQuery(type, id, projection, null);
@ -716,7 +715,7 @@ public class LibraryActivity
break; break;
case CTX_MENU_NEW_PLAYLIST: { case CTX_MENU_NEW_PLAYLIST: {
PlaylistTask playlistTask = new PlaylistTask(-1, null); PlaylistTask playlistTask = new PlaylistTask(-1, null);
playlistTask.query = buildQueryFromIntent(intent, true, false); playlistTask.query = buildQueryFromIntent(intent, true, null);
NewPlaylistDialog dialog = new NewPlaylistDialog(this, null, R.string.create, playlistTask); NewPlaylistDialog dialog = new NewPlaylistDialog(this, null, R.string.create, playlistTask);
dialog.setDismissMessage(mHandler.obtainMessage(MSG_NEW_PLAYLIST, dialog)); dialog.setDismissMessage(mHandler.obtainMessage(MSG_NEW_PLAYLIST, dialog));
dialog.show(); dialog.show();
@ -773,7 +772,7 @@ public class LibraryActivity
long playlistId = intent.getLongExtra("playlist", -1); long playlistId = intent.getLongExtra("playlist", -1);
String playlistName = intent.getStringExtra("playlistName"); String playlistName = intent.getStringExtra("playlistName");
PlaylistTask playlistTask = new PlaylistTask(playlistId, playlistName); PlaylistTask playlistTask = new PlaylistTask(playlistId, playlistName);
playlistTask.query = buildQueryFromIntent(intent, true, false); playlistTask.query = buildQueryFromIntent(intent, true, null);
mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, playlistTask)); mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, playlistTask));
break; break;
case CTX_MENU_MORE_FROM_ARTIST: { case CTX_MENU_MORE_FROM_ARTIST: {