Search in sources :

Example 11 with PlayList

use of io.github.ryanhoo.music.data.model.PlayList in project StylishMusicPlayer by ryanhoo.

the class PlayListDetailsActivity method onAction.

// Adapter Action Callback
@Override
public void onAction(View actionView, final int position) {
    final Song song = mAdapter.getItem(position);
    PopupMenu actionMenu = new PopupMenu(this, actionView, Gravity.END | Gravity.BOTTOM);
    actionMenu.inflate(R.menu.music_action);
    actionMenu.getMenu().findItem(R.id.menu_item_delete).setVisible(!isFolder);
    actionMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case R.id.menu_item_add_to_play_list:
                    new AddToPlayListDialogFragment().setCallback(new AddToPlayListDialogFragment.Callback() {

                        @Override
                        public void onPlayListSelected(PlayList playList) {
                            if (playList.getId() == mPlayList.getId())
                                return;
                            mPresenter.addSongToPlayList(song, playList);
                        }
                    }).show(getSupportFragmentManager().beginTransaction(), "AddToPlayList");
                    break;
                case R.id.menu_item_delete:
                    mDeleteIndex = position;
                    mPresenter.delete(song, mPlayList);
                    break;
            }
            return true;
        }
    });
    actionMenu.show();
}
Also used : AddToPlayListDialogFragment(io.github.ryanhoo.music.ui.playlist.AddToPlayListDialogFragment) PlayList(io.github.ryanhoo.music.data.model.PlayList) Song(io.github.ryanhoo.music.data.model.Song) MenuItem(android.view.MenuItem) PopupMenu(android.support.v7.widget.PopupMenu)

Example 12 with PlayList

use of io.github.ryanhoo.music.data.model.PlayList in project StylishMusicPlayer by ryanhoo.

the class PlayListDetailsPresenter method addSongToPlayList.

@Override
public void addSongToPlayList(Song song, PlayList playList) {
    if (playList.isFavorite()) {
        song.setFavorite(true);
    }
    playList.addSong(song, 0);
    Subscription subscription = mRepository.update(playList).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<PlayList>() {

        @Override
        public void onStart() {
            mView.showLoading();
        }

        @Override
        public void onCompleted() {
            mView.hideLoading();
        }

        @Override
        public void onError(Throwable e) {
            mView.hideLoading();
            mView.handleError(e);
        }

        @Override
        public void onNext(PlayList playList) {
            RxBus.getInstance().post(new PlayListUpdatedEvent(playList));
        }
    });
    mSubscriptions.add(subscription);
}
Also used : PlayList(io.github.ryanhoo.music.data.model.PlayList) PlayListUpdatedEvent(io.github.ryanhoo.music.event.PlayListUpdatedEvent) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Example 13 with PlayList

use of io.github.ryanhoo.music.data.model.PlayList in project StylishMusicPlayer by ryanhoo.

the class PlayListPresenter method createPlayList.

@Override
public void createPlayList(PlayList playList) {
    Subscription subscription = mRepository.create(playList).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<PlayList>() {

        @Override
        public void onStart() {
            mView.showLoading();
        }

        @Override
        public void onCompleted() {
            mView.hideLoading();
        }

        @Override
        public void onError(Throwable e) {
            mView.hideLoading();
            mView.handleError(e);
        }

        @Override
        public void onNext(PlayList result) {
            mView.onPlayListCreated(result);
        }
    });
    mSubscriptions.add(subscription);
}
Also used : PlayList(io.github.ryanhoo.music.data.model.PlayList) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Example 14 with PlayList

use of io.github.ryanhoo.music.data.model.PlayList in project StylishMusicPlayer by ryanhoo.

the class PlayListPresenter method loadPlayLists.

@Override
public void loadPlayLists() {
    Subscription subscription = mRepository.playLists().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<List<PlayList>>() {

        @Override
        public void onStart() {
            mView.showLoading();
        }

        @Override
        public void onCompleted() {
            mView.hideLoading();
        }

        @Override
        public void onError(Throwable e) {
            mView.hideLoading();
            mView.handleError(e);
        }

        @Override
        public void onNext(List<PlayList> playLists) {
            mView.onPlayListsLoaded(playLists);
        }
    });
    mSubscriptions.add(subscription);
}
Also used : PlayList(io.github.ryanhoo.music.data.model.PlayList) List(java.util.List) PlayList(io.github.ryanhoo.music.data.model.PlayList) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Example 15 with PlayList

use of io.github.ryanhoo.music.data.model.PlayList in project StylishMusicPlayer by ryanhoo.

the class PlayListPresenter method editPlayList.

@Override
public void editPlayList(PlayList playList) {
    Subscription subscription = mRepository.update(playList).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<PlayList>() {

        @Override
        public void onStart() {
            mView.showLoading();
        }

        @Override
        public void onCompleted() {
            mView.hideLoading();
        }

        @Override
        public void onError(Throwable e) {
            mView.hideLoading();
            mView.handleError(e);
        }

        @Override
        public void onNext(PlayList result) {
            mView.onPlayListEdited(result);
        }
    });
    mSubscriptions.add(subscription);
}
Also used : PlayList(io.github.ryanhoo.music.data.model.PlayList) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Aggregations

PlayList (io.github.ryanhoo.music.data.model.PlayList)16 Subscription (rx.Subscription)8 CompositeSubscription (rx.subscriptions.CompositeSubscription)8 PopupMenu (android.support.v7.widget.PopupMenu)3 PlayListUpdatedEvent (io.github.ryanhoo.music.event.PlayListUpdatedEvent)3 Song (io.github.ryanhoo.music.data.model.Song)2 AddToPlayListDialogFragment (io.github.ryanhoo.music.ui.playlist.AddToPlayListDialogFragment)2 MenuItem (android.view.MenuItem)1 Folder (io.github.ryanhoo.music.data.model.Folder)1 PlayListNowEvent (io.github.ryanhoo.music.event.PlayListNowEvent)1 OnItemClickListener (io.github.ryanhoo.music.ui.base.adapter.OnItemClickListener)1 DefaultDividerDecoration (io.github.ryanhoo.music.ui.common.DefaultDividerDecoration)1 EditPlayListDialogFragment (io.github.ryanhoo.music.ui.playlist.EditPlayListDialogFragment)1 List (java.util.List)1