OSDN Git Service

Eleven: Add song indicators, change ProfileSongAdapter to use SongAdapter
[android-x86/packages-apps-Eleven.git] / src / com / cyngn / eleven / adapters / AlbumAdapter.java
index 517d270..9ab3aad 100644 (file)
@@ -19,7 +19,9 @@ import android.view.View.OnClickListener;
 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;
@@ -28,6 +30,7 @@ import com.cyngn.eleven.ui.MusicHolder;
 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
@@ -35,7 +38,8 @@ import com.cyngn.eleven.utils.MusicUtils;
  * 
  * @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)
@@ -58,11 +62,6 @@ public class AlbumAdapter extends ArrayAdapter<Album> implements SectionAdapter.
     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.
      */
@@ -74,6 +73,11 @@ public class AlbumAdapter extends ArrayAdapter<Album> implements SectionAdapter.
     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.
@@ -102,6 +106,8 @@ public class AlbumAdapter extends ArrayAdapter<Album> implements SectionAdapter.
             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();
         }
@@ -109,6 +115,8 @@ public class AlbumAdapter extends ArrayAdapter<Album> implements SectionAdapter.
         // 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)
@@ -116,15 +124,7 @@ public class AlbumAdapter extends ArrayAdapter<Album> implements SectionAdapter.
         // 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);
@@ -167,9 +167,6 @@ public class AlbumAdapter extends ArrayAdapter<Album> implements SectionAdapter.
             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);
         }
     }
 
@@ -186,7 +183,7 @@ public class AlbumAdapter extends ArrayAdapter<Album> implements SectionAdapter.
             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);
             }
         });
     }
@@ -242,19 +239,15 @@ public class AlbumAdapter extends ArrayAdapter<Album> implements SectionAdapter.
     }
 
     /**
-     * @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;
+    }
 }