Search in sources :

Example 1 with Playlist

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();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) FavourateSongEvent(io.hefuyi.listener.event.FavourateSongEvent) AppCompatActivity(android.support.v7.app.AppCompatActivity) View(android.view.View) Playlist(io.hefuyi.listener.mvp.model.Playlist) PlaylistUpdateEvent(io.hefuyi.listener.event.PlaylistUpdateEvent) CreatePlaylistDialog(io.hefuyi.listener.ui.dialogs.CreatePlaylistDialog) Dialog(android.app.Dialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) List(java.util.List)

Example 2 with Playlist

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);
}
Also used : Playlist(io.hefuyi.listener.mvp.model.Playlist) Resources(android.content.res.Resources)

Example 3 with Playlist

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);
}
Also used : Playlist(io.hefuyi.listener.mvp.model.Playlist) GetPlaylists(io.hefuyi.listener.mvp.usecase.GetPlaylists) List(java.util.List) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Example 4 with Playlist

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();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) FastScrollRecyclerView(io.hefuyi.listener.widget.fastscroller.FastScrollRecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Playlist(io.hefuyi.listener.mvp.model.Playlist) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) PopupMenu(android.widget.PopupMenu)

Example 5 with Playlist

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);
}
Also used : Palette(android.support.v7.graphics.Palette) Drawable(android.graphics.drawable.Drawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Playlist(io.hefuyi.listener.mvp.model.Playlist) Song(io.hefuyi.listener.mvp.model.Song) Bitmap(android.graphics.Bitmap) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Playlist (io.hefuyi.listener.mvp.model.Playlist)5 List (java.util.List)3 View (android.view.View)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 Dialog (android.app.Dialog)1 Resources (android.content.res.Resources)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 NonNull (android.support.annotation.NonNull)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 Palette (android.support.v7.graphics.Palette)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MenuItem (android.view.MenuItem)1 ImageView (android.widget.ImageView)1 PopupMenu (android.widget.PopupMenu)1 TextView (android.widget.TextView)1 DialogAction (com.afollestad.materialdialogs.DialogAction)1 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)1 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)1 FavourateSongEvent (io.hefuyi.listener.event.FavourateSongEvent)1