Search in sources :

Example 1 with PlaylistUpdateEvent

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

the class CreatePlaylistDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new MaterialDialog.Builder(getActivity()).title(R.string.create_new_playlist).positiveText(R.string.create).negativeText(R.string.cancel).input(getString(R.string.playlist_name), "", false, new MaterialDialog.InputCallback() {

        @Override
        public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
            long[] songs = getArguments().getLongArray("songs");
            long playistId = MusicPlayer.createPlaylist(getActivity(), input.toString());
            if (playistId != -1) {
                if (songs != null && songs.length != 0) {
                    MusicPlayer.addToPlaylist(getActivity(), songs, playistId);
                } else {
                    Toast.makeText(getActivity(), R.string.create_playlist_success, Toast.LENGTH_SHORT).show();
                }
                RxBus.getInstance().post(new PlaylistUpdateEvent());
            } else {
                Toast.makeText(getActivity(), R.string.create_playlist_fail, Toast.LENGTH_SHORT).show();
            }
        }
    }).build();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) PlaylistUpdateEvent(io.hefuyi.listener.event.PlaylistUpdateEvent) NonNull(android.support.annotation.NonNull) NonNull(android.support.annotation.NonNull)

Example 2 with PlaylistUpdateEvent

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

the class PlaylistDetailFragment method onViewCreated.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ButterKnife.bind(this, view);
    ATE.apply(this, ATEUtil.getATEKey(getActivity()));
    if (getArguments().getBoolean("transition")) {
        playlistArt.setTransitionName(getArguments().getString("transition_name"));
    }
    recyclerView.setAdapter(mAdapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST, false));
    setupToolbar();
    mPresenter.loadPlaylistSongs(playlistID);
    mPresenter.loadPlaylistArt(firstAlbumID);
    //监听歌曲删除事件,修改歌单封面
    mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {

        @Override
        public void onItemRangeRemoved(int positionStart, int itemCount) {
            super.onItemRangeRemoved(positionStart, itemCount);
            RxBus.getInstance().post(new PlaylistUpdateEvent());
            if (positionStart == 0) {
                List<Song> songs = mAdapter.getSongList();
                if (songs.size() == 0) {
                    firstAlbumID = -1;
                } else {
                    firstAlbumID = songs.get(0).albumId;
                }
                mPresenter.loadPlaylistArt(firstAlbumID);
            }
        }
    });
    subscribeMetaChangedEvent();
}
Also used : PlaylistUpdateEvent(io.hefuyi.listener.event.PlaylistUpdateEvent) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(io.hefuyi.listener.widget.DividerItemDecoration) TargetApi(android.annotation.TargetApi)

Example 3 with PlaylistUpdateEvent

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

the class PlaylistDetailFragment method showRenamePlaylistDialog.

private void showRenamePlaylistDialog(String oldName) {
    new MaterialDialog.Builder(getActivity()).title(R.string.rename_playlist).positiveText("确定").negativeText(R.string.cancel).input(null, oldName, false, new MaterialDialog.InputCallback() {

        @Override
        public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
            MusicPlayer.renamePlaylist(getActivity(), playlistID, input.toString());
            collapsingToolbarLayout.setTitle(input.toString());
            playlistName = input.toString();
            RxBus.getInstance().post(new PlaylistUpdateEvent());
            Toast.makeText(getActivity(), R.string.rename_playlist_success, Toast.LENGTH_SHORT).show();
        }
    }).show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) PlaylistUpdateEvent(io.hefuyi.listener.event.PlaylistUpdateEvent) NonNull(android.support.annotation.NonNull)

Example 4 with PlaylistUpdateEvent

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

the class PlaylistFragment method subscribePlaylistUpdateEvent.

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

        @Override
        public void call(PlaylistUpdateEvent event) {
            mPresenter.loadPlaylist();
        }
    }, new Action1<Throwable>() {

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

Example 5 with PlaylistUpdateEvent

use of io.hefuyi.listener.event.PlaylistUpdateEvent 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)

Aggregations

PlaylistUpdateEvent (io.hefuyi.listener.event.PlaylistUpdateEvent)5 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3 NonNull (android.support.annotation.NonNull)2 List (java.util.List)2 TargetApi (android.annotation.TargetApi)1 Dialog (android.app.Dialog)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 FavourateSongEvent (io.hefuyi.listener.event.FavourateSongEvent)1 Playlist (io.hefuyi.listener.mvp.model.Playlist)1 CreatePlaylistDialog (io.hefuyi.listener.ui.dialogs.CreatePlaylistDialog)1 DividerItemDecoration (io.hefuyi.listener.widget.DividerItemDecoration)1 Subscription (rx.Subscription)1