Use the correct sort order when using play all
This commit is contained in:
parent
fa1c9d23eb
commit
f49d71f688
@ -479,11 +479,7 @@ public class LibraryActivity extends PlaybackActivity implements AdapterView.OnI
|
||||
|
||||
QueryTask query;
|
||||
if (intent.getBooleanExtra("isHeader", false)) {
|
||||
query = mAdapters[type - 1].buildQuery(true);
|
||||
query.setProjection(projection);
|
||||
// we want to query songs, not albums or artists
|
||||
if (type != MediaUtils.TYPE_SONG)
|
||||
query.setUri(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
|
||||
query = mAdapters[type - 1].buildSongQuery(projection);
|
||||
} else {
|
||||
long id = intent.getLongExtra("id", -1);
|
||||
query = MediaUtils.buildQuery(type, id, projection, null);
|
||||
@ -737,7 +733,7 @@ public class LibraryActivity extends PlaybackActivity implements AdapterView.OnI
|
||||
}
|
||||
case MSG_RUN_QUERY: {
|
||||
final MediaAdapter adapter = (MediaAdapter)message.obj;
|
||||
QueryTask query = adapter.buildQuery(false);
|
||||
QueryTask query = adapter.buildQuery();
|
||||
final Cursor cursor = query.runQuery(getContentResolver());
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
|
@ -71,6 +71,10 @@ public class MediaAdapter extends CursorAdapter implements SectionIndexer {
|
||||
* used to speed up sorting and filtering.
|
||||
*/
|
||||
private String[] mFieldKeys;
|
||||
/**
|
||||
* The columns to query from the content provider.
|
||||
*/
|
||||
private String[] mProjection;
|
||||
/**
|
||||
* If true, show an expand arrow next the the text in each view.
|
||||
*/
|
||||
@ -98,6 +102,10 @@ public class MediaAdapter extends CursorAdapter implements SectionIndexer {
|
||||
* The text to show in the header.
|
||||
*/
|
||||
private String mHeaderText;
|
||||
/**
|
||||
* The sort order for use with buildSongQuery().
|
||||
*/
|
||||
private String mSongSort;
|
||||
|
||||
/**
|
||||
* Construct a MediaAdapter representing the given <code>type</code> of
|
||||
@ -128,12 +136,14 @@ public class MediaAdapter extends CursorAdapter implements SectionIndexer {
|
||||
mStore = MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI;
|
||||
mFields = new String[] { MediaStore.Audio.Artists.ARTIST };
|
||||
mFieldKeys = new String[] { MediaStore.Audio.Artists.ARTIST_KEY };
|
||||
mSongSort = MediaUtils.DEFAULT_SORT;
|
||||
break;
|
||||
case MediaUtils.TYPE_ALBUM:
|
||||
mStore = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
|
||||
mFields = new String[] { MediaStore.Audio.Albums.ARTIST, MediaStore.Audio.Albums.ALBUM };
|
||||
// Why is there no artist_key column constant in the album MediaStore? The column does seem to exist.
|
||||
mFieldKeys = new String[] { "artist_key", MediaStore.Audio.Albums.ALBUM_KEY };
|
||||
mSongSort = "album_key,track";
|
||||
break;
|
||||
case MediaUtils.TYPE_SONG:
|
||||
mStore = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
||||
@ -153,6 +163,11 @@ public class MediaAdapter extends CursorAdapter implements SectionIndexer {
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid value for type: " + type);
|
||||
}
|
||||
|
||||
if (mFields.length == 1)
|
||||
mProjection = new String[] { BaseColumns._ID, mFields[0] };
|
||||
else
|
||||
mProjection = new String[] { BaseColumns._ID, mFields[mFields.length - 1], mFields[0] };
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -240,20 +255,15 @@ public class MediaAdapter extends CursorAdapter implements SectionIndexer {
|
||||
/**
|
||||
* Build the query to be run with runQuery().
|
||||
*
|
||||
* @param projection The columns to query.
|
||||
* @param forceMusicCheck Force the is_music check to be added to the
|
||||
* selection.
|
||||
*/
|
||||
public QueryTask buildQuery(boolean forceMusicCheck)
|
||||
public QueryTask buildQuery(String[] projection, boolean forceMusicCheck)
|
||||
{
|
||||
String constraint = mConstraint;
|
||||
Limiter limiter = mLimiter;
|
||||
|
||||
String[] projection;
|
||||
if (mFields.length == 1)
|
||||
projection = new String[] { BaseColumns._ID, mFields[0] };
|
||||
else
|
||||
projection = new String[] { BaseColumns._ID, mFields[mFields.length - 1], mFields[0] };
|
||||
|
||||
StringBuilder selection = new StringBuilder();
|
||||
String[] selectionArgs = null;
|
||||
|
||||
@ -318,6 +328,31 @@ public class MediaAdapter extends CursorAdapter implements SectionIndexer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a query to populate the adapter with. The result should be set with
|
||||
* changeCursor().
|
||||
*/
|
||||
public QueryTask buildQuery()
|
||||
{
|
||||
return buildQuery(mProjection, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a query for all the songs represented by this adapter, for adding
|
||||
* to the timeline.
|
||||
*
|
||||
* @param projection The columns to query.
|
||||
*/
|
||||
public QueryTask buildSongQuery(String[] projection)
|
||||
{
|
||||
QueryTask query = buildQuery(projection, true);
|
||||
if (mType != MediaUtils.TYPE_SONG) {
|
||||
query.setUri(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
|
||||
query.setSortOrder(mSongSort);
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of media represented by this adapter. One of
|
||||
* MediaUtils.TYPE_*.
|
||||
|
@ -53,6 +53,12 @@ public class MediaUtils {
|
||||
*/
|
||||
public static final int TYPE_GENRE = 5;
|
||||
|
||||
/**
|
||||
* The default sort order for media queries. First artist, then album, then
|
||||
* track number.
|
||||
*/
|
||||
public static final String DEFAULT_SORT = "artist_key,album_key,track";
|
||||
|
||||
/**
|
||||
* Cached random instance.
|
||||
*/
|
||||
@ -125,8 +131,7 @@ public class MediaUtils {
|
||||
selection.append(select);
|
||||
}
|
||||
|
||||
String sort = MediaStore.Audio.Media.ARTIST_KEY + ',' + MediaStore.Audio.Media.ALBUM_KEY + ',' + MediaStore.Audio.Media.TRACK;
|
||||
return new QueryTask(media, projection, selection.toString(), null, sort);
|
||||
return new QueryTask(media, projection, selection.toString(), null, DEFAULT_SORT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -724,9 +724,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
mHandler.removeMessages(PROCESS_SONG);
|
||||
|
||||
mHandler.sendMessage(mHandler.obtainMessage(PROCESS_SONG, song));
|
||||
Message msg = mHandler.obtainMessage(BROADCAST_CHANGE, -1, 0);
|
||||
msg.obj = song;
|
||||
mHandler.sendMessage(msg);
|
||||
mHandler.sendMessage(mHandler.obtainMessage(BROADCAST_CHANGE, -1, 0, song));
|
||||
return song;
|
||||
}
|
||||
|
||||
@ -1145,9 +1143,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
*/
|
||||
public void addSongs(int mode, QueryTask query)
|
||||
{
|
||||
Message msg = mHandler.obtainMessage(QUERY, query);
|
||||
msg.arg1 = mode;
|
||||
mHandler.sendMessage(msg);
|
||||
mHandler.sendMessage(mHandler.obtainMessage(QUERY, mode, 0, query));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,6 +69,24 @@ public class QueryTask {
|
||||
mProjection = projection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the sort order of the pending query.
|
||||
*/
|
||||
public String getSortOrder()
|
||||
{
|
||||
return mSortOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the sort order of the pending query.
|
||||
*
|
||||
* @param sortOrder The new sort order.
|
||||
*/
|
||||
public void setSortOrder(String sortOrder)
|
||||
{
|
||||
mSortOrder = sortOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the query. Should be called on a background thread.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user