Search in sources :

Example 1 with Album

use of io.hefuyi.listener.mvp.model.Album in project ListenerMusicPlayer by hefuyicoder.

the class AlbumsPresenter method loadAlbums.

@Override
public void loadAlbums(String action) {
    mCompositeSubscription.clear();
    Subscription subscription = mUsecase.execute(new GetAlbums.RequestValues(action)).getSongList().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Album>>() {

        @Override
        public void call(List<Album> albumList) {
            if (albumList == null || albumList.size() == 0) {
                mView.showEmptyView();
            } else {
                mView.showAlbums(albumList);
            }
        }
    });
    mCompositeSubscription.add(subscription);
}
Also used : GetAlbums(io.hefuyi.listener.mvp.usecase.GetAlbums) Album(io.hefuyi.listener.mvp.model.Album) List(java.util.List) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Example 2 with Album

use of io.hefuyi.listener.mvp.model.Album in project ListenerMusicPlayer by hefuyicoder.

the class ArtistAlbumLoader method getAlbumsForArtist.

public static Observable<List<Album>> getAlbumsForArtist(final Context context, final long artistID) {
    return Observable.create(new Observable.OnSubscribe<List<Album>>() {

        @Override
        public void call(Subscriber<? super List<Album>> subscriber) {
            List<Album> albumList = new ArrayList<Album>();
            Cursor cursor = makeAlbumForArtistCursor(context, artistID);
            if (cursor != null) {
                if (cursor.moveToFirst())
                    do {
                        Album album = new Album(cursor.getLong(0), cursor.getString(1), cursor.getString(2), artistID, cursor.getInt(3), cursor.getInt(4));
                        albumList.add(album);
                    } while (cursor.moveToNext());
            }
            if (cursor != null) {
                cursor.close();
            }
            subscriber.onNext(albumList);
            subscriber.onCompleted();
        }
    });
}
Also used : Album(io.hefuyi.listener.mvp.model.Album) List(java.util.List) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Observable(rx.Observable)

Example 3 with Album

use of io.hefuyi.listener.mvp.model.Album in project ListenerMusicPlayer by hefuyicoder.

the class AlbumAdapter method setOnPopupMenuListener.

private void setOnPopupMenuListener(final AlbumAdapter.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 Album album = arraylist.get(adapterPosition);
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.popup_album_addto_queue:
                            getSongListIdByAlbum(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_album_addto_playlist:
                            getSongListIdByAlbum(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_album_goto_artist:
                            NavigationUtil.goToArtist(mContext, arraylist.get(position).artistId, arraylist.get(position).artistName);
                            break;
                        case R.id.popup_artist_delete:
                            switch(action) {
                                case Constants.NAVIGATE_PLAYLIST_FAVOURATE:
                                    getSongListIdByAlbum(album.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:
                                    getSongListIdByAlbum(album.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<long[]>() {

                                        @Override
                                        public void call(long[] ids) {
                                            ListenerUtil.showDeleteFromRecentlyPlay(mContext, ids);
                                        }
                                    });
                                    break;
                                default:
                                    AlbumSongLoader.getSongsForAlbum(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_album);
            menu.show();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Album(io.hefuyi.listener.mvp.model.Album) 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) 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 4 with Album

use of io.hefuyi.listener.mvp.model.Album in project ListenerMusicPlayer by hefuyicoder.

the class ArtistAlbumAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ItemHolder itemHolder, int i) {
    Album localItem = arraylist.get(i);
    itemHolder.title.setText(localItem.title);
    String songCount = ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount);
    itemHolder.details.setText(songCount);
    Glide.with(mContext).load(ListenerUtil.getAlbumArtUri(localItem.id).toString()).diskCacheStrategy(DiskCacheStrategy.SOURCE).error(ATEUtil.getDefaultAlbumDrawable(mContext)).centerCrop().into(itemHolder.albumArt);
    if (ListenerUtil.isLollipop())
        itemHolder.albumArt.setTransitionName("transition_album_art" + i);
}
Also used : Album(io.hefuyi.listener.mvp.model.Album)

Example 5 with Album

use of io.hefuyi.listener.mvp.model.Album in project ListenerMusicPlayer by hefuyicoder.

the class SearchAdapter method setAlbumPopupMenu.

private void setAlbumPopupMenu(ItemHolder itemHolder, final int position) {
    final Album album = (Album) 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_album_addto_queue:
                            getSongListIdByAlbum(album.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_album_addto_playlist:
                            getSongListIdByAlbum(album.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_album_goto_artist:
                            NavigationUtil.goToArtist(mContext, album.artistId, album.artistName);
                            break;
                        case R.id.popup_artist_delete:
                            AlbumSongLoader.getSongsForAlbum(mContext, album.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, album.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_album);
            menu.show();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Album(io.hefuyi.listener.mvp.model.Album) 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)

Aggregations

Album (io.hefuyi.listener.mvp.model.Album)8 List (java.util.List)5 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 ArrayList (java.util.ArrayList)2 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 Palette (android.support.v7.graphics.Palette)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Gson (com.google.gson.Gson)1 Artist (io.hefuyi.listener.mvp.model.Artist)1