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