Search in sources :

Example 66 with PopupMenu

use of android.widget.PopupMenu in project ListenerMusicPlayer by hefuyicoder.

the class SongsListAdapter method setOnPopupMenuListener.

private void setOnPopupMenuListener(ItemHolder itemHolder, final int position) {
    final int realSongPosition;
    if (withHeader) {
        realSongPosition = position - 1;
    } else {
        realSongPosition = 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(realSongPosition).id;
                            MusicPlayer.playNext(mContext, ids, -1, ListenerUtil.IdType.NA);
                            break;
                        case R.id.popup_song_goto_album:
                            NavigationUtil.goToAlbum(mContext, arraylist.get(realSongPosition).albumId, arraylist.get(realSongPosition).title);
                            break;
                        case R.id.popup_song_goto_artist:
                            NavigationUtil.goToArtist(mContext, arraylist.get(realSongPosition).artistId, arraylist.get(realSongPosition).artistName);
                            break;
                        case R.id.popup_song_addto_queue:
                            long[] id = new long[1];
                            id[0] = arraylist.get(realSongPosition).id;
                            MusicPlayer.addToQueue(mContext, id, -1, ListenerUtil.IdType.NA);
                            break;
                        case R.id.popup_song_addto_playlist:
                            ListenerUtil.showAddPlaylistDialog(mContext, new long[] { arraylist.get(realSongPosition).id });
                            break;
                        case R.id.popup_song_delete:
                            long[] deleteIds = { arraylist.get(realSongPosition).id };
                            switch(action) {
                                case Constants.NAVIGATE_PLAYLIST_FAVOURATE:
                                    ListenerUtil.showDeleteFromFavourate(mContext, deleteIds);
                                    break;
                                case Constants.NAVIGATE_PLAYLIST_RECENTPLAY:
                                    ListenerUtil.showDeleteFromRecentlyPlay(mContext, deleteIds);
                                    break;
                                default:
                                    ListenerUtil.showDeleteDialog(mContext, arraylist.get(realSongPosition).title, deleteIds, new MaterialDialog.SingleButtonCallback() {

                                        @Override
                                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                            arraylist.remove(realSongPosition);
                                            songIDs = getSongIds();
                                            notifyItemRemoved(position);
                                        }
                                    });
                                    break;
                            }
                            break;
                    }
                    return false;
                }
            });
            menu.inflate(R.menu.popup_song);
            menu.show();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) 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) PopupMenu(android.widget.PopupMenu)

Example 67 with PopupMenu

use of android.widget.PopupMenu 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)

Example 68 with PopupMenu

use of android.widget.PopupMenu in project materialistic by hidroh.

the class ItemFragmentSinglePageTest method testVoteItemFailed.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItemFailed() {
    viewHolder.itemView.findViewById(R.id.button_more).performClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote));
    verify(userServices).voteUp(any(Context.class), any(), voteCallback.capture());
    voteCallback.getValue().onError(new IOException());
    assertEquals(activity.getString(R.string.vote_failed), ShadowToast.getTextOfLatestToast());
}
Also used : Context(android.content.Context) IOException(java.io.IOException) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 69 with PopupMenu

use of android.widget.PopupMenu in project materialistic by hidroh.

the class ListFragmentViewHolderTest method testVoteItemFailed.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItemFailed() {
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
    itemListener.getValue().onResponse(item);
    adapter.getViewHolder(0).itemView.performLongClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote));
    verify(userServices).voteUp(any(Context.class), eq(item.getId()), voteCallback.capture());
    voteCallback.getValue().onError(new IOException());
    assertEquals(activity.getString(R.string.vote_failed), ShadowToast.getTextOfLatestToast());
}
Also used : Context(android.content.Context) IOException(java.io.IOException) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 70 with PopupMenu

use of android.widget.PopupMenu in project materialistic by hidroh.

the class ListFragmentViewHolderTest method testViewUser.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testViewUser() {
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
    itemListener.getValue().onResponse(item);
    adapter.getViewHolder(0).itemView.performLongClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_profile));
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, UserActivity.class).hasExtra(UserActivity.EXTRA_USERNAME, "author");
}
Also used : RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Aggregations

PopupMenu (android.widget.PopupMenu)99 MenuItem (android.view.MenuItem)60 View (android.view.View)44 TextView (android.widget.TextView)41 ImageView (android.widget.ImageView)30 RecyclerView (android.support.v7.widget.RecyclerView)22 TargetApi (android.annotation.TargetApi)20 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)19 Test (org.junit.Test)19 ShadowPopupMenu (org.robolectric.shadows.ShadowPopupMenu)19 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)18 Intent (android.content.Intent)14 Context (android.content.Context)12 DialogAction (com.afollestad.materialdialogs.DialogAction)12 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)12 MenuInflater (android.view.MenuInflater)10 AdapterView (android.widget.AdapterView)10 ListView (android.widget.ListView)10 Menu (android.view.Menu)9 NonNull (android.support.annotation.NonNull)8