Search in sources :

Example 6 with Artist

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

the class SongLoader method getSongFromPath.

public static Song getSongFromPath(String songPath, Context context) {
    ContentResolver cr = context.getContentResolver();
    Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    String selection = MediaStore.Audio.Media.DATA;
    String[] selectionArgs = { songPath };
    String[] projection = new String[] { "_id", "title", "artist", "album", "duration", "track", "artist_id", "album_id" };
    String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
    Cursor cursor = cr.query(uri, projection, selection + "=?", selectionArgs, sortOrder);
    if (cursor != null && cursor.getCount() > 0) {
        Song song = getSongForCursor(cursor);
        cursor.close();
        return song;
    } else
        return new Song();
}
Also used : Song(com.naman14.timber.models.Song) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 7 with Artist

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

the class SongLoader method getSongForCursor.

public static Song getSongForCursor(Cursor cursor) {
    Song song = new Song();
    if ((cursor != null) && (cursor.moveToFirst())) {
        long id = cursor.getLong(0);
        String title = cursor.getString(1);
        String artist = cursor.getString(2);
        String album = cursor.getString(3);
        int duration = cursor.getInt(4);
        int trackNumber = cursor.getInt(5);
        long artistId = cursor.getInt(6);
        long albumId = cursor.getLong(7);
        song = new Song(id, albumId, artistId, title, artist, album, duration, trackNumber);
    }
    if (cursor != null)
        cursor.close();
    return song;
}
Also used : Song(com.naman14.timber.models.Song)

Example 8 with Artist

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

the class ArtistAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ItemHolder itemHolder, int i) {
    final Artist localItem = arraylist.get(i);
    itemHolder.name.setText(localItem.name);
    String albumNmber = TimberUtils.makeLabel(mContext, R.plurals.Nalbums, localItem.albumCount);
    String songCount = TimberUtils.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount);
    itemHolder.albums.setText(TimberUtils.makeCombinedString(mContext, albumNmber, songCount));
    LastFmClient.getInstance(mContext).getArtistInfo(new ArtistQuery(localItem.name), new ArtistInfoListener() {

        @Override
        public void artistInfoSucess(LastfmArtist artist) {
            if (artist != null && artist.mArtwork != null) {
                if (isGrid) {
                    ImageLoader.getInstance().displayImage(artist.mArtwork.get(2).mUrl, itemHolder.artistImage, new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(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 && loadedImage != null) {
                                new Palette.Builder(loadedImage).generate(new Palette.PaletteAsyncListener() {

                                    @Override
                                    public void onGenerated(Palette palette) {
                                        int color = palette.getVibrantColor(Color.parseColor("#66000000"));
                                        itemHolder.footer.setBackgroundColor(color);
                                        Palette.Swatch swatch = palette.getVibrantSwatch();
                                        int textColor;
                                        if (swatch != null) {
                                            textColor = getOpaqueColor(swatch.getTitleTextColor());
                                        } else
                                            textColor = Color.parseColor("#ffffff");
                                        itemHolder.name.setTextColor(textColor);
                                        itemHolder.albums.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.name.setTextColor(textColorPrimary);
                                    itemHolder.albums.setTextColor(textColorPrimary);
                                }
                            }
                        }
                    });
                } else {
                    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() {
        }
    });
    if (TimberUtils.isLollipop())
        itemHolder.artistImage.setTransitionName("transition_artist_art" + i);
}
Also used : LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist) Artist(com.naman14.timber.models.Artist) Palette(android.support.v7.graphics.Palette) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ArtistQuery(com.naman14.timber.lastfmapi.models.ArtistQuery) LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist) SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Bitmap(android.graphics.Bitmap) ArtistInfoListener(com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)

Example 9 with Artist

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

the class ArtistBioFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_artist_bio, container, false);
    Artist artist = ArtistLoader.getArtist(getActivity(), artistID);
    LastFmClient.getInstance(getActivity()).getArtistInfo(new ArtistQuery(artist.name), new ArtistInfoListener() {

        @Override
        public void artistInfoSucess(LastfmArtist artist) {
        }

        @Override
        public void artistInfoFailed() {
        }
    });
    final MultiViewPager pager = (MultiViewPager) rootView.findViewById(R.id.tagspager);
    final FragmentStatePagerAdapter adapter = new FragmentStatePagerAdapter(getActivity().getSupportFragmentManager()) {

        @Override
        public int getCount() {
            return 20;
        }

        @Override
        public Fragment getItem(int position) {
            return ArtistTagFragment.newInstance(position);
        }
    };
    pager.setAdapter(adapter);
    return rootView;
}
Also used : LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist) Artist(com.naman14.timber.models.Artist) FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) ArtistInfoListener(com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener) MultiViewPager(com.naman14.timber.widgets.MultiViewPager) View(android.view.View) ArtistQuery(com.naman14.timber.lastfmapi.models.ArtistQuery) LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist)

Example 10 with Artist

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

the class ArtistSongLoader method getSongsForArtist.

public static ArrayList<Song> getSongsForArtist(Context context, long artistID) {
    Cursor cursor = makeArtistSongCursor(context, artistID);
    ArrayList songsList = new ArrayList();
    if ((cursor != null) && (cursor.moveToFirst()))
        do {
            long id = cursor.getLong(0);
            String title = cursor.getString(1);
            String artist = cursor.getString(2);
            String album = cursor.getString(3);
            int duration = cursor.getInt(4);
            int trackNumber = cursor.getInt(5);
            long albumId = cursor.getInt(6);
            long artistId = artistID;
            songsList.add(new Song(id, albumId, artistID, title, artist, album, duration, trackNumber));
        } while (cursor.moveToNext());
    if (cursor != null)
        cursor.close();
    return songsList;
}
Also used : Song(com.naman14.timber.models.Song) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Aggregations

Song (com.naman14.timber.models.Song)8 ArtistInfoListener (com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener)5 ArtistQuery (com.naman14.timber.lastfmapi.models.ArtistQuery)5 LastfmArtist (com.naman14.timber.lastfmapi.models.LastfmArtist)5 Artist (com.naman14.timber.models.Artist)5 ArrayList (java.util.ArrayList)5 View (android.view.View)4 Cursor (android.database.Cursor)3 Bitmap (android.graphics.Bitmap)2 Palette (android.support.v7.graphics.Palette)2 ImageView (android.widget.ImageView)2 FadeInBitmapDisplayer (com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)2 SimpleImageLoadingListener (com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener)2 ContentResolver (android.content.ContentResolver)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)1 RecyclerView (android.support.v7.widget.RecyclerView)1 TextView (android.widget.TextView)1 Album (com.naman14.timber.models.Album)1