use of io.hefuyi.listener.mvp.model.Artist in project ListenerMusicPlayer by hefuyicoder.
the class SearchAdapter method setArtistPopupMenu.
private void setArtistPopupMenu(ItemHolder itemHolder, final int position) {
final Artist artist = (Artist) searchResults.get(position);
itemHolder.popupMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu menu = new PopupMenu(mContext, v);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.popup_artist_addto_queue:
getSongListIdByArtist(artist.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {
@Override
public void call(long[] ids) {
MusicPlayer.addToQueue(mContext, ids, -1, ListenerUtil.IdType.NA);
}
});
break;
case R.id.popup_artist_addto_playlist:
getSongListIdByArtist(artist.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {
@Override
public void call(long[] ids) {
ListenerUtil.showAddPlaylistDialog(mContext, ids);
}
});
break;
case R.id.popup_artist_delete:
ArtistSongLoader.getSongsForArtist(mContext, artist.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Song>>() {
@Override
public void call(List<Song> songs) {
long[] ids = new long[songs.size()];
int i = 0;
for (Song song : songs) {
ids[i] = song.id;
i++;
}
if (ids.length == 1) {
ListenerUtil.showDeleteDialog(mContext, songs.get(0).title, ids, new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
searchResults.remove(position);
notifyDataSetChanged();
}
});
} else {
String songCount = ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, artist.songCount);
ListenerUtil.showDeleteDialog(mContext, songCount, ids, new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
searchResults.remove(position);
notifyDataSetChanged();
}
});
}
}
});
break;
}
return false;
}
});
menu.inflate(R.menu.popup_artist);
menu.show();
}
});
}
use of io.hefuyi.listener.mvp.model.Artist in project ListenerMusicPlayer by hefuyicoder.
the class ArtistPresenter method loadArtists.
@Override
public void loadArtists(String action) {
mCompositeSubscription.clear();
Subscription subscription = mUsecase.execute(new GetArtists.RequestValues(action)).getArtistList().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Artist>>() {
@Override
public void call(List<Artist> artists) {
if (artists == null || artists.size() == 0) {
mView.showEmptyView();
} else {
mView.showArtists(artists);
}
}
});
mCompositeSubscription.add(subscription);
}
use of io.hefuyi.listener.mvp.model.Artist in project ListenerMusicPlayer by hefuyicoder.
the class SearchAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ItemHolder itemHolder, int position) {
switch(getItemViewType(position)) {
case 0:
Song song = (Song) searchResults.get(position);
itemHolder.title.setText(song.title);
itemHolder.subtitle1.setText(song.artistName);
itemHolder.subtitle2.setText(song.albumName);
Glide.with(itemHolder.itemView.getContext()).load(ListenerUtil.getAlbumArtUri(song.albumId).toString()).error(ATEUtil.getDefaultAlbumDrawable(mContext)).placeholder(ATEUtil.getDefaultAlbumDrawable(mContext)).centerCrop().into(itemHolder.image);
setOnPopupMenuListener(itemHolder, 0, position);
break;
case 1:
Album album = (Album) searchResults.get(position);
itemHolder.title.setText(album.title);
itemHolder.subtitle1.setText(album.artistName);
itemHolder.subtitle2.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, album.songCount));
Glide.with(itemHolder.itemView.getContext()).load(ListenerUtil.getAlbumArtUri(album.id).toString()).asBitmap().placeholder(ATEUtil.getDefaultAlbumDrawable(mContext)).error(ATEUtil.getDefaultAlbumDrawable(mContext)).centerCrop().into(itemHolder.image);
if (ListenerUtil.isLollipop())
itemHolder.image.setTransitionName("transition_album_art" + position);
setOnPopupMenuListener(itemHolder, 1, position);
break;
case 2:
Artist artist = (Artist) searchResults.get(position);
itemHolder.title.setText(artist.name);
itemHolder.subtitle1.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nalbums, artist.albumCount));
itemHolder.subtitle2.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, artist.songCount));
String artistArtJson = PreferencesUtility.getInstance(mContext).getArtistArt(artist.id);
if (!TextUtils.isEmpty(artistArtJson)) {
ArtistArt artistArt = new Gson().fromJson(artistArtJson, ArtistArt.class);
Glide.with(mContext).load(artistArt.getLarge()).asBitmap().placeholder(ATEUtil.getDefaultSingerDrawable(mContext)).diskCacheStrategy(DiskCacheStrategy.SOURCE).error(ATEUtil.getDefaultSingerDrawable(mContext)).into(itemHolder.image);
}
if (ListenerUtil.isLollipop())
itemHolder.image.setTransitionName("transition_artist_art" + position);
setOnPopupMenuListener(itemHolder, 2, position);
break;
case 10:
itemHolder.sectionHeader.setText((String) searchResults.get(position));
case 3:
break;
}
}
use of io.hefuyi.listener.mvp.model.Artist in project ListenerMusicPlayer by hefuyicoder.
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);
itemHolder.albumCount.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nalbums, localItem.albumCount));
itemHolder.songCount.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount));
String artistArtJson = PreferencesUtility.getInstance(mContext).getArtistArt(localItem.id);
if (TextUtils.isEmpty(artistArtJson)) {
getArtistInfo.execute(new GetArtistInfo.RequestValues(localItem.name)).getArtistInfo().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).onErrorReturn(new Func1<Throwable, ArtistInfo>() {
@Override
public ArtistInfo call(Throwable throwable) {
Toast.makeText(itemHolder.itemView.getContext(), R.string.load_artist_fail, Toast.LENGTH_SHORT).show();
return null;
}
}).subscribe(new Action1<ArtistInfo>() {
@Override
public void call(ArtistInfo artistInfo) {
if (artistInfo != null && artistInfo.mArtist != null && artistInfo.mArtist.mArtwork != null) {
List<Artwork> artworks = artistInfo.mArtist.mArtwork;
ArtistArt artistArt = new ArtistArt(artworks.get(0).mUrl, artworks.get(1).mUrl, artworks.get(2).mUrl, artworks.get(3).mUrl);
PreferencesUtility.getInstance(mContext).setArtistArt(localItem.id, new Gson().toJson(artistArt));
loadArtistArt(artistArt, itemHolder);
}
}
});
} else {
ArtistArt artistArt = new Gson().fromJson(artistArtJson, ArtistArt.class);
loadArtistArt(artistArt, itemHolder);
}
if (ListenerUtil.isLollipop())
itemHolder.artistImage.setTransitionName("transition_artist_art" + i);
setOnPopupMenuListener(itemHolder, i);
}
use of io.hefuyi.listener.mvp.model.Artist in project ListenerMusicPlayer by hefuyicoder.
the class ArtistAdapter method setOnPopupMenuListener.
private void setOnPopupMenuListener(final ArtistAdapter.ItemHolder itemHolder, final int position) {
itemHolder.popupMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu menu = new PopupMenu(mContext, v);
int adapterPosition = itemHolder.getAdapterPosition();
final Artist artist = arraylist.get(adapterPosition);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.popup_artist_addto_queue:
getSongListIdByArtist(arraylist.get(position).id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {
@Override
public void call(long[] ids) {
MusicPlayer.addToQueue(mContext, ids, -1, ListenerUtil.IdType.NA);
}
});
break;
case R.id.popup_artist_addto_playlist:
getSongListIdByArtist(arraylist.get(position).id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {
@Override
public void call(long[] ids) {
ListenerUtil.showAddPlaylistDialog(mContext, ids);
}
});
break;
case R.id.popup_artist_delete:
switch(action) {
case Constants.NAVIGATE_PLAYLIST_FAVOURATE:
getSongListIdByArtist(artist.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {
@Override
public void call(long[] ids) {
ListenerUtil.showDeleteFromFavourate(mContext, ids);
}
});
break;
case Constants.NAVIGATE_PLAYLIST_RECENTPLAY:
getSongListIdByArtist(artist.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {
@Override
public void call(long[] ids) {
ListenerUtil.showDeleteFromRecentlyPlay(mContext, ids);
}
});
break;
default:
ArtistSongLoader.getSongsForArtist(mContext, arraylist.get(position).id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Song>>() {
@Override
public void call(List<Song> songs) {
long[] ids = new long[songs.size()];
int i = 0;
for (Song song : songs) {
ids[i] = song.id;
i++;
}
if (ids.length == 1) {
ListenerUtil.showDeleteDialog(mContext, songs.get(0).title, ids, new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
arraylist.remove(position);
notifyDataSetChanged();
}
});
} else {
String songCount = ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, arraylist.get(position).songCount);
ListenerUtil.showDeleteDialog(mContext, songCount, ids, new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
arraylist.remove(position);
notifyDataSetChanged();
}
});
}
}
});
break;
}
break;
}
return false;
}
});
menu.inflate(R.menu.popup_artist);
menu.show();
}
});
}
Aggregations