import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
+import android.widget.TextView;
+import com.cyngn.eleven.Config;
import com.cyngn.eleven.R;
import com.cyngn.eleven.cache.ImageFetcher;
import com.cyngn.eleven.model.Album;
import com.cyngn.eleven.ui.MusicHolder.DataHolder;
import com.cyngn.eleven.utils.ApolloUtils;
import com.cyngn.eleven.utils.MusicUtils;
+import com.cyngn.eleven.widgets.IPopupMenuCallback;
/**
* This {@link ArrayAdapter} is used to display all of the albums on a user's
*
* @author Andrew Neal (andrewdneal@gmail.com)
*/
-public class AlbumAdapter extends ArrayAdapter<Album> implements SectionAdapter.BasicAdapter {
+public class AlbumAdapter extends ArrayAdapter<Album>
+ implements SectionAdapter.BasicAdapter, IPopupMenuCallback {
/**
* Number of views (ImageView and TextView)
private final int mOverlay;
/**
- * Determines if the grid or list should be the default style
- */
- private boolean mLoadExtraData = false;
-
- /**
* Sets the album art on click listener to start playing them album when
* touched.
*/
private DataHolder[] mData;
/**
+ * Used to listen to the pop up menu callbacks
+ */
+ private IPopupMenuCallback.IListener mListener;
+
+ /**
* Constructor of <code>AlbumAdapter</code>
*
* @param context The {@link Context} to use.
convertView = LayoutInflater.from(getContext()).inflate(mLayoutId, parent, false);
holder = new MusicHolder(convertView);
convertView.setTag(holder);
+ // set the pop up menu listener
+ holder.mPopupMenuButton.get().setPopupMenuClickedListener(mListener);
} else {
holder = (MusicHolder)convertView.getTag();
}
// Retrieve the data holder
final DataHolder dataHolder = mData[position];
+ // Sets the position each time because of recycling
+ holder.mPopupMenuButton.get().setPosition(position);
// Set each album name (line one)
holder.mLineOne.get().setText(dataHolder.mLineOne);
// Set the artist name (line two)
// Asynchronously load the album images into the adapter
mImageFetcher.loadAlbumImage(dataHolder.mLineTwo, dataHolder.mLineOne, dataHolder.mItemId,
holder.mImage.get());
- // List view only items
- if (mLoadExtraData) {
- // Make sure the background layer gets set
- holder.mOverlay.get().setBackgroundColor(mOverlay);
- // Set the number of songs (line three)
- holder.mLineThree.get().setText(dataHolder.mLineThree);
- // Asynchronously load the artist image on the background view
- mImageFetcher.loadArtistImage(dataHolder.mLineTwo, holder.mBackground.get());
- }
+
if (mTouchPlay) {
// Play the album when the artwork is touched
playAlbum(holder.mImage.get(), position);
mData[i].mLineOne = album.mAlbumName;
// Album artist names (line two)
mData[i].mLineTwo = album.mArtistName;
- // Number of songs for each album (line three)
- mData[i].mLineThree = MusicUtils.makeLabel(getContext(),
- R.plurals.Nsongs, album.mSongNumber);
}
}
public void onClick(final View v) {
final long id = getItem(position).mAlbumId;
final long[] list = MusicUtils.getSongListForAlbum(getContext(), id);
- MusicUtils.playAll(getContext(), list, 0, false);
+ MusicUtils.playAll(getContext(), list, 0, id, Config.IdType.Album, false);
}
});
}
}
/**
- * @param extra True to load line three and the background image, false
- * otherwise.
- */
- public void setLoadExtraData(final boolean extra) {
- mLoadExtraData = extra;
- setTouchPlay(true);
- }
-
- /**
* @param play True to play the album when the artwork is touched, false
* otherwise.
*/
public void setTouchPlay(final boolean play) {
mTouchPlay = play;
}
+
+ @Override
+ public void setPopupMenuClickedListener(IPopupMenuCallback.IListener listener) {
+ mListener = listener;
+ }
}