Subclass MediaAdapter for songs
Override the sort order when limiting by album to sort by track number
This commit is contained in:
parent
f5f86018ec
commit
8f76a2be25
@ -50,11 +50,10 @@ public class MediaAdapter extends CursorAdapter implements FilterQueryProvider {
|
|||||||
private String[] mFields;
|
private String[] mFields;
|
||||||
private String[] mFieldKeys;
|
private String[] mFieldKeys;
|
||||||
private View.OnClickListener mExpanderListener;
|
private View.OnClickListener mExpanderListener;
|
||||||
private String mSelection;
|
|
||||||
private String[] mLimiter;
|
private String[] mLimiter;
|
||||||
private CharSequence mConstraint;
|
private CharSequence mConstraint;
|
||||||
|
|
||||||
public MediaAdapter(Context context, Uri store, String[] fields, String[] fieldKeys, View.OnClickListener expanderListener, String selection)
|
public MediaAdapter(Context context, Uri store, String[] fields, String[] fieldKeys, View.OnClickListener expanderListener)
|
||||||
{
|
{
|
||||||
super(context, null, true);
|
super(context, null, true);
|
||||||
|
|
||||||
@ -62,7 +61,6 @@ public class MediaAdapter extends CursorAdapter implements FilterQueryProvider {
|
|||||||
mFields = fields;
|
mFields = fields;
|
||||||
mFieldKeys = fieldKeys;
|
mFieldKeys = fieldKeys;
|
||||||
mExpanderListener = expanderListener;
|
mExpanderListener = expanderListener;
|
||||||
mSelection = selection;
|
|
||||||
|
|
||||||
setFilterQueryProvider(this);
|
setFilterQueryProvider(this);
|
||||||
|
|
||||||
@ -75,6 +73,16 @@ public class MediaAdapter extends CursorAdapter implements FilterQueryProvider {
|
|||||||
getFilter().filter(constraint, listener);
|
getFilter().filter(constraint, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getDefaultSelection()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getSortOrder()
|
||||||
|
{
|
||||||
|
return mFieldKeys[mFieldKeys.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
public Cursor runQuery(CharSequence constraint)
|
public Cursor runQuery(CharSequence constraint)
|
||||||
{
|
{
|
||||||
ContentResolver resolver = ContextApplication.getContext().getContentResolver();
|
ContentResolver resolver = ContextApplication.getContext().getContentResolver();
|
||||||
@ -83,8 +91,9 @@ public class MediaAdapter extends CursorAdapter implements FilterQueryProvider {
|
|||||||
String[] selectionArgs;
|
String[] selectionArgs;
|
||||||
String limiter;
|
String limiter;
|
||||||
|
|
||||||
if (mSelection != null)
|
String defaultSelection = getDefaultSelection();
|
||||||
selection.append(mSelection);
|
if (defaultSelection != null)
|
||||||
|
selection.append(defaultSelection);
|
||||||
|
|
||||||
if (mLimiter != null) {
|
if (mLimiter != null) {
|
||||||
int i = Math.min(mLimiter.length, mFields.length) - 1;
|
int i = Math.min(mLimiter.length, mFields.length) - 1;
|
||||||
@ -132,7 +141,7 @@ public class MediaAdapter extends CursorAdapter implements FilterQueryProvider {
|
|||||||
else
|
else
|
||||||
projection = new String[] { BaseColumns._ID, mFields[mFields.length - 1], mFields[0] };
|
projection = new String[] { BaseColumns._ID, mFields[mFields.length - 1], mFields[0] };
|
||||||
|
|
||||||
return resolver.query(mStore, projection, selection.toString(), selectionArgs, mFieldKeys[mFieldKeys.length - 1]);
|
return resolver.query(mStore, projection, selection.toString(), selectionArgs, getSortOrder());
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean hasExpanders()
|
public final boolean hasExpanders()
|
||||||
|
43
src/org/kreed/vanilla/SongMediaAdapter.java
Normal file
43
src/org/kreed/vanilla/SongMediaAdapter.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Christopher Eby <kreed@kreed.org>
|
||||||
|
*
|
||||||
|
* This file is part of Vanilla Music Player.
|
||||||
|
*
|
||||||
|
* Vanilla Music Player is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Library General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Vanilla Music Player is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.kreed.vanilla;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.MediaStore;
|
||||||
|
|
||||||
|
public class SongMediaAdapter extends MediaAdapter {
|
||||||
|
public SongMediaAdapter(Context context)
|
||||||
|
{
|
||||||
|
super(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, SONG_FIELDS, SONG_FIELD_KEYS, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getDefaultSelection()
|
||||||
|
{
|
||||||
|
return MediaStore.Audio.Media.IS_MUSIC + "!=0";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getSortOrder()
|
||||||
|
{
|
||||||
|
if (getLimiter() != null && getLimiter().length == 2)
|
||||||
|
return null; // use default sort order (by track)
|
||||||
|
return super.getSortOrder();
|
||||||
|
}
|
||||||
|
}
|
@ -71,12 +71,12 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
return (MediaAdapter)getList(tab).getAdapter();
|
return (MediaAdapter)getList(tab).getAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeList(int id, Uri store, String[] fields, String[] fieldKeys, View.OnClickListener expanderListener, String selection)
|
private void initializeList(int id, Uri store, String[] fields, String[] fieldKeys, View.OnClickListener expanderListener)
|
||||||
{
|
{
|
||||||
ListView view = (ListView)findViewById(id);
|
ListView view = (ListView)findViewById(id);
|
||||||
view.setOnItemClickListener(this);
|
view.setOnItemClickListener(this);
|
||||||
view.setOnCreateContextMenuListener(this);
|
view.setOnCreateContextMenuListener(this);
|
||||||
view.setAdapter(new MediaAdapter(getContext(), store, fields, fieldKeys, expanderListener, selection));
|
view.setAdapter(new MediaAdapter(getContext(), store, fields, fieldKeys, expanderListener));
|
||||||
}
|
}
|
||||||
|
|
||||||
public SongSelector(Context context)
|
public SongSelector(Context context)
|
||||||
@ -109,9 +109,13 @@ public class SongSelector extends Dialog implements AdapterView.OnItemClickListe
|
|||||||
new Handler().post(new Runnable() {
|
new Handler().post(new Runnable() {
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
initializeList(R.id.artist_list, MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, MediaAdapter.ARTIST_FIELDS, MediaAdapter.ARTIST_FIELD_KEYS, SongSelector.this, null);
|
initializeList(R.id.artist_list, MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, MediaAdapter.ARTIST_FIELDS, MediaAdapter.ARTIST_FIELD_KEYS, SongSelector.this);
|
||||||
initializeList(R.id.album_list, MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, MediaAdapter.ALBUM_FIELDS, MediaAdapter.ALBUM_FIELD_KEYS,SongSelector.this, null);
|
initializeList(R.id.album_list, MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, MediaAdapter.ALBUM_FIELDS, MediaAdapter.ALBUM_FIELD_KEYS,SongSelector.this);
|
||||||
initializeList(R.id.song_list, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, MediaAdapter.SONG_FIELDS, MediaAdapter.SONG_FIELD_KEYS, null, MediaStore.Audio.Media.IS_MUSIC + "!=0");
|
|
||||||
|
ListView view = (ListView)findViewById(R.id.song_list);
|
||||||
|
view.setOnItemClickListener(SongSelector.this);
|
||||||
|
view.setOnCreateContextMenuListener(SongSelector.this);
|
||||||
|
view.setAdapter(new SongMediaAdapter(getContext()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user