deprecate LazyCoverView.setup

We are now creating our own worker thread
This commit is contained in:
Adrian Ulrich 2015-10-16 09:33:50 +02:00
parent 617eb9e23b
commit f2d7cfda02
7 changed files with 19 additions and 36 deletions

View File

@ -25,6 +25,7 @@ import android.graphics.drawable.TransitionDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
@ -95,15 +96,6 @@ public class LazyCoverView extends ImageView
public LazyCoverView(Context context, AttributeSet attributes) {
super(context, attributes);
mContext = context;
}
/**
* Setup the handler of this view instance. This function
* must be called before calling setCover().
*
* @param looper The worker thread to use for image scaling
*/
public void setup(Looper looper) {
if (sCoverCache == null) {
sCoverCache = new CoverCache(mContext);
}
@ -113,11 +105,13 @@ public class LazyCoverView extends ImageView
if (sUiHandler == null) {
sUiHandler = new Handler(this);
}
if (sHandler == null || sHandler.getLooper().equals(looper) == false) {
sHandler = new Handler(looper, this);
if (sHandler == null) {
HandlerThread thread = new HandlerThread("LazyCoverRpc");
thread.start();
sHandler = new Handler(thread.getLooper(), this);
}
}
}
/**
* mHandler and mUiHandler callbacks

View File

@ -307,30 +307,29 @@ public class LibraryPagerAdapter
LayoutInflater inflater = activity.getLayoutInflater();
LibraryAdapter adapter;
LinearLayout header = null;
Looper looper = mWorkerHandler.getLooper();
switch (type) {
case MediaUtils.TYPE_ARTIST:
adapter = mArtistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ARTIST, null, activity, looper);
adapter = mArtistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ARTIST, null, activity);
mArtistAdapter.setExpandable(mSongsPosition != -1 || mAlbumsPosition != -1);
mArtistHeader = header = (LinearLayout)inflater.inflate(R.layout.library_row_expandable, null);
break;
case MediaUtils.TYPE_ALBUM:
adapter = mAlbumAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ALBUM, mPendingAlbumLimiter, activity, looper);
adapter = mAlbumAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ALBUM, mPendingAlbumLimiter, activity);
mAlbumAdapter.setExpandable(mSongsPosition != -1);
mPendingAlbumLimiter = null;
mAlbumHeader = header = (LinearLayout)inflater.inflate(R.layout.library_row_expandable, null);
break;
case MediaUtils.TYPE_SONG:
adapter = mSongAdapter = new MediaAdapter(activity, MediaUtils.TYPE_SONG, mPendingSongLimiter, activity, looper);
adapter = mSongAdapter = new MediaAdapter(activity, MediaUtils.TYPE_SONG, mPendingSongLimiter, activity);
mPendingSongLimiter = null;
mSongHeader = header = (LinearLayout)inflater.inflate(R.layout.library_row_expandable, null);
break;
case MediaUtils.TYPE_PLAYLIST:
adapter = mPlaylistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_PLAYLIST, null, activity, looper);
adapter = mPlaylistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_PLAYLIST, null, activity);
break;
case MediaUtils.TYPE_GENRE:
adapter = mGenreAdapter = new MediaAdapter(activity, MediaUtils.TYPE_GENRE, null, activity, looper);
adapter = mGenreAdapter = new MediaAdapter(activity, MediaUtils.TYPE_GENRE, null, activity);
mGenreAdapter.setExpandable(mSongsPosition != -1);
break;
case MediaUtils.TYPE_FILE:

View File

@ -29,7 +29,6 @@ import android.database.Cursor;
import android.database.DatabaseUtils;
import android.graphics.Color;
import android.net.Uri;
import android.os.Looper;
import android.provider.BaseColumns;
import android.provider.MediaStore;
import android.text.Spannable;
@ -82,7 +81,6 @@ public class MediaAdapter
* The current data.
*/
private Cursor mCursor;
private Looper mLooper;
/**
* The type of media represented by this adapter. Must be one of the
* MediaUtils.FIELD_* constants. Determines which content provider to query for
@ -157,16 +155,14 @@ public class MediaAdapter
* and what fields to display in the views.
* @param limiter An initial limiter to use
* @param activity The LibraryActivity that will contain this adapter - may be null
* @param looper The looper to use for image processing - may be null
*
*/
public MediaAdapter(Context context, int type, Limiter limiter, LibraryActivity activity, Looper looper)
public MediaAdapter(Context context, int type, Limiter limiter, LibraryActivity activity)
{
mContext = context;
mActivity = activity;
mType = type;
mLimiter = limiter;
mLooper = looper;
if (mActivity != null) {
mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@ -490,7 +486,6 @@ public class MediaAdapter
holder.divider.setVisibility(mExpandable ? View.VISIBLE : View.GONE);
holder.arrow.setVisibility(mExpandable ? View.VISIBLE : View.GONE);
holder.cover.setVisibility(mCoverCacheType != MediaUtils.TYPE_INVALID ? View.VISIBLE : View.GONE);
holder.cover.setup(mLooper);
} else {
holder = (ViewHolder)view.getTag();
}

View File

@ -99,11 +99,11 @@ public class MirrorLinkMediaBrowserService extends MediaBrowserService implement
thread.start();
// Prep the Media Adapters (caches the top categories)
mArtistAdapter = new MediaAdapter(this, MediaUtils.TYPE_ARTIST, null ,null, null);
mAlbumAdapter = new MediaAdapter(this, MediaUtils.TYPE_ALBUM, null, null, null);
mSongAdapter = new MediaAdapter(this, MediaUtils.TYPE_SONG, null, null, null);
mPlaylistAdapter = new MediaAdapter(this, MediaUtils.TYPE_PLAYLIST, null, null, null);
mGenreAdapter = new MediaAdapter(this, MediaUtils.TYPE_GENRE, null, null, null);
mArtistAdapter = new MediaAdapter(this, MediaUtils.TYPE_ARTIST, null ,null);
mAlbumAdapter = new MediaAdapter(this, MediaUtils.TYPE_ALBUM, null, null);
mSongAdapter = new MediaAdapter(this, MediaUtils.TYPE_SONG, null, null);
mPlaylistAdapter = new MediaAdapter(this, MediaUtils.TYPE_PLAYLIST, null, null);
mGenreAdapter = new MediaAdapter(this, MediaUtils.TYPE_GENRE, null, null);
mMediaAdapters[MediaUtils.TYPE_ARTIST] = mArtistAdapter;
mMediaAdapters[MediaUtils.TYPE_ALBUM] = mAlbumAdapter;
mMediaAdapters[MediaUtils.TYPE_SONG] = mSongAdapter;

View File

@ -116,7 +116,6 @@ public class PlaylistAdapter extends CursorAdapter implements Handler.Callback {
textView.setTag(cursor.getLong(3));
LazyCoverView cover = dview.getCoverView();
cover.setup(mWorkerHandler.getLooper());
cover.setCover(MediaUtils.TYPE_ALBUM, cursor.getLong(4));
}

View File

@ -51,7 +51,7 @@ public class ShowQueueActivity extends PlaybackActivity
mService = PlaybackService.get(this);
mListView = (DragSortListView) findViewById(R.id.list);
listAdapter = new ShowQueueAdapter(this, R.layout.draggable_row, mHandler.getLooper());
listAdapter = new ShowQueueAdapter(this, R.layout.draggable_row);
mListView.setAdapter(listAdapter);
mListView.setDropListener(this);
mListView.setRemoveListener(this);

View File

@ -19,7 +19,6 @@ package ch.blinkenlights.android.vanilla;
import android.content.Context;
import android.app.Activity;
import android.os.Looper;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
@ -39,13 +38,11 @@ public class ShowQueueAdapter
private int mResource;
private int mHighlightRow;
private Context mContext;
private Looper mLooper;
public ShowQueueAdapter(Context context, int resource, Looper looper) {
public ShowQueueAdapter(Context context, int resource) {
super(context, resource);
mResource = resource;
mContext = context;
mLooper = looper;
mHighlightRow = -1;
}
@ -68,7 +65,6 @@ public class ShowQueueAdapter
LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
row = (DraggableRow)inflater.inflate(mResource, parent, false);
row.setupLayout(DraggableRow.LAYOUT_COVERVIEW);
row.getCoverView().setup(mLooper);
}
Song song = getItem(position);