use of io.hefuyi.listener.mvp.model.Playlist in project ListenerMusicPlayer by hefuyicoder.
the class ListenerUtil method showAddPlaylistDialog.
public static void showAddPlaylistDialog(final Context context, final long[] songIds) {
PlaylistLoader.getPlaylists(context, true).map(new Func1<List<Playlist>, Dialog>() {
@Override
public Dialog call(final List<Playlist> playlists) {
final CharSequence[] chars = new CharSequence[playlists.size() + 1];
chars[0] = context.getResources().getString(R.string.create_new_playlist);
for (int i = 0; i < playlists.size(); i++) {
chars[i + 1] = playlists.get(i).name;
}
return new MaterialDialog.Builder(context).title(R.string.add_to_playlist).items(chars).itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
if (which == 0) {
CreatePlaylistDialog.newInstance(songIds).show(((AppCompatActivity) context).getSupportFragmentManager(), context.getString(R.string.create_new_playlist));
return;
} else if (which == 1) {
//我喜欢
int num = FavoriteSong.getInstance(context).addFavoriteSong(songIds);
Toast.makeText(getContext(), R.string.add_favorite_success, Toast.LENGTH_SHORT).show();
RxBus.getInstance().post(new FavourateSongEvent());
dialog.dismiss();
return;
}
MusicPlayer.addToPlaylist(context, songIds, playlists.get(which - 1).id);
RxBus.getInstance().post(new PlaylistUpdateEvent());
dialog.dismiss();
}
}).build();
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Dialog>() {
@Override
public void call(Dialog dialog) {
dialog.show();
}
});
}
use of io.hefuyi.listener.mvp.model.Playlist in project ListenerMusicPlayer by hefuyicoder.
the class PlaylistLoader method makeDefaultPlaylists.
private static void makeDefaultPlaylists(Context context) {
final Resources resources = context.getResources();
final Playlist topTracks = new Playlist(ListenerUtil.PlaylistType.Favourate.mId, resources.getString(ListenerUtil.PlaylistType.Favourate.mTitleId), -1);
mPlaylistList.add(topTracks);
}
use of io.hefuyi.listener.mvp.model.Playlist in project ListenerMusicPlayer by hefuyicoder.
the class PlaylistPresenter method loadPlaylist.
@Override
public void loadPlaylist() {
mCompositeSubscription.clear();
Subscription subscription = mUsecase.execute(new GetPlaylists.RequestValues(false)).getPlaylists().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Playlist>>() {
@Override
public void call(List<Playlist> playlists) {
if (playlists == null || playlists.size() == 0) {
mView.showEmptyView();
} else {
mView.showPlaylist(playlists);
}
}
});
mCompositeSubscription.add(subscription);
}
use of io.hefuyi.listener.mvp.model.Playlist in project ListenerMusicPlayer by hefuyicoder.
the class PlaylistAdapter method setOnPopupMenuListener.
private void setOnPopupMenuListener(final ItemHolder itemHolder, final int 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) {
final Playlist playlist = arraylist.get(itemHolder.getAdapterPosition());
switch(item.getItemId()) {
case R.id.popup_playlist_rename:
new MaterialDialog.Builder(mContext).title(R.string.rename_playlist).positiveText("确定").negativeText(R.string.cancel).input(null, playlist.name, false, new MaterialDialog.InputCallback() {
@Override
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
MusicPlayer.renamePlaylist(mContext, playlist.id, input.toString());
itemHolder.title.setText(input.toString());
Toast.makeText(mContext, R.string.rename_playlist_success, Toast.LENGTH_SHORT).show();
}
}).show();
break;
case R.id.popup_playlist_addto_playlist:
getSongListIdByPlaylist(playlist.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {
@Override
public void call(long[] ids) {
ListenerUtil.showAddPlaylistDialog(mFragment.getActivity(), ids);
}
});
break;
case R.id.popup_playlist_addto_queue:
getSongListIdByPlaylist(playlist.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {
@Override
public void call(long[] ids) {
MusicPlayer.addToQueue(mContext, ids, -1, ListenerUtil.IdType.Playlist);
}
});
break;
case R.id.popup_playlist_delete:
new MaterialDialog.Builder(mContext).title(R.string.delete_playlist).positiveText(R.string.delete).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
PlaylistLoader.deletePlaylists(mContext, playlist.id);
arraylist.remove(itemHolder.getAdapterPosition());
notifyItemRemoved(itemHolder.getAdapterPosition());
Toast.makeText(mContext, R.string.delete_playlist_success, Toast.LENGTH_SHORT).show();
}
}).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
dialog.dismiss();
}
}).show();
break;
}
return false;
}
});
menu.inflate(R.menu.popup_playlist);
menu.show();
}
});
}
use of io.hefuyi.listener.mvp.model.Playlist in project ListenerMusicPlayer by hefuyicoder.
the class PlaylistAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ItemHolder itemHolder, final int i) {
final Playlist localItem = arraylist.get(i);
itemHolder.title.setText(localItem.name);
itemHolder.songcount.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount));
itemHolder.subtitle1.setVisibility(View.GONE);
itemHolder.divider.setVisibility(View.GONE);
PlaylistSongLoader.getSongsInPlaylist(mContext, localItem.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Song>>() {
@Override
public void call(List<Song> playlistsongs) {
String uri = "";
long firstAlbumID = -1;
if (playlistsongs.size() != 0) {
firstAlbumID = playlistsongs.get(0).albumId;
uri = ListenerUtil.getAlbumArtUri(firstAlbumID).toString();
}
itemHolder.playlistArt.setTag(R.string.playlistArt, firstAlbumID);
Glide.with(itemHolder.itemView.getContext()).load(uri).asBitmap().placeholder(ATEUtil.getDefaultAlbumDrawable(mContext)).into(new SimpleTarget<Bitmap>() {
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
if (isGrid) {
itemHolder.footer.setBackgroundColor(ATEUtil.getThemeAlbumDefaultPaletteColor(mContext));
}
itemHolder.playlistArt.setImageDrawable(ATEUtil.getDefaultAlbumDrawable(mContext));
itemHolder.title.setTextColor(ATEUtil.getThemeTextColorPrimary(mContext));
itemHolder.songcount.setTextColor(ATEUtil.getThemeTextColorSecondly(mContext));
itemHolder.popupMenu.setColorFilter(mContext.getResources().getColor(R.color.background_floating_material_dark));
}
@Override
public void onResourceReady(final Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
if (isGrid) {
new Palette.Builder(resource).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
Palette.Swatch swatch = ColorUtil.getMostPopulousSwatch(palette);
if (swatch != null) {
int color = swatch.getRgb();
itemHolder.footer.setBackgroundColor(color);
int detailColor = swatch.getTitleTextColor();
itemHolder.playlistArt.setImageBitmap(resource);
itemHolder.title.setTextColor(ColorUtil.getOpaqueColor(detailColor));
itemHolder.songcount.setTextColor(detailColor);
itemHolder.popupMenu.setColorFilter(detailColor);
}
}
});
} else {
itemHolder.playlistArt.setImageBitmap(resource);
}
}
});
}
});
if (ListenerUtil.isLollipop())
itemHolder.playlistArt.setTransitionName("transition_album_art" + i);
setOnPopupMenuListener(itemHolder, i);
}
Aggregations