Search in sources :

Example 1 with FavourateSongEvent

use of io.hefuyi.listener.event.FavourateSongEvent in project ListenerMusicPlayer by hefuyicoder.

the class ListenerUtil method showAddPlaylistDialog.

public static void showAddPlaylistDialog(final Context context, final long[] songIds) {
    PlaylistLoader.getPlaylists(context, true).map(new Func1<List<Playlist>, Dialog>() {

        @Override
        public Dialog call(final List<Playlist> playlists) {
            final CharSequence[] chars = new CharSequence[playlists.size() + 1];
            chars[0] = context.getResources().getString(R.string.create_new_playlist);
            for (int i = 0; i < playlists.size(); i++) {
                chars[i + 1] = playlists.get(i).name;
            }
            return new MaterialDialog.Builder(context).title(R.string.add_to_playlist).items(chars).itemsCallback(new MaterialDialog.ListCallback() {

                @Override
                public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                    if (which == 0) {
                        CreatePlaylistDialog.newInstance(songIds).show(((AppCompatActivity) context).getSupportFragmentManager(), context.getString(R.string.create_new_playlist));
                        return;
                    } else if (which == 1) {
                        //我喜欢
                        int num = FavoriteSong.getInstance(context).addFavoriteSong(songIds);
                        Toast.makeText(getContext(), R.string.add_favorite_success, Toast.LENGTH_SHORT).show();
                        RxBus.getInstance().post(new FavourateSongEvent());
                        dialog.dismiss();
                        return;
                    }
                    MusicPlayer.addToPlaylist(context, songIds, playlists.get(which - 1).id);
                    RxBus.getInstance().post(new PlaylistUpdateEvent());
                    dialog.dismiss();
                }
            }).build();
        }
    }).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Dialog>() {

        @Override
        public void call(Dialog dialog) {
            dialog.show();
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) FavourateSongEvent(io.hefuyi.listener.event.FavourateSongEvent) AppCompatActivity(android.support.v7.app.AppCompatActivity) View(android.view.View) Playlist(io.hefuyi.listener.mvp.model.Playlist) PlaylistUpdateEvent(io.hefuyi.listener.event.PlaylistUpdateEvent) CreatePlaylistDialog(io.hefuyi.listener.ui.dialogs.CreatePlaylistDialog) Dialog(android.app.Dialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) List(java.util.List)

Example 2 with FavourateSongEvent

use of io.hefuyi.listener.event.FavourateSongEvent in project ListenerMusicPlayer by hefuyicoder.

the class SongsFragment method subscribeFavourateSongEvent.

private void subscribeFavourateSongEvent() {
    Subscription subscription = RxBus.getInstance().toObservable(FavourateSongEvent.class).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<FavourateSongEvent>() {

        @Override
        public void call(FavourateSongEvent event) {
            mPresenter.loadSongs(action);
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
        }
    });
    RxBus.getInstance().addSubscription(this, subscription);
}
Also used : FavourateSongEvent(io.hefuyi.listener.event.FavourateSongEvent) Subscription(rx.Subscription)

Example 3 with FavourateSongEvent

use of io.hefuyi.listener.event.FavourateSongEvent in project ListenerMusicPlayer by hefuyicoder.

the class QuickControlsFragment method onFavoriteClick.

@OnClick(R.id.heart)
public void onFavoriteClick() {
    if (mIsFavorite) {
        int num = FavoriteSong.getInstance(getContext()).removeFavoriteSong(new long[] { MusicPlayer.getCurrentAudioId() });
        if (num == 1) {
            favorite.setColor(blackWhiteColor);
            mIsFavorite = false;
            RxBus.getInstance().post(new FavourateSongEvent());
            Toast.makeText(getContext(), R.string.remove_favorite_success, Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(getContext(), R.string.remove_favorite_fail, Toast.LENGTH_SHORT).show();
        }
    } else {
        int num = FavoriteSong.getInstance(getContext()).addFavoriteSong(new long[] { MusicPlayer.getCurrentAudioId() });
        if (num == 1) {
            favorite.setColor(Color.parseColor("#E97767"));
            mIsFavorite = true;
            RxBus.getInstance().post(new FavourateSongEvent());
            Toast.makeText(getContext(), R.string.add_favorite_success, Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(getContext(), R.string.add_favorite_fail, Toast.LENGTH_SHORT).show();
        }
    }
}
Also used : FavourateSongEvent(io.hefuyi.listener.event.FavourateSongEvent) OnClick(butterknife.OnClick)

Example 4 with FavourateSongEvent

use of io.hefuyi.listener.event.FavourateSongEvent in project ListenerMusicPlayer by hefuyicoder.

the class QuickControlsFragment method subscribeFavourateSongEvent.

private void subscribeFavourateSongEvent() {
    Subscription subscription = RxBus.getInstance().toObservable(FavourateSongEvent.class).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<FavourateSongEvent>() {

        @Override
        public void call(FavourateSongEvent event) {
            mIsFavorite = FavoriteSong.getInstance(getContext()).isFavorite(MusicPlayer.getCurrentAudioId());
            if (mIsFavorite) {
                favorite.setColor(Color.parseColor("#E97767"));
            } else {
                favorite.setColor(blackWhiteColor);
            }
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
        }
    });
    RxBus.getInstance().addSubscription(this, subscription);
}
Also used : FavourateSongEvent(io.hefuyi.listener.event.FavourateSongEvent) Subscription(rx.Subscription)

Example 5 with FavourateSongEvent

use of io.hefuyi.listener.event.FavourateSongEvent in project ListenerMusicPlayer by hefuyicoder.

the class AlbumFragment method subscribeFavourateSongEvent.

private void subscribeFavourateSongEvent() {
    Subscription subscription = RxBus.getInstance().toObservable(FavourateSongEvent.class).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<FavourateSongEvent>() {

        @Override
        public void call(FavourateSongEvent event) {
            mPresenter.loadAlbums(action);
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
        }
    });
    RxBus.getInstance().addSubscription(this, subscription);
}
Also used : FavourateSongEvent(io.hefuyi.listener.event.FavourateSongEvent) Subscription(rx.Subscription)

Aggregations

FavourateSongEvent (io.hefuyi.listener.event.FavourateSongEvent)6 Subscription (rx.Subscription)4 Dialog (android.app.Dialog)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 View (android.view.View)1 OnClick (butterknife.OnClick)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 PlaylistUpdateEvent (io.hefuyi.listener.event.PlaylistUpdateEvent)1 Playlist (io.hefuyi.listener.mvp.model.Playlist)1 CreatePlaylistDialog (io.hefuyi.listener.ui.dialogs.CreatePlaylistDialog)1 List (java.util.List)1