Search in sources :

Example 1 with PlayListNowEvent

use of io.github.ryanhoo.music.event.PlayListNowEvent in project StylishMusicPlayer by ryanhoo.

the class PlayListFragment method onAction.

// Adapter Callbacks
@Override
public void onAction(View actionView, final int position) {
    final PlayList playList = mAdapter.getItem(position);
    PopupMenu actionMenu = new PopupMenu(getActivity(), actionView, Gravity.END | Gravity.BOTTOM);
    actionMenu.inflate(R.menu.play_list_action);
    if (playList.isFavorite()) {
        actionMenu.getMenu().findItem(R.id.menu_item_rename).setVisible(false);
        actionMenu.getMenu().findItem(R.id.menu_item_delete).setVisible(false);
    }
    actionMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == R.id.menu_item_play_now) {
                PlayListNowEvent playListNowEvent = new PlayListNowEvent(playList, 0);
                RxBus.getInstance().post(playListNowEvent);
            } else if (item.getItemId() == R.id.menu_item_rename) {
                mEditIndex = position;
                EditPlayListDialogFragment.editPlayList(playList).setCallback(PlayListFragment.this).show(getFragmentManager().beginTransaction(), "EditPlayList");
            } else if (item.getItemId() == R.id.menu_item_delete) {
                mDeleteIndex = position;
                mPresenter.deletePlayList(playList);
            }
            return true;
        }
    });
    actionMenu.show();
}
Also used : PlayList(io.github.ryanhoo.music.data.model.PlayList) PlayListNowEvent(io.github.ryanhoo.music.event.PlayListNowEvent) PopupMenu(android.support.v7.widget.PopupMenu)

Example 2 with PlayListNowEvent

use of io.github.ryanhoo.music.event.PlayListNowEvent in project StylishMusicPlayer by ryanhoo.

the class PlayListDetailsActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    Folder folder = getIntent().getParcelableExtra(EXTRA_FOLDER);
    mPlayList = getIntent().getParcelableExtra(EXTRA_PLAY_LIST);
    if (folder == null && mPlayList == null) {
        Log.e(TAG, "onCreate: folder & play list can't be both null!");
        finish();
    }
    if (folder != null) {
        isFolder = true;
        mPlayList = PlayList.fromFolder(folder);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play_list_details);
    ButterKnife.bind(this);
    supportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(mPlayList.getName());
    }
    mAdapter = new SongAdapter(this, mPlayList.getSongs());
    mAdapter.setActionCallback(this);
    mAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position) {
            RxBus.getInstance().post(new PlayListNowEvent(mPlayList, position));
        }
    });
    recyclerView.setAdapter(mAdapter);
    recyclerView.addItemDecoration(new DefaultDividerDecoration());
    emptyView.setVisibility(mPlayList.getNumOfSongs() > 0 ? View.GONE : View.VISIBLE);
    new PlayListDetailsPresenter(AppRepository.getInstance(), this).subscribe();
}
Also used : OnItemClickListener(io.github.ryanhoo.music.ui.base.adapter.OnItemClickListener) Folder(io.github.ryanhoo.music.data.model.Folder) PlayListNowEvent(io.github.ryanhoo.music.event.PlayListNowEvent) DefaultDividerDecoration(io.github.ryanhoo.music.ui.common.DefaultDividerDecoration)

Aggregations

PlayListNowEvent (io.github.ryanhoo.music.event.PlayListNowEvent)2 PopupMenu (android.support.v7.widget.PopupMenu)1 Folder (io.github.ryanhoo.music.data.model.Folder)1 PlayList (io.github.ryanhoo.music.data.model.PlayList)1 OnItemClickListener (io.github.ryanhoo.music.ui.base.adapter.OnItemClickListener)1 DefaultDividerDecoration (io.github.ryanhoo.music.ui.common.DefaultDividerDecoration)1