Search in sources :

Example 1 with QueuePagerView

use of com.simplecity.amp_library.ui.views.QueuePagerView in project Shuttle by timusus.

the class QueuePagerPresenter method bindView.

@Override
public void bindView(@NonNull QueuePagerView view) {
    super.bindView(view);
    IntentFilter filter = new IntentFilter();
    filter.addAction(MusicService.InternalIntents.META_CHANGED);
    filter.addAction(MusicService.InternalIntents.REPEAT_CHANGED);
    filter.addAction(MusicService.InternalIntents.SHUFFLE_CHANGED);
    filter.addAction(MusicService.InternalIntents.QUEUE_CHANGED);
    filter.addAction(MusicService.InternalIntents.SERVICE_CONNECTED);
    addDisposable(RxBroadcast.fromBroadcast(ShuttleApplication.getInstance(), filter).startWith(new Intent(MusicService.InternalIntents.QUEUE_CHANGED)).toFlowable(BackpressureStrategy.LATEST).observeOn(AndroidSchedulers.mainThread()).subscribe(intent -> {
        final String action = intent.getAction();
        QueuePagerView queuePagerView = getView();
        if (queuePagerView == null) {
            return;
        }
        if (action != null) {
            switch(action) {
                case MusicService.InternalIntents.META_CHANGED:
                    queuePagerView.updateQueuePosition(MusicUtils.getQueuePosition());
                    break;
                case MusicService.InternalIntents.REPEAT_CHANGED:
                case MusicService.InternalIntents.SHUFFLE_CHANGED:
                case MusicService.InternalIntents.QUEUE_CHANGED:
                case MusicService.InternalIntents.SERVICE_CONNECTED:
                    List<ViewModel> items = Stream.of(MusicUtils.getQueue()).map(song -> new QueuePagerItemView(song, requestManager)).collect(Collectors.toList());
                    queuePagerView.loadData(items, MusicUtils.getQueuePosition());
                    break;
            }
        }
    }));
}
Also used : QueuePagerItemView(com.simplecity.amp_library.ui.modelviews.QueuePagerItemView) BackpressureStrategy(io.reactivex.BackpressureStrategy) Collectors(com.annimon.stream.Collectors) Stream(com.annimon.stream.Stream) QueuePagerView(com.simplecity.amp_library.ui.views.QueuePagerView) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) NonNull(android.support.annotation.NonNull) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) Inject(javax.inject.Inject) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) List(java.util.List) RequestManager(com.bumptech.glide.RequestManager) MusicService(com.simplecity.amp_library.playback.MusicService) IntentFilter(android.content.IntentFilter) QueuePagerView(com.simplecity.amp_library.ui.views.QueuePagerView) QueuePagerItemView(com.simplecity.amp_library.ui.modelviews.QueuePagerItemView) Intent(android.content.Intent) List(java.util.List)

Aggregations

Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 NonNull (android.support.annotation.NonNull)1 Collectors (com.annimon.stream.Collectors)1 Stream (com.annimon.stream.Stream)1 RequestManager (com.bumptech.glide.RequestManager)1 RxBroadcast (com.cantrowitz.rxbroadcast.RxBroadcast)1 ShuttleApplication (com.simplecity.amp_library.ShuttleApplication)1 MusicService (com.simplecity.amp_library.playback.MusicService)1 QueuePagerItemView (com.simplecity.amp_library.ui.modelviews.QueuePagerItemView)1 QueuePagerView (com.simplecity.amp_library.ui.views.QueuePagerView)1 MusicUtils (com.simplecity.amp_library.utils.MusicUtils)1 ViewModel (com.simplecityapps.recycler_adapter.model.ViewModel)1 BackpressureStrategy (io.reactivex.BackpressureStrategy)1 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)1 List (java.util.List)1 Inject (javax.inject.Inject)1