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();
}
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();
}
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();
}
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);
}
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();
}
});
}
Aggregations