Search in sources :

Example 1 with PlayerView

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;
}
Also used : PlayerView(com.simplecity.amp_library.ui.views.PlayerView)

Example 2 with PlayerView

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());
    }
}
Also used : PlayerView(com.simplecity.amp_library.ui.views.PlayerView)

Example 3 with PlayerView

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)));
}
Also used : Context(android.content.Context) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) LyricsDialog(com.simplecity.amp_library.lyrics.LyricsDialog) NonNull(android.support.annotation.NonNull) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Inject(javax.inject.Inject) Song(com.simplecity.amp_library.model.Song) Flowable(io.reactivex.Flowable) BiographyDialog(com.simplecity.amp_library.ui.dialog.BiographyDialog) Schedulers(io.reactivex.schedulers.Schedulers) UpgradeDialog(com.simplecity.amp_library.ui.dialog.UpgradeDialog) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) TaggerDialog(com.simplecity.amp_library.tagger.TaggerDialog) LogUtils(com.simplecity.amp_library.utils.LogUtils) BackpressureStrategy(io.reactivex.BackpressureStrategy) ShareDialog(com.simplecity.amp_library.ui.dialog.ShareDialog) IntentFilter(android.content.IntentFilter) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) PlayerView(com.simplecity.amp_library.ui.views.PlayerView) Disposable(io.reactivex.disposables.Disposable) MusicService(com.simplecity.amp_library.playback.MusicService) PlaybackMonitor(com.simplecity.amp_library.playback.PlaybackMonitor) Activity(android.app.Activity) IntentFilter(android.content.IntentFilter)

Example 4 with PlayerView

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;
}
Also used : PlayerView(com.simplecity.amp_library.ui.views.PlayerView)

Example 5 with PlayerView

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);
    }
}
Also used : Context(android.content.Context) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) LyricsDialog(com.simplecity.amp_library.lyrics.LyricsDialog) NonNull(android.support.annotation.NonNull) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) Inject(javax.inject.Inject) Song(com.simplecity.amp_library.model.Song) Flowable(io.reactivex.Flowable) BiographyDialog(com.simplecity.amp_library.ui.dialog.BiographyDialog) Schedulers(io.reactivex.schedulers.Schedulers) UpgradeDialog(com.simplecity.amp_library.ui.dialog.UpgradeDialog) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) TaggerDialog(com.simplecity.amp_library.tagger.TaggerDialog) LogUtils(com.simplecity.amp_library.utils.LogUtils) BackpressureStrategy(io.reactivex.BackpressureStrategy) ShareDialog(com.simplecity.amp_library.ui.dialog.ShareDialog) IntentFilter(android.content.IntentFilter) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) PlayerView(com.simplecity.amp_library.ui.views.PlayerView) Disposable(io.reactivex.disposables.Disposable) MusicService(com.simplecity.amp_library.playback.MusicService) PlaybackMonitor(com.simplecity.amp_library.playback.PlaybackMonitor) Activity(android.app.Activity) PlayerView(com.simplecity.amp_library.ui.views.PlayerView)

Aggregations

PlayerView (com.simplecity.amp_library.ui.views.PlayerView)5 Activity (android.app.Activity)2 Context (android.content.Context)2 IntentFilter (android.content.IntentFilter)2 NonNull (android.support.annotation.NonNull)2 RxBroadcast (com.cantrowitz.rxbroadcast.RxBroadcast)2 ShuttleApplication (com.simplecity.amp_library.ShuttleApplication)2 LyricsDialog (com.simplecity.amp_library.lyrics.LyricsDialog)2 Song (com.simplecity.amp_library.model.Song)2 MusicService (com.simplecity.amp_library.playback.MusicService)2 PlaybackMonitor (com.simplecity.amp_library.playback.PlaybackMonitor)2 TaggerDialog (com.simplecity.amp_library.tagger.TaggerDialog)2 BiographyDialog (com.simplecity.amp_library.ui.dialog.BiographyDialog)2 ShareDialog (com.simplecity.amp_library.ui.dialog.ShareDialog)2 UpgradeDialog (com.simplecity.amp_library.ui.dialog.UpgradeDialog)2 LogUtils (com.simplecity.amp_library.utils.LogUtils)2 MusicUtils (com.simplecity.amp_library.utils.MusicUtils)2 PlaylistUtils (com.simplecity.amp_library.utils.PlaylistUtils)2 SettingsManager (com.simplecity.amp_library.utils.SettingsManager)2 ShuttleUtils (com.simplecity.amp_library.utils.ShuttleUtils)2