use of io.github.ryanhoo.music.data.model.Song in project StylishMusicPlayer by ryanhoo.
the class MusicPlayerFragment method onFavoriteToggleAction.
@OnClick(R.id.button_favorite_toggle)
public void onFavoriteToggleAction(View view) {
if (mPlayer == null)
return;
Song currentSong = mPlayer.getPlayingSong();
if (currentSong != null) {
view.setEnabled(false);
mPresenter.setSongAsFavorite(currentSong, !currentSong.isFavorite());
}
}
use of io.github.ryanhoo.music.data.model.Song in project StylishMusicPlayer by ryanhoo.
the class Player method playNext.
@Override
public boolean playNext() {
isPaused = false;
boolean hasNext = mPlayList.hasNext(false);
if (hasNext) {
Song next = mPlayList.next();
play();
notifyPlayNext(next);
return true;
}
return false;
}
use of io.github.ryanhoo.music.data.model.Song in project StylishMusicPlayer by ryanhoo.
the class Player method onCompletion.
// Listeners
@Override
public void onCompletion(MediaPlayer mp) {
Song next = null;
// There is only one limited play mode which is list, player should be stopped when hitting the list end
if (mPlayList.getPlayMode() == PlayMode.LIST && mPlayList.getPlayingIndex() == mPlayList.getNumOfSongs() - 1) {
// In the end of the list
// Do nothing, just deliver the callback
} else if (mPlayList.getPlayMode() == PlayMode.SINGLE) {
next = mPlayList.getCurrentSong();
play();
} else {
boolean hasNext = mPlayList.hasNext(true);
if (hasNext) {
next = mPlayList.next();
play();
}
}
notifyComplete(next);
}
use of io.github.ryanhoo.music.data.model.Song in project StylishMusicPlayer by ryanhoo.
the class AllLocalMusicFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
mAdapter = new LocalMusicAdapter(getActivity(), null);
mAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(int position) {
Song song = mAdapter.getItem(position);
RxBus.getInstance().post(new PlaySongEvent(song));
}
});
recyclerView.setAdapter(mAdapter);
recyclerView.addItemDecoration(new DefaultDividerDecoration());
fastScroller.setRecyclerView(recyclerView);
new LocalMusicPresenter(AppRepository.getInstance(), this).subscribe();
}
use of io.github.ryanhoo.music.data.model.Song in project StylishMusicPlayer by ryanhoo.
the class FolderPresenter method refreshFolder.
@Override
public void refreshFolder(final Folder folder) {
Subscription subscription = Observable.just(FileUtils.musicFiles(new File(folder.getPath()))).flatMap(new Func1<List<Song>, Observable<Folder>>() {
@Override
public Observable<Folder> call(List<Song> songs) {
folder.setSongs(songs);
folder.setNumOfSongs(songs.size());
return mRepository.update(folder);
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<Folder>() {
@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(Folder folder) {
mView.onFolderUpdated(folder);
}
});
mSubscriptions.add(subscription);
}
Aggregations