use of com.simplecity.amp_library.ui.views.PlayerView in project Shuttle by timusus.
the class PlayerPresenter method refreshCurrentTimeText.
private void refreshCurrentTimeText(long playbackTime) {
PlayerView view = getView();
if (playbackTime != this.currentPlaybackTime) {
if (view != null) {
view.currentTimeChanged(playbackTime);
}
}
this.currentPlaybackTime = playbackTime;
}
use of com.simplecity.amp_library.ui.views.PlayerView in project Shuttle by timusus.
the class PlayerPresenter method updateShuffleMode.
private void updateShuffleMode() {
PlayerView view = getView();
if (view != null) {
view.repeatChanged(MusicUtils.getRepeatMode());
view.shuffleChanged(MusicUtils.getShuffleMode());
}
}
use of com.simplecity.amp_library.ui.views.PlayerView in project Shuttle by timusus.
the class PlayerPresenter method bindView.
@Override
public void bindView(@NonNull PlayerView view) {
super.bindView(view);
updateTrackInfo();
updateShuffleMode();
updatePlaystate();
updateRepeatMode();
addDisposable(PlaybackMonitor.getInstance().getProgressObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(progress -> view.setSeekProgress((int) (progress * 1000)), error -> LogUtils.logException(TAG, "PlayerPresenter: Error updating seek progress", error)));
addDisposable(PlaybackMonitor.getInstance().getCurrentTimeObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(pos -> refreshTimeText(pos / 1000), error -> LogUtils.logException(TAG, "PlayerPresenter: Error refreshing time text", error)));
addDisposable(Flowable.interval(500, TimeUnit.MILLISECONDS).onBackpressureDrop().observeOn(AndroidSchedulers.mainThread()).subscribe(aLong -> setCurrentTimeVisibility(MusicUtils.isPlaying() || !currentPlaybackTimeVisible), error -> LogUtils.logException(TAG, "PlayerPresenter: Error emitting current time", error)));
final IntentFilter filter = new IntentFilter();
filter.addAction(MusicService.InternalIntents.META_CHANGED);
filter.addAction(MusicService.InternalIntents.QUEUE_CHANGED);
filter.addAction(MusicService.InternalIntents.PLAY_STATE_CHANGED);
filter.addAction(MusicService.InternalIntents.SHUFFLE_CHANGED);
filter.addAction(MusicService.InternalIntents.REPEAT_CHANGED);
filter.addAction(MusicService.InternalIntents.SERVICE_CONNECTED);
addDisposable(RxBroadcast.fromBroadcast(ShuttleApplication.getInstance(), filter).toFlowable(BackpressureStrategy.LATEST).observeOn(AndroidSchedulers.mainThread()).subscribe(intent -> {
final String action = intent.getAction();
if (action != null) {
switch(action) {
case MusicService.InternalIntents.META_CHANGED:
updateTrackInfo();
break;
case MusicService.InternalIntents.QUEUE_CHANGED:
updateTrackInfo();
break;
case MusicService.InternalIntents.PLAY_STATE_CHANGED:
updateTrackInfo();
updatePlaystate();
break;
case MusicService.InternalIntents.SHUFFLE_CHANGED:
updateTrackInfo();
updateShuffleMode();
break;
case MusicService.InternalIntents.REPEAT_CHANGED:
updateRepeatMode();
break;
case MusicService.InternalIntents.SERVICE_CONNECTED:
updateTrackInfo();
updatePlaystate();
updateShuffleMode();
updateRepeatMode();
break;
}
}
}, error -> LogUtils.logException(TAG, "PlayerPresenter: Error sending broadcast", error)));
}
use of com.simplecity.amp_library.ui.views.PlayerView in project Shuttle by timusus.
the class PlayerPresenter method setCurrentTimeVisibility.
private void setCurrentTimeVisibility(boolean visible) {
PlayerView view = getView();
if (visible != currentPlaybackTimeVisible) {
if (view != null) {
view.currentTimeVisibilityChanged(visible);
}
}
currentPlaybackTimeVisible = visible;
}
use of com.simplecity.amp_library.ui.views.PlayerView in project Shuttle by timusus.
the class PlayerPresenter method updateTrackInfo.
public void updateTrackInfo() {
PlayerView view = getView();
if (view != null) {
view.trackInfoChanged(MusicUtils.getSong());
view.queueChanged(MusicUtils.getQueuePosition() + 1, MusicUtils.getQueue().size());
view.currentTimeChanged(MusicUtils.getPosition() / 1000);
updateRemainingTime();
if (isFavoriteDisposable != null) {
isFavoriteDisposable.dispose();
}
isFavoriteDisposable = PlaylistUtils.isFavorite(MusicUtils.getSong()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(isFavorite -> updateFavorite((isFavorite)));
addDisposable(isFavoriteDisposable);
}
}
Aggregations