diff options
-rw-r--r-- | res/layout/grid_base.xml | 7 | ||||
-rw-r--r-- | res/layout/grid_header.xml | 6 | ||||
-rw-r--r-- | res/layout/grid_items_normal.xml | 30 | ||||
-rw-r--r-- | res/values/colors.xml | 2 | ||||
-rw-r--r-- | res/values/dimens.xml | 8 | ||||
-rw-r--r-- | res/values/styles.xml | 2 | ||||
-rw-r--r-- | src/com/cyngn/eleven/adapters/AlbumAdapter.java | 149 | ||||
-rw-r--r-- | src/com/cyngn/eleven/ui/fragments/AlbumFragment.java | 28 |
8 files changed, 122 insertions, 110 deletions
diff --git a/res/layout/grid_base.xml b/res/layout/grid_base.xml index 446f901..112486b 100644 --- a/res/layout/grid_base.xml +++ b/res/layout/grid_base.xml @@ -17,10 +17,7 @@ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/grid_base_container" android:layout_width="match_parent" - android:layout_height="match_parent" - android:paddingLeft="@dimen/list_preferred_item_padding" - android:paddingRight="@dimen/list_preferred_item_padding" - android:paddingTop="@dimen/list_preferred_item_padding"> + android:layout_height="match_parent"> <include layout="@layout/loading_empty_container" /> @@ -29,6 +26,8 @@ android:id="@+id/grid_base" android:layout_width="match_parent" android:layout_height="match_parent" + android:paddingLeft="@dimen/list_outer_edge_padding" + android:paddingRight="@dimen/list_outer_edge_padding" android:cacheColorHint="@color/transparent" android:drawSelectorOnTop="true" android:fadingEdge="vertical" diff --git a/res/layout/grid_header.xml b/res/layout/grid_header.xml new file mode 100644 index 0000000..03b1bcc --- /dev/null +++ b/res/layout/grid_header.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="8dp"> + <!-- height should be list_outer_edge_padding - grid_item_vertical_spacing --> +</FrameLayout>
\ No newline at end of file diff --git a/res/layout/grid_items_normal.xml b/res/layout/grid_items_normal.xml index 91f9374..320a926 100644 --- a/res/layout/grid_items_normal.xml +++ b/res/layout/grid_items_normal.xml @@ -28,21 +28,26 @@ android:background="@drawable/cardcontainer" android:paddingLeft="@dimen/grid_item_padding_left" > - <TextView - android:id="@+id/line_one" - style="@style/ListItemMainText.Grid.Single" + <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_alignParentTop="true" - android:layout_toLeftOf="@+id/popup_menu_button"/> + android:orientation="vertical" + android:layout_centerVertical="true" + android:layout_toLeftOf="@+id/popup_menu_button"> - <TextView - android:id="@+id/line_two" - style="@style/ListItemSecondaryText.Grid.Single" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_below="@+id/line_one" - android:layout_toLeftOf="@id/popup_menu_button" /> + <TextView + android:id="@+id/line_one" + style="@style/ListItemMainText.Grid.Single" + android:paddingBottom="1dp" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + <TextView + android:id="@+id/line_two" + style="@style/ListItemSecondaryText.Grid.Single" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + </LinearLayout> <com.cyngn.eleven.widgets.PopupMenuButton android:id="@id/popup_menu_button" @@ -50,6 +55,7 @@ android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" + android:paddingRight="@dimen/grid_item_padding_right" android:src="@drawable/menu_button" /> </RelativeLayout> diff --git a/res/values/colors.xml b/res/values/colors.xml index 08a96aa..4c8b9c6 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -84,7 +84,7 @@ <color name="list_item_text_color">@color/default_text_color</color> <color name="list_item_text_color_light">@color/default_text_color_light</color> <color name="list_item_divider_color">#4c231f20</color> - <color name="grid_list_item_text_color">#cc231f20</color> + <color name="grid_list_item_text_color">#b3231f20</color> <!-- Top title page colors --> <color name="tpi_background_color">#fff4f4f4</color> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 82aea64..da8b015 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -33,6 +33,7 @@ <!-- List and grid view padding --> <dimen name="list_preferred_item_padding">10.0dip</dimen> + <dimen name="list_outer_edge_padding">16.0dp</dimen> <dimen name="list_menu_item_padding_right">2.0dip</dimen> <dimen name="list_item_general_margin">16.0dip</dimen> <dimen name="list_item_menu_button_width">24.0dip</dimen> @@ -50,16 +51,17 @@ <!-- List view fast scroll padding right --> <dimen name="fast_scroll_padding_right">8.0dip</dimen> <!-- grid view vertical and horizontal spacing --> - <dimen name="grid_item_horizontal_spacing">4.0dip</dimen> - <dimen name="grid_item_vertical_spacing">6.0dip</dimen> + <dimen name="grid_item_horizontal_spacing">8.0dip</dimen> + <dimen name="grid_item_vertical_spacing">8.0dip</dimen> <!-- List item detailed height --> <dimen name="list_item_detailed_height">120.0dip</dimen> <!-- Top margin of "line_two" --> <dimen name="list_item_line_two_margin_top">8.0dip</dimen> <!-- Left padding in the grid text --> <dimen name="grid_item_padding_left">8.0dip</dimen> + <dimen name="grid_item_padding_right">5.0dip</dimen> <!-- Left padding in the grid text --> - <dimen name="grid_bottom_height">40dip</dimen> + <dimen name="grid_bottom_height">44dip</dimen> <!-- Grid and list item normal height --> <dimen name="item_normal_height">70.0dip</dimen> <dimen name="item_short_height">60.0dip</dimen> diff --git a/res/values/styles.xml b/res/values/styles.xml index 4b4f0d3..1e51710 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -115,6 +115,7 @@ </style> <style name="ListItemMainText.Grid.Single" parent="ListItemMainText.Single"> + <item name="android:textSize">@dimen/text_size_micro</item> <item name="android:textColor">@color/grid_list_item_text_color</item> </style> @@ -132,6 +133,7 @@ </style> <style name="ListItemSecondaryText.Grid.Single" parent="ListItemSecondaryText.Single"> + <item name="android:textSize">@dimen/text_size_extra_micro</item> <item name="android:textColor">@color/grid_list_item_text_color</item> </style> diff --git a/src/com/cyngn/eleven/adapters/AlbumAdapter.java b/src/com/cyngn/eleven/adapters/AlbumAdapter.java index 9ab3aad..0d520d4 100644 --- a/src/com/cyngn/eleven/adapters/AlbumAdapter.java +++ b/src/com/cyngn/eleven/adapters/AlbumAdapter.java @@ -15,36 +15,35 @@ import android.app.Activity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; -import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.TextView; +import android.widget.BaseAdapter; -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.sectionadapter.SectionAdapter; 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; +import java.util.Collections; +import java.util.List; + /** * This {@link ArrayAdapter} is used to display all of the albums on a user's * device for {@link RecentsFragment} and {@link AlbumsFragment}. * * @author Andrew Neal (andrewdneal@gmail.com) */ -public class AlbumAdapter extends ArrayAdapter<Album> - implements SectionAdapter.BasicAdapter, IPopupMenuCallback { +public class AlbumAdapter extends BaseAdapter implements IPopupMenuCallback { /** * Number of views (ImageView and TextView) */ private static final int VIEW_TYPE_COUNT = 2; + private static final int VIEW_TYPE_HEADER = 0; + private static final int VIEW_TYPE_ITEM = 1; /** * The resource Id of the layout to inflate @@ -57,26 +56,22 @@ public class AlbumAdapter extends ArrayAdapter<Album> private final ImageFetcher mImageFetcher; /** - * Semi-transparent overlay - */ - private final int mOverlay; - - /** - * Sets the album art on click listener to start playing them album when - * touched. - */ - private boolean mTouchPlay = false; - - /** * Used to cache the album info */ - private DataHolder[] mData; + private DataHolder[] mData = new DataHolder[0]; + private List<Album> mAlbums = Collections.emptyList(); /** * Used to listen to the pop up menu callbacks */ private IPopupMenuCallback.IListener mListener; + /** number of columns of containing grid view, + * used to determine how many headers to show */ + private int mColumns; + + private Context mContext; + /** * Constructor of <code>AlbumAdapter</code> * @@ -86,13 +81,11 @@ public class AlbumAdapter extends ArrayAdapter<Album> * load. */ public AlbumAdapter(final Activity context, final int layoutId) { - super(context, 0); + mContext = context; // Get the layout Id mLayoutId = layoutId; // Initialize the cache & image fetcher mImageFetcher = ApolloUtils.getImageFetcher(context); - // Cache the transparent overlay - mOverlay = context.getResources().getColor(R.color.list_item_background); } /** @@ -100,10 +93,17 @@ public class AlbumAdapter extends ArrayAdapter<Album> */ @Override public View getView(final int position, View convertView, final ViewGroup parent) { + if(getItemViewType(position) == VIEW_TYPE_HEADER) { + if(convertView != null) { + return convertView; + } + return LayoutInflater.from(mContext).inflate(R.layout.grid_header, parent, false); + } + // Recycle ViewHolder's items MusicHolder holder; if (convertView == null) { - convertView = LayoutInflater.from(getContext()).inflate(mLayoutId, parent, false); + convertView = LayoutInflater.from(mContext).inflate(mLayoutId, parent, false); holder = new MusicHolder(convertView); convertView.setTag(holder); // set the pop up menu listener @@ -113,7 +113,7 @@ public class AlbumAdapter extends ArrayAdapter<Album> } // Retrieve the data holder - final DataHolder dataHolder = mData[position]; + final DataHolder dataHolder = mData[position - mColumns]; // Sets the position each time because of recycling holder.mPopupMenuButton.get().setPosition(position); @@ -125,10 +125,6 @@ public class AlbumAdapter extends ArrayAdapter<Album> mImageFetcher.loadAlbumImage(dataHolder.mLineTwo, dataHolder.mLineOne, dataHolder.mItemId, holder.mImage.get()); - if (mTouchPlay) { - // Play the album when the artwork is touched - playAlbum(holder.mImage.get(), position); - } return convertView; } @@ -148,52 +144,66 @@ public class AlbumAdapter extends ArrayAdapter<Album> return VIEW_TYPE_COUNT; } + @Override + public int getItemViewType(int position) { + if(position < mColumns) { + return VIEW_TYPE_HEADER; + } else { + return VIEW_TYPE_ITEM; + } + } + + @Override + public boolean isEnabled(int position) { + return getItemViewType(position) == VIEW_TYPE_ITEM; + } + + @Override + public int getCount() { + return mAlbums.size() + mColumns; // data items plus headers + } + + @Override + public Album getItem(int pos) { + if(pos < mColumns) { + return null; // header position + } else { + return mAlbums.get(pos - mColumns); + } + } + + @Override + public long getItemId(int pos) { return pos; } + /** * Method used to cache the data used to populate the list or grid. The idea * is to cache everything before {@code #getView(int, View, ViewGroup)} is * called. */ public void buildCache() { - mData = new DataHolder[getCount()]; - for (int i = 0; i < getCount(); i++) { - // Build the album - final Album album = getItem(i); - - // Build the data holder + mData = new DataHolder[mAlbums.size()]; + int i = 0; + for (Album album : mAlbums) { mData[i] = new DataHolder(); - // Album Id mData[i].mItemId = album.mAlbumId; - // Album names (line one) mData[i].mLineOne = album.mAlbumName; - // Album artist names (line two) mData[i].mLineTwo = album.mArtistName; + i++; } } - /** - * Starts playing an album if the user touches the artwork in the list. - * - * @param album The {@link ImageView} holding the album - * @param position The position of the album to play. - */ - private void playAlbum(final ImageView album, final int position) { - album.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(final View v) { - final long id = getItem(position).mAlbumId; - final long[] list = MusicUtils.getSongListForAlbum(getContext(), id); - MusicUtils.playAll(getContext(), list, 0, id, Config.IdType.Album, false); - } - }); + public void setData(List<Album> albums) { + mAlbums = albums; + buildCache(); + notifyDataSetChanged(); + } + + public void setNumColumns(int columns) { + mColumns = columns; } - /** - * Method that unloads and clears the items in the adapter - */ public void unload() { - clear(); - mData = null; + setData(Collections.<Album>emptyList()); } /** @@ -227,27 +237,20 @@ public class AlbumAdapter extends ArrayAdapter<Album> * @param id identifies the object * @return the position if found, -1 otherwise */ - @Override public int getItemPosition(long id) { - for (int i = 0; i < getCount(); i++) { - if (getItem(i).mAlbumId == id) { - return i; + int i = 0; + for (Album album : mAlbums) { + if (album.mAlbumId == id) { + return mColumns + i; } + i++; } - return -1; - } - - /** - * @param play True to play the album when the artwork is touched, false - * otherwise. - */ - public void setTouchPlay(final boolean play) { - mTouchPlay = play; + return -1; } @Override public void setPopupMenuClickedListener(IPopupMenuCallback.IListener listener) { mListener = listener; } -} +}
\ No newline at end of file diff --git a/src/com/cyngn/eleven/ui/fragments/AlbumFragment.java b/src/com/cyngn/eleven/ui/fragments/AlbumFragment.java index cbb148d..5fd40ef 100644 --- a/src/com/cyngn/eleven/ui/fragments/AlbumFragment.java +++ b/src/com/cyngn/eleven/ui/fragments/AlbumFragment.java @@ -31,7 +31,6 @@ import com.cyngn.eleven.adapters.PagerAdapter; import com.cyngn.eleven.loaders.AlbumLoader; import com.cyngn.eleven.model.Album; import com.cyngn.eleven.recycler.RecycleHolder; -import com.cyngn.eleven.sectionadapter.SectionAdapter; import com.cyngn.eleven.sectionadapter.SectionCreator; import com.cyngn.eleven.sectionadapter.SectionListContainer; import com.cyngn.eleven.ui.activities.BaseActivity; @@ -43,7 +42,6 @@ import com.cyngn.eleven.utils.NavUtils; import com.cyngn.eleven.utils.PopupMenuHelper; import com.cyngn.eleven.widgets.IPopupMenuCallback; import com.cyngn.eleven.widgets.LoadingEmptyContainer; -import com.cyngn.eleven.widgets.NoResultsContainer; import com.viewpagerindicator.TitlePageIndicator; /** @@ -58,7 +56,7 @@ public class AlbumFragment extends MusicBrowserFragment implements /** * Grid view column count. ONE - list, TWO - normal grid, FOUR - landscape */ - private static final int ONE = 1, TWO = 2, FOUR = 4; + private static final int TWO = 2, FOUR = 4; /** * Fragment UI @@ -68,7 +66,7 @@ public class AlbumFragment extends MusicBrowserFragment implements /** * The adapter for the grid */ - private SectionAdapter<Album, AlbumAdapter> mAdapter; + private AlbumAdapter mAdapter; /** * The grid view @@ -99,14 +97,13 @@ public class AlbumFragment extends MusicBrowserFragment implements mPopupMenuHelper = new AlbumPopupMenuHelper(getActivity(), getFragmentManager()) { public Album getAlbum(int position) { - return mAdapter.getTItem(position); + return mAdapter.getItem(position); } }; int layout = R.layout.grid_items_normal; - AlbumAdapter adapter = new AlbumAdapter(getActivity(), layout); - mAdapter = new SectionAdapter<Album, AlbumAdapter>(getActivity(), adapter); + mAdapter = new AlbumAdapter(getActivity(), layout); mAdapter.setPopupMenuClickedListener(new IPopupMenuCallback.IListener() { @Override public void onPopupMenuClicked(View v, int position) { @@ -167,9 +164,9 @@ public class AlbumFragment extends MusicBrowserFragment implements // Pause disk cache access to ensure smoother scrolling if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING || scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { - mAdapter.getUnderlyingAdapter().setPauseDiskCache(true); + mAdapter.setPauseDiskCache(true); } else { - mAdapter.getUnderlyingAdapter().setPauseDiskCache(false); + mAdapter.setPauseDiskCache(false); mAdapter.notifyDataSetChanged(); } } @@ -180,7 +177,7 @@ public class AlbumFragment extends MusicBrowserFragment implements @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { - Album album = mAdapter.getTItem(position); + Album album = mAdapter.getItem(position); NavUtils.openAlbumProfile(getActivity(), album.mAlbumName, album.mArtistName, album.mAlbumId); } @@ -207,8 +204,7 @@ public class AlbumFragment extends MusicBrowserFragment implements return; } - // Set the data - mAdapter.setData(data); + mAdapter.setData(data.mListResults); } /** @@ -310,17 +306,15 @@ public class AlbumFragment extends MusicBrowserFragment implements * Sets up the grid view */ private void initGridView() { + int columns = ApolloUtils.isLandscape(getActivity()) ? FOUR : TWO; + mAdapter.setNumColumns(columns); // Initialize the grid mGridView = (GridView)mRootView.findViewById(R.id.grid_base); // Set the data behind the grid mGridView.setAdapter(mAdapter); // Set up the helpers initAbsListView(mGridView); - if (ApolloUtils.isLandscape(getActivity())) { - mGridView.setNumColumns(FOUR); - } else { - mGridView.setNumColumns(TWO); - } + mGridView.setNumColumns(columns); // Show progress bar mLoadingEmptyContainer = (LoadingEmptyContainer)mRootView.findViewById(R.id.loading_empty_container); |