package com.cyngn.eleven.adapters;
+import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
+import com.cyngn.eleven.cache.ImageFetcher;
+import com.cyngn.eleven.model.Artist;
import com.cyngn.eleven.model.Song;
import com.cyngn.eleven.sectionadapter.SectionAdapter;
import com.cyngn.eleven.ui.MusicHolder;
import com.cyngn.eleven.ui.MusicHolder.DataHolder;
import com.cyngn.eleven.ui.fragments.QueueFragment;
import com.cyngn.eleven.ui.fragments.SongFragment;
+import com.cyngn.eleven.utils.ApolloUtils;
import com.cyngn.eleven.utils.MusicUtils;
import com.cyngn.eleven.widgets.PlayPauseProgressButton;
private final int mLayoutId;
/**
+ * Image cache and image fetcher
+ */
+ private final ImageFetcher mImageFetcher;
+
+ /**
* The index of the item that is currently playing
*/
private long mCurrentlyPlayingSongId = -1;
* @param context The {@link Context} to use.
* @param layoutId The resource Id of the view to inflate.
*/
- public SongAdapter(final Context context, final int layoutId) {
+ public SongAdapter(final Activity context, final int layoutId) {
super(context, 0);
// Get the layout Id
mLayoutId = layoutId;
+ // Initialize the cache & image fetcher
+ mImageFetcher = ApolloUtils.getImageFetcher(context);
}
/**
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(mLayoutId, parent, false);
holder = new MusicHolder(convertView);
- // Hide the third line of text
- holder.mLineThree.get().setVisibility(View.GONE);
convertView.setTag(holder);
} else {
holder = (MusicHolder)convertView.getTag();
// Set each song name (line one)
holder.mLineOne.get().setText(dataHolder.mLineOne);
- // Set the song duration (line one, right)
- holder.mLineOneRight.get().setText(dataHolder.mLineOneRight);
// Set the album name (line two)
holder.mLineTwo.get().setText(dataHolder.mLineTwo);
+ // Asynchronously load the artist image into the adapter
+ Song item = getItem(position);
+ if (item.mAlbumId >= 0) {
+ mImageFetcher.loadAlbumImage(item.mArtistName, item.mAlbumName, item.mAlbumId,
+ holder.mImage.get());
+ }
+
// padding doesn't apply to included layouts, so we need
// to wrap it in a container and show/hide with the container
PlayPauseProgressButton playPauseProgressButton = holder.mPlayPauseProgressButton.get();
}
/**
+ * @param pause True to temporarily pause the disk cache, false otherwise.
+ */
+ public void setPauseDiskCache(final boolean pause) {
+ if (mImageFetcher != null) {
+ mImageFetcher.setPauseDiskCache(pause);
+ }
+ }
+
+ /**
+ * @param artist The key used to find the cached artist to remove
+ */
+ public void removeFromCache(final Artist artist) {
+ if (mImageFetcher != null) {
+ mImageFetcher.removeFromCache(artist.mArtistName);
+ }
+ }
+
+ /**
* Method that unloads and clears the items in the adapter
*/
public void unload() {