/**
  * @return If current {@link Playlist} is empty or null, return 1. If current {@link Playlist} is
  *     repeating, return FAKE_INFINITY_COUNT. Else return the current {@link Playlist}'s length.
  */
 @Override
 public int getCount() {
   if (mPlaylist == null || mPlaylist.getCount() == 0) {
     return 1;
   }
   if (mPlaylist.isRepeating()) {
     return FAKE_INFINITY_COUNT;
   }
   return mPlaylist.getCount();
 }
 /**
  * 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);
   }
 }
示例#3
0
 public void fillView(Playlist playlist) {
   if (findViewById(R.id.imageview_create_playlist) != null) {
     findViewById(R.id.imageview_create_playlist).setVisibility(View.GONE);
   }
   ArrayList<Image> artistImages = new ArrayList<>();
   String topArtistsString = "";
   String[] artists = playlist.getTopArtistNames();
   if (artists != null) {
     for (int i = 0; i < artists.length && i < 5 && artistImages.size() < 3; i++) {
       Artist artist = Artist.get(artists[i]);
       topArtistsString += artists[i];
       if (i != artists.length - 1) {
         topArtistsString += ", ";
       }
       if (artist.getImage() != null) {
         artistImages.add(artist.getImage());
       }
     }
   }
   fillView(mRootView, artistImages, 0, false);
   TextView textView1 = (TextView) findViewById(R.id.textview1);
   if (textView1 != null) {
     textView1.setText(playlist.getName());
   }
   TextView textView2 = (TextView) findViewById(R.id.textview2);
   if (textView2 != null) {
     textView2.setText(topArtistsString);
     textView2.setVisibility(View.VISIBLE);
   }
   TextView textView3 = (TextView) findViewById(R.id.textview3);
   if (textView3 != null) {
     textView3.setVisibility(View.VISIBLE);
     textView3.setText(
         TomahawkApp.getContext()
             .getResources()
             .getQuantityString(
                 R.plurals.songs_with_count, (int) playlist.getCount(), playlist.getCount()));
   }
 }
 /**
  * Instantiate an item in the {@link PagerAdapter}. Fill it async with the correct AlbumArt image.
  */
 @Override
 public Object instantiateItem(View collection, int position) {
   ImageView albumArtImageView = new ImageView(mContext);
   if (mPlaylist != null && mPlaylist.getCount() > 0) {
     if (mPlaylist.isRepeating()
         && mPlaylist.peekTrackAtPos((position) % mPlaylist.getCount()).getAlbum() != null) {
       mPlaylist
           .peekTrackAtPos((position) % mPlaylist.getCount())
           .getAlbum()
           .loadBitmap(mContext, albumArtImageView);
     } else if (!mPlaylist.isRepeating()
         && mPlaylist.peekTrackAtPos(position).getAlbum() != null) {
       mPlaylist.peekTrackAtPos(position).getAlbum().loadBitmap(mContext, albumArtImageView);
     } else {
       albumArtImageView.setImageResource(R.drawable.no_album_art_placeholder);
     }
   } else {
     albumArtImageView.setImageResource(R.drawable.no_album_art_placeholder);
   }
   ((ViewPager) collection).addView(albumArtImageView);
   return albumArtImageView;
 }
 /**
  * @param position to set the current item to
  * @param smoothScroll boolean to determine whether or not to show a scrolling animation
  */
 public void setCurrentItem(int position, boolean smoothScroll) {
   if (position != mCurrentViewPage) {
     if (mPlaylist.isRepeating()) {
       if (position == (mCurrentViewPage % mPlaylist.getCount()) + 1
           || ((mCurrentViewPage % mPlaylist.getCount()) == mPlaylist.getCount() - 1
               && position == 0)) {
         setCurrentToNextItem(smoothScroll);
       } else if (position == (mCurrentViewPage % mPlaylist.getCount()) - 1
           || ((mCurrentViewPage % mPlaylist.getCount()) == 0
               && position == mPlaylist.getCount() - 1)) {
         setCurrentToPreviousItem(smoothScroll);
       } else {
         mViewPager.setCurrentItem(position, false);
       }
     } else {
       mViewPager.setCurrentItem(position, smoothScroll);
     }
     mCurrentViewPage = mViewPager.getCurrentItem();
   }
 }