/** {@inheritDoc} */ @Override public void onScrollStateChanged(final AbsListView view, final int scrollState) { // Pause disk cache access to ensure smoother scrolling if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING || scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { mAdapter.setPauseDiskCache(true); } else { mAdapter.setPauseDiskCache(false); mAdapter.notifyDataSetChanged(); } }
/** * @return The position of an item in the list or grid based on the name of the currently playing * artist. */ private int getItemPositionByArtist() { final long artistId = MusicUtils.getCurrentArtistId(); if (mAdapter == null) { return 0; } for (int i = 0; i < mAdapter.getCount(); i++) { if (mAdapter.getItem(i).mArtistId == artistId) { return i; } } return 0; }
/** {@inheritDoc} */ @Override public void onCreateContextMenu( final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); // Get the position of the selected item final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; // Creat a new model mArtist = mAdapter.getItem(info.position); // Create a list of the artist's songs mArtistList = MusicUtils.getSongListForArtist(getActivity(), mArtist.mArtistId); // Play the artist menu.add( GROUP_ID, FragmentMenuItems.PLAY_SELECTION, Menu.NONE, getString(R.string.context_menu_play_selection)); // Add the artist to the queue menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_QUEUE, Menu.NONE, getString(R.string.add_to_queue)); // Add the artist to a playlist final SubMenu subMenu = menu.addSubMenu( GROUP_ID, FragmentMenuItems.ADD_TO_PLAYLIST, Menu.NONE, R.string.add_to_playlist); MusicUtils.makePlaylistMenu(getActivity(), GROUP_ID, subMenu, false); // Delete the artist menu.add( GROUP_ID, FragmentMenuItems.DELETE, Menu.NONE, getString(R.string.context_menu_delete)); }
/** Sets up the grid view */ private void initGridView() { // 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())) { if (isDetailedLayout()) { mAdapter.setLoadExtraData(true); mGridView.setNumColumns(TWO); } else { mGridView.setNumColumns(FOUR); } } else { if (isDetailedLayout()) { mAdapter.setLoadExtraData(true); mGridView.setNumColumns(ONE); } else { mGridView.setNumColumns(TWO); } } }
/** {@inheritDoc} */ @Override public void onLoadFinished(final Loader<List<Artist>> loader, final List<Artist> data) { // Check for any errors if (data.isEmpty()) { // Set the empty text final TextView empty = (TextView) mRootView.findViewById(R.id.empty); empty.setText(getString(R.string.empty_music)); if (isSimpleLayout()) { mListView.setEmptyView(empty); } else { mGridView.setEmptyView(empty); } return; } // Start fresh mAdapter.unload(); // Add the data to the adpater for (final Artist artist : data) { mAdapter.add(artist); } // Build the cache mAdapter.buildCache(); }
/** {@inheritDoc} */ @Override public void onLoaderReset(final Loader<List<Artist>> loader) { // Clear the data in the adapter mAdapter.unload(); }
/** {@inheritDoc} */ @Override public void onItemClick( final AdapterView<?> parent, final View view, final int position, final long id) { mArtist = mAdapter.getItem(position); NavUtils.openArtistProfile(getActivity(), mArtist.mArtistName); }
/** {@inheritDoc} */ @Override public void onPause() { super.onPause(); mAdapter.flush(); }