Search in sources :

Example 6 with PlayList

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

the class FolderPresenter method addFolderToPlayList.

@Override
public void addFolderToPlayList(final Folder folder, PlayList playList) {
    if (folder.getSongs().isEmpty())
        return;
    if (playList.isFavorite()) {
        for (Song song : folder.getSongs()) {
            song.setFavorite(true);
        }
    }
    playList.addSong(folder.getSongs(), 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) Song(io.github.ryanhoo.music.data.model.Song) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Example 7 with PlayList

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

the class DBUtils method generateFavoritePlayList.

public static PlayList generateFavoritePlayList(Context context) {
    PlayList favorite = new PlayList();
    favorite.setFavorite(true);
    favorite.setName(context.getString(R.string.mp_play_list_favorite));
    return favorite;
}
Also used : PlayList(io.github.ryanhoo.music.data.model.PlayList)

Example 8 with PlayList

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

the class FolderFragment method onAction.

// Adapter Callbacks
@Override
public void onAction(View actionView, final int position) {
    final Folder folder = mAdapter.getItem(position);
    PopupMenu actionMenu = new PopupMenu(getActivity(), actionView, Gravity.END | Gravity.BOTTOM);
    actionMenu.inflate(R.menu.folders_action);
    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) {
                            mPresenter.addFolderToPlayList(folder, playList);
                        }
                    }).show(getFragmentManager().beginTransaction(), "AddToPlayList");
                    break;
                case R.id.menu_item_create_play_list:
                    PlayList playList = PlayList.fromFolder(folder);
                    EditPlayListDialogFragment.editPlayList(playList).setCallback(new EditPlayListDialogFragment.Callback() {

                        @Override
                        public void onCreated(PlayList playList) {
                        // Empty
                        }

                        @Override
                        public void onEdited(PlayList playList) {
                            mPresenter.createPlayList(playList);
                        }
                    }).show(getFragmentManager().beginTransaction(), "CreatePlayList");
                    break;
                case R.id.menu_item_refresh:
                    mUpdateIndex = position;
                    mPresenter.refreshFolder(folder);
                    break;
                case R.id.menu_item_delete:
                    mDeleteIndex = position;
                    mPresenter.deleteFolder(folder);
                    break;
            }
            return true;
        }
    });
    actionMenu.show();
}
Also used : AddToPlayListDialogFragment(io.github.ryanhoo.music.ui.playlist.AddToPlayListDialogFragment) PlayList(io.github.ryanhoo.music.data.model.PlayList) Folder(io.github.ryanhoo.music.data.model.Folder) EditPlayListDialogFragment(io.github.ryanhoo.music.ui.playlist.EditPlayListDialogFragment) PopupMenu(android.support.v7.widget.PopupMenu)

Example 9 with PlayList

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

the class FolderPresenter 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 playList) {
            mView.onPlayListCreated(playList);
        }
    });
    mSubscriptions.add(subscription);
}
Also used : PlayList(io.github.ryanhoo.music.data.model.PlayList) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Example 10 with PlayList

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

the class MusicPlayerFragment method onPlayListNowEvent.

private void onPlayListNowEvent(PlayListNowEvent event) {
    PlayList playList = event.playList;
    int playIndex = event.playIndex;
    playSong(playList, playIndex);
}
Also used : PlayList(io.github.ryanhoo.music.data.model.PlayList)

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