Search in sources :

Example 1 with Album

use of com.naman14.timber.models.Album in project Timber by naman14.

the class AlbumAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ItemHolder itemHolder, int i) {
    Album localItem = arraylist.get(i);
    itemHolder.title.setText(localItem.title);
    itemHolder.artist.setText(localItem.artistName);
    ImageLoader.getInstance().displayImage(TimberUtils.getAlbumArtUri(localItem.id).toString(), itemHolder.albumArt, new DisplayImageOptions.Builder().cacheInMemory(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).displayer(new FadeInBitmapDisplayer(400)).build(), new SimpleImageLoadingListener() {

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            if (isGrid) {
                new Palette.Builder(loadedImage).generate(new Palette.PaletteAsyncListener() {

                    @Override
                    public void onGenerated(Palette palette) {
                        Palette.Swatch swatch = palette.getVibrantSwatch();
                        if (swatch != null) {
                            int color = swatch.getRgb();
                            itemHolder.footer.setBackgroundColor(color);
                            int textColor = TimberUtils.getBlackWhiteColor(swatch.getTitleTextColor());
                            itemHolder.title.setTextColor(textColor);
                            itemHolder.artist.setTextColor(textColor);
                        } else {
                            Palette.Swatch mutedSwatch = palette.getMutedSwatch();
                            if (mutedSwatch != null) {
                                int color = mutedSwatch.getRgb();
                                itemHolder.footer.setBackgroundColor(color);
                                int textColor = TimberUtils.getBlackWhiteColor(mutedSwatch.getTitleTextColor());
                                itemHolder.title.setTextColor(textColor);
                                itemHolder.artist.setTextColor(textColor);
                            }
                        }
                    }
                });
            }
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            if (isGrid) {
                itemHolder.footer.setBackgroundColor(0);
                if (mContext != null) {
                    int textColorPrimary = Config.textColorPrimary(mContext, Helpers.getATEKey(mContext));
                    itemHolder.title.setTextColor(textColorPrimary);
                    itemHolder.artist.setTextColor(textColorPrimary);
                }
            }
        }
    });
    if (TimberUtils.isLollipop())
        itemHolder.albumArt.setTransitionName("transition_album_art" + i);
}
Also used : Palette(android.support.v7.graphics.Palette) Album(com.naman14.timber.models.Album) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Bitmap(android.graphics.Bitmap) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)

Example 2 with Album

use of com.naman14.timber.models.Album in project Timber by naman14.

the class SearchAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ItemHolder itemHolder, int i) {
    switch(getItemViewType(i)) {
        case 0:
            Song song = (Song) searchResults.get(i);
            itemHolder.title.setText(song.title);
            itemHolder.songartist.setText(song.albumName);
            ImageLoader.getInstance().displayImage(TimberUtils.getAlbumArtUri(song.albumId).toString(), itemHolder.albumArt, new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).displayer(new FadeInBitmapDisplayer(400)).build());
            setOnPopupMenuListener(itemHolder, i);
            break;
        case 1:
            Album album = (Album) searchResults.get(i);
            itemHolder.albumtitle.setText(album.title);
            itemHolder.albumartist.setText(album.artistName);
            ImageLoader.getInstance().displayImage(TimberUtils.getAlbumArtUri(album.id).toString(), itemHolder.albumArt, new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).displayer(new FadeInBitmapDisplayer(400)).build());
            break;
        case 2:
            Artist artist = (Artist) searchResults.get(i);
            itemHolder.artisttitle.setText(artist.name);
            String albumNmber = TimberUtils.makeLabel(mContext, R.plurals.Nalbums, artist.albumCount);
            String songCount = TimberUtils.makeLabel(mContext, R.plurals.Nsongs, artist.songCount);
            itemHolder.albumsongcount.setText(TimberUtils.makeCombinedString(mContext, albumNmber, songCount));
            LastFmClient.getInstance(mContext).getArtistInfo(new ArtistQuery(artist.name), new ArtistInfoListener() {

                @Override
                public void artistInfoSucess(LastfmArtist artist) {
                    if (artist != null && itemHolder.artistImage != null) {
                        ImageLoader.getInstance().displayImage(artist.mArtwork.get(1).mUrl, itemHolder.artistImage, new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).displayer(new FadeInBitmapDisplayer(400)).build());
                    }
                }

                @Override
                public void artistInfoFailed() {
                }
            });
            break;
        case 10:
            itemHolder.sectionHeader.setText((String) searchResults.get(i));
        case 3:
            break;
    }
}
Also used : LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist) Artist(com.naman14.timber.models.Artist) Song(com.naman14.timber.models.Song) ArtistInfoListener(com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer) Album(com.naman14.timber.models.Album) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions) ArtistQuery(com.naman14.timber.lastfmapi.models.ArtistQuery) LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist)

