From e94c40bdcb502df28f93f30d5c6b98f97550751e Mon Sep 17 00:00:00 2001 From: Christopher Eby Date: Wed, 21 Sep 2011 16:26:41 -0500 Subject: [PATCH] Remove SongMediaAdapter --- src/org/kreed/vanilla/MediaAdapter.java | 50 ++++++----------- src/org/kreed/vanilla/SongMediaAdapter.java | 60 --------------------- src/org/kreed/vanilla/SongSelector.java | 2 +- 3 files changed, 18 insertions(+), 94 deletions(-) delete mode 100644 src/org/kreed/vanilla/SongMediaAdapter.java diff --git a/src/org/kreed/vanilla/MediaAdapter.java b/src/org/kreed/vanilla/MediaAdapter.java index d040f9e9..205ace43 100644 --- a/src/org/kreed/vanilla/MediaAdapter.java +++ b/src/org/kreed/vanilla/MediaAdapter.java @@ -179,30 +179,6 @@ public class MediaAdapter extends CursorAdapter implements SectionIndexer { mActivity.runQuery(this); } - /** - * A query selection that should always be a part of the query. By default, - * this returns null, meaning that no elements should be excluded. This - * method may be overridden in subclasses to exclude certain media from the - * adapter. - * - * @return The selection, formatted as an SQL WHERE clause or null to - * accept all media. - */ - protected String getDefaultSelection() - { - return null; - } - - /** - * Returns the sort order for queries. By default, sorts by the last field - * in mFields, using the field keys if available. - */ - protected String getSortOrder() - { - String[] source = mFieldKeys == null ? mFields : mFieldKeys; - return source[source.length - 1]; - } - /** * Query the backing content provider. Should be called on a background * thread. @@ -210,6 +186,10 @@ public class MediaAdapter extends CursorAdapter implements SectionIndexer { public void runQuery() { ContentResolver resolver = mActivity.getContentResolver(); + Cursor cursor; + + String constraint = mConstraint; + Limiter limiter = mLimiter; String[] projection; if (mFields.length == 1) @@ -220,11 +200,17 @@ public class MediaAdapter extends CursorAdapter implements SectionIndexer { StringBuilder selection = new StringBuilder(); String[] selectionArgs = null; - String defaultSelection = getDefaultSelection(); - if (defaultSelection != null) - selection.append(defaultSelection); + String sort; + if (mLimiter != null && mLimiter.type == MediaUtils.TYPE_ALBUM) + sort = MediaStore.Audio.Media.TRACK; + else if (mFieldKeys == null) + sort = mFields[mFields.length - 1]; + else + sort = mFieldKeys[mFieldKeys.length - 1]; + + if (mType == MediaUtils.TYPE_SONG) + selection.append("is_music!=0"); - String constraint = mConstraint; if (constraint != null && constraint.length() != 0) { String[] needles; @@ -260,20 +246,18 @@ public class MediaAdapter extends CursorAdapter implements SectionIndexer { } } - Cursor cursor; - - if (mLimiter != null && mLimiter.type == MediaUtils.TYPE_GENRE) { + if (limiter != null && limiter.type == MediaUtils.TYPE_GENRE) { // Genre is not standard metadata for MediaStore.Audio.Media. // We have to query it through a separate provider. : / cursor = MediaUtils.queryGenre(mActivity, mLimiter.id, projection, selection.toString(), selectionArgs); } else { - if (mLimiter != null) { + if (limiter != null) { if (selection.length() != 0) selection.append(" AND "); selection.append(mLimiter.selection); } - cursor = resolver.query(mStore, projection, selection.toString(), selectionArgs, getSortOrder()); + cursor = resolver.query(mStore, projection, selection.toString(), selectionArgs, sort); } mActivity.changeCursor(this, cursor); diff --git a/src/org/kreed/vanilla/SongMediaAdapter.java b/src/org/kreed/vanilla/SongMediaAdapter.java deleted file mode 100644 index faa8e333..00000000 --- a/src/org/kreed/vanilla/SongMediaAdapter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2010 Christopher Eby - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package org.kreed.vanilla; - -import android.provider.MediaStore; - -/** - * Subclasses MediaAdapter to represent songs. Providers some song-specific - * logic over plain MediaAdapter: exclusion of non-music media files and - * better sorting inside albums. - */ -public class SongMediaAdapter extends MediaAdapter { - /** - * Construct a MediaAdapter backed by MediaStore.Audio.Media. - * - * @param activity The activity that owns this adapter. - * @param expandable Whether an expander arrow should by shown to the right - * of views - * @param limiter An initial limiter to use. - */ - public SongMediaAdapter(SongSelector activity, boolean expandable, MediaAdapter.Limiter limiter) - { - super(activity, MediaUtils.TYPE_SONG, expandable, limiter); - } - - @Override - protected String getDefaultSelection() - { - return MediaStore.Audio.Media.IS_MUSIC + "!=0"; - } - - @Override - protected String getSortOrder() - { - Limiter limiter = getLimiter(); - if (limiter != null && limiter.type == MediaUtils.TYPE_ALBUM) - return MediaStore.Audio.Media.TRACK; - return super.getSortOrder(); - } -} diff --git a/src/org/kreed/vanilla/SongSelector.java b/src/org/kreed/vanilla/SongSelector.java index db4e5175..8433821f 100644 --- a/src/org/kreed/vanilla/SongSelector.java +++ b/src/org/kreed/vanilla/SongSelector.java @@ -149,7 +149,7 @@ public class SongSelector extends PlaybackActivity implements AdapterView.OnItem mArtistAdapter = setupView(R.id.artist_list, new MediaAdapter(this, MediaUtils.TYPE_ARTIST, true, null)); mAlbumAdapter = setupView(R.id.album_list, new MediaAdapter(this, MediaUtils.TYPE_ALBUM, true, state == null ? null : (MediaAdapter.Limiter)state.getSerializable("limiter_albums"))); - mSongAdapter = setupView(R.id.song_list, new SongMediaAdapter(this, false, state == null ? null : (MediaAdapter.Limiter)state.getSerializable("limiter_songs"))); + mSongAdapter = setupView(R.id.song_list, new MediaAdapter(this, MediaUtils.TYPE_SONG, false, state == null ? null : (MediaAdapter.Limiter)state.getSerializable("limiter_songs"))); mPlaylistAdapter = setupView(R.id.playlist_list, new MediaAdapter(this, MediaUtils.TYPE_PLAYLIST, false, null)); mGenreAdapter = setupView(R.id.genre_list, new MediaAdapter(this, MediaUtils.TYPE_GENRE, true, state == null ? null : (MediaAdapter.Limiter)state.getSerializable("limiter_genres"))); mAdapters = new MediaAdapter[] { mArtistAdapter, mAlbumAdapter, mSongAdapter, mPlaylistAdapter, mGenreAdapter };