Search in sources :

Example 1 with Artist

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

Example 2 with Artist

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

Example 3 with Artist

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;
    }
}
Also used : Artist(io.hefuyi.listener.mvp.model.Artist) Song(io.hefuyi.listener.mvp.model.Song) Album(io.hefuyi.listener.mvp.model.Album) Gson(com.google.gson.Gson) ArtistArt(io.hefuyi.listener.mvp.model.ArtistArt)

Example 4 with Artist

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);
}
Also used : Artist(io.hefuyi.listener.mvp.model.Artist) Gson(com.google.gson.Gson) List(java.util.List) Func1(rx.functions.Func1) ArtistArt(io.hefuyi.listener.mvp.model.ArtistArt) ArtistInfo(io.hefuyi.listener.api.model.ArtistInfo) GetArtistInfo(io.hefuyi.listener.mvp.usecase.GetArtistInfo)

Example 5 with Artist

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

Aggregations

Artist (io.hefuyi.listener.mvp.model.Artist)5 List (java.util.List)4 Song (io.hefuyi.listener.mvp.model.Song)3 NonNull (android.support.annotation.NonNull)2 RecyclerView (android.support.v7.widget.RecyclerView)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 PopupMenu (android.widget.PopupMenu)2 TextView (android.widget.TextView)2 DialogAction (com.afollestad.materialdialogs.DialogAction)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 Gson (com.google.gson.Gson)2 ArtistArt (io.hefuyi.listener.mvp.model.ArtistArt)2 ArtistInfo (io.hefuyi.listener.api.model.ArtistInfo)1 Album (io.hefuyi.listener.mvp.model.Album)1 GetArtistInfo (io.hefuyi.listener.mvp.usecase.GetArtistInfo)1 GetArtists (io.hefuyi.listener.mvp.usecase.GetArtists)1 FastScrollRecyclerView (io.hefuyi.listener.widget.fastscroller.FastScrollRecyclerView)1 Subscription (rx.Subscription)1