Example 3 with Album

use of com.naman14.timber.models.Album in project Timber by naman14.

the class ArtistAlbumAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ItemHolder itemHolder, int i) {
    Album localItem = arraylist.get(i);
    itemHolder.title.setText(localItem.title);
    String songCount = TimberUtils.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount);
    itemHolder.details.setText(songCount);
    ImageLoader.getInstance().displayImage(TimberUtils.getAlbumArtUri(localItem.id).toString(), itemHolder.albumArt, new DisplayImageOptions.Builder().cacheInMemory(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).build());
    if (TimberUtils.isLollipop())
        itemHolder.albumArt.setTransitionName("transition_album_art" + i);
}
Also used : Album(com.naman14.timber.models.Album) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions)

Example 4 with Album

use of com.naman14.timber.models.Album in project Timber by naman14.

the class QueueLoader method getQueueSongs.

public static List<Song> getQueueSongs(Context context) {
    final ArrayList<Song> mSongList = new ArrayList<>();
    mCursor = new NowPlayingCursor(context);
    if (mCursor != null && mCursor.moveToFirst()) {
        do {
            final long id = mCursor.getLong(0);
            final String songName = mCursor.getString(1);
            final String artist = mCursor.getString(2);
            final long albumId = mCursor.getLong(3);
            final String album = mCursor.getString(4);
            final int duration = mCursor.getInt(5);
            final long artistid = mCursor.getInt(7);
            final int tracknumber = mCursor.getInt(6);
            final Song song = new Song(id, albumId, artistid, songName, artist, album, duration, tracknumber);
            mSongList.add(song);
        } while (mCursor.moveToNext());
    }
    if (mCursor != null) {
        mCursor.close();
        mCursor = null;
    }
    return mSongList;
}
Also used : Song(com.naman14.timber.models.Song) ArrayList(java.util.ArrayList)

Example 5 with Album

use of com.naman14.timber.models.Album in project Timber by naman14.

the class AlbumDetailFragment method onCreateView.

@TargetApi(21)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_album_detail, container, false);
    albumArt = (ImageView) rootView.findViewById(R.id.album_art);
    artistArt = (ImageView) rootView.findViewById(R.id.artist_art);
    albumTitle = (TextView) rootView.findViewById(R.id.album_title);
    albumDetails = (TextView) rootView.findViewById(R.id.album_details);
    toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    if (getArguments().getBoolean("transition")) {
        albumArt.setTransitionName(getArguments().getString("transition_name"));
    }
    recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
    collapsingToolbarLayout = (CollapsingToolbarLayout) rootView.findViewById(R.id.collapsing_toolbar);
    appBarLayout = (AppBarLayout) rootView.findViewById(R.id.app_bar);
    recyclerView.setEnabled(false);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    album = AlbumLoader.getAlbum(getActivity(), albumID);
    setAlbumart();
    setUpEverything();
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    AlbumSongsAdapter adapter = (AlbumSongsAdapter) recyclerView.getAdapter();
                    MusicPlayer.playAll(getActivity(), adapter.getSongIds(), 0, albumID, TimberUtils.IdType.Album, true);
                    NavigationUtils.navigateToNowplaying(getActivity(), false);
                }
            }, 150);
        }
    });
    return rootView;
}
Also used : AlbumSongsAdapter(com.naman14.timber.adapters.AlbumSongsAdapter) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) TargetApi(android.annotation.TargetApi)

Aggregations

Song (com.naman14.timber.models.Song)8 ArrayList (java.util.ArrayList)6 Cursor (android.database.Cursor)4 Album (com.naman14.timber.models.Album)4 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)2 FadeInBitmapDisplayer (com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)2 TargetApi (android.annotation.TargetApi)1 ContentResolver (android.content.ContentResolver)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 Palette (android.support.v7.graphics.Palette)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 AlbumSongsAdapter (com.naman14.timber.adapters.AlbumSongsAdapter)1 ArtistInfoListener (com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener)1 ArtistQuery (com.naman14.timber.lastfmapi.models.ArtistQuery)1