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();
}
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;
}
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);
}
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;
}
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;
}
Aggregations