/**
  * Is being called, whenever a new Page in our {@link AlbumArtSwipeAdapter} has been selected/
  * swiped to
  */
 @Override
 public void onPageSelected(int arg0) {
   if (mPlaybackService != null && isByUser()) {
     setSwiped(true);
     if (arg0 == mCurrentViewPage - 1) {
       mPlaybackService.previous();
     } else if (arg0 == mCurrentViewPage + 1) {
       mPlaybackService.next();
     }
   }
   mCurrentViewPage = arg0;
 }
예제 #2
0
 /**
  * Called every time an item inside the {@link
  * se.emilsjolander.stickylistheaders.StickyListHeadersListView} is clicked
  *
  * @param parent The AdapterView where the click happened.
  * @param view The view within the AdapterView that was clicked (this will be a view provided by
  *     the adapter)
  * @param position The position of the view in the adapter.
  * @param id The row id of the item that was clicked.
  */
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   Object item;
   TomahawkMainActivity activity = (TomahawkMainActivity) getActivity();
   if (!isShowGridView()) {
     item = getListAdapter().getItem(position);
   } else {
     item = getGridAdapter().getItem(position);
   }
   if (item instanceof Query && ((Query) item).isPlayable()) {
     PlaybackService playbackService = activity.getPlaybackService();
     if (playbackService != null
         && shouldShowPlaystate()
         && mQueryPositions.get(playbackService.getCurrentPlaylist().getCurrentQueryIndex())
             == position) {
       playbackService.playPause();
     } else {
       UserPlaylist playlist =
           UserPlaylist.fromQueryList(
               TomahawkMainActivity.getLifetimeUniqueStringId(),
               "",
               mShownQueries,
               mQueryPositions.keyAt(mQueryPositions.indexOfValue(position)));
       if (playbackService != null) {
         playbackService.setCurrentPlaylist(playlist);
         playbackService.start();
       }
     }
   } else if (item instanceof Album) {
     FragmentUtils.replace(
         getActivity(),
         getActivity().getSupportFragmentManager(),
         TracksFragment.class,
         ((Album) item).getCacheKey(),
         TomahawkFragment.TOMAHAWK_ALBUM_KEY,
         mIsLocal);
   }
 }
 /**
  * update the {@link Playlist} of the {@link AlbumArtSwipeAdapter} to the given {@link Playlist}
  */
 public void updatePlaylist() {
   if (mPlaybackService != null) {
     mPlaylist = mPlaybackService.getCurrentPlaylist();
     notifyDataSetChanged();
   }
   if (mPlaylist != null && mPlaylist.getCount() > 0) {
     mFakeInfinityOffset =
         mPlaylist.getCount() * ((FAKE_INFINITY_COUNT / 2) / mPlaylist.getCount());
     setByUser(false);
     if (mPlaylist.isRepeating()) {
       setCurrentItem(mPlaylist.getCurrentTrackIndex() + getFakeInfinityOffset(), false);
     } else {
       setCurrentItem(mPlaylist.getCurrentTrackIndex(), false);
     }
     setByUser(true);
   }
 }