Search in sources :

Example 26 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project ListenerMusicPlayer by hefuyicoder.

the class ArtistSongAdapter method setOnPopupMenuListener.

private void setOnPopupMenuListener(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) {
                    switch(item.getItemId()) {
                        case R.id.popup_song_play_next:
                            long[] ids = new long[1];
                            ids[0] = arraylist.get(position + 1).id;
                            MusicPlayer.playNext(mContext, ids, -1, ListenerUtil.IdType.NA);
                            break;
                        case R.id.popup_song_addto_playlist:
                            ListenerUtil.showAddPlaylistDialog(mContext, new long[] { arraylist.get(position + 1).id });
                            break;
                        case R.id.popup_song_addto_queue:
                            long[] id = new long[1];
                            id[0] = arraylist.get(position + 1).id;
                            MusicPlayer.addToQueue(mContext, id, -1, ListenerUtil.IdType.NA);
                            break;
                        case R.id.popup_song_goto_album:
                            NavigationUtil.goToAlbum(mContext, arraylist.get(position + 1).albumId, arraylist.get(position + 1).title);
                            break;
                        case R.id.popup_song_delete:
                            long[] deleteIds = { arraylist.get(position + 1).id };
                            ListenerUtil.showDeleteDialog(mContext, arraylist.get(position + 1).title, deleteIds, new MaterialDialog.SingleButtonCallback() {

                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                    arraylist.remove(position + 1);
                                    songIDs = getSongIds();
                                    notifyDataSetChanged();
                                }
                            });
                            break;
                    }
                    return false;
                }
            });
            menu.inflate(R.menu.popup_song);
            menu.getMenu().findItem(R.id.popup_song_goto_artist).setVisible(false);
            menu.show();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) PopupMenu(android.widget.PopupMenu)

Example 27 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project ListenerMusicPlayer by hefuyicoder.

the class PlaylistSongAdapter 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);
            final int adapterPosition = itemHolder.getAdapterPosition();
            final Song song = arraylist.get(adapterPosition);
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.popup_song_play_next:
                            long[] ids = new long[1];
                            ids[0] = arraylist.get(adapterPosition).id;
                            MusicPlayer.playNext(mContext, ids, -1, ListenerUtil.IdType.NA);
                            break;
                        case R.id.popup_song_goto_album:
                            NavigationUtil.goToAlbum(mContext, song.albumId, song.title);
                            break;
                        case R.id.popup_song_goto_artist:
                            NavigationUtil.goToArtist(mContext, song.artistId, song.artistName);
                            break;
                        case R.id.popup_song_addto_queue:
                            long[] id = new long[1];
                            id[0] = song.id;
                            MusicPlayer.addToQueue(mContext, id, -1, ListenerUtil.IdType.Playlist);
                            break;
                        case R.id.popup_song_addto_playlist:
                            ListenerUtil.showAddPlaylistDialog(mContext, new long[] { song.id });
                            break;
                        case R.id.popup_song_delete:
                            new MaterialDialog.Builder(mContext).title(mContext.getResources().getString(R.string.delete_playlist_song) + "?").positiveText(R.string.delete).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {

                                @Override
                                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                    PlaylistSongLoader.removeFromPlaylist(mContext, new long[] { song.id }, playlistId);
                                    arraylist.remove(adapterPosition);
                                    songIDs = getSongIds();
                                    notifyItemRemoved(adapterPosition);
                                }
                            }).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_song);
            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) Song(io.hefuyi.listener.mvp.model.Song) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) PopupMenu(android.widget.PopupMenu)

Example 28 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog 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 29 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog 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)

Example 30 with MaterialDialog

use of com.afollestad.materialdialogs.MaterialDialog in project ListenerMusicPlayer by hefuyicoder.

the class PlaylistDetailFragment method showRenamePlaylistDialog.

private void showRenamePlaylistDialog(String oldName) {
    new MaterialDialog.Builder(getActivity()).title(R.string.rename_playlist).positiveText("确定").negativeText(R.string.cancel).input(null, oldName, false, new MaterialDialog.InputCallback() {

        @Override
        public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
            MusicPlayer.renamePlaylist(getActivity(), playlistID, input.toString());
            collapsingToolbarLayout.setTitle(input.toString());
            playlistName = input.toString();
            RxBus.getInstance().post(new PlaylistUpdateEvent());
            Toast.makeText(getActivity(), R.string.rename_playlist_success, Toast.LENGTH_SHORT).show();
        }
    }).show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) PlaylistUpdateEvent(io.hefuyi.listener.event.PlaylistUpdateEvent) NonNull(android.support.annotation.NonNull)

Aggregations

MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)80 View (android.view.View)49 DialogAction (com.afollestad.materialdialogs.DialogAction)44 NonNull (android.support.annotation.NonNull)32 TextView (android.widget.TextView)32 Intent (android.content.Intent)19 ImageView (android.widget.ImageView)19 RecyclerView (android.support.v7.widget.RecyclerView)17 File (java.io.File)17 MenuItem (android.view.MenuItem)14 PopupMenu (android.widget.PopupMenu)12 List (java.util.List)12 ListView (android.widget.ListView)11 Activity (android.app.Activity)9 Toast (android.widget.Toast)9 SuppressLint (android.annotation.SuppressLint)8 Context (android.content.Context)8 Bundle (android.os.Bundle)8 ArrayList (java.util.ArrayList)8 LayoutInflater (android.view.LayoutInflater)7