Search in sources :

Example 31 with ViewModel

use of com.simplecityapps.recycler_adapter.model.ViewModel 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(InternalIntents.META_CHANGED);
    filter.addAction(InternalIntents.REPEAT_CHANGED);
    filter.addAction(InternalIntents.SHUFFLE_CHANGED);
    filter.addAction(InternalIntents.QUEUE_CHANGED);
    filter.addAction(InternalIntents.SERVICE_CONNECTED);
    addDisposable(RxBroadcast.fromBroadcast(application, filter).startWith(new Intent(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 InternalIntents.META_CHANGED:
                    queuePagerView.updateQueuePosition(mediaManager.getQueuePosition());
                    break;
                case InternalIntents.REPEAT_CHANGED:
                case InternalIntents.SHUFFLE_CHANGED:
                case InternalIntents.QUEUE_CHANGED:
                case InternalIntents.SERVICE_CONNECTED:
                    List<ViewModel> items = Stream.of(mediaManager.getQueue()).map(queueItem -> new QueuePagerItemView(queueItem.getSong(), requestManager, settingsManager)).collect(Collectors.toList());
                    queuePagerView.loadData(items, mediaManager.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) MediaManager(com.simplecity.amp_library.playback.MediaManager) 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) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) Inject(javax.inject.Inject) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) List(java.util.List) InternalIntents(com.simplecity.amp_library.playback.constants.InternalIntents) RequestManager(com.bumptech.glide.RequestManager) Presenter(com.simplecity.amp_library.ui.common.Presenter) IntentFilter(android.content.IntentFilter) QueuePagerItemView(com.simplecity.amp_library.ui.modelviews.QueuePagerItemView) Intent(android.content.Intent) List(java.util.List)

Aggregations

ViewModel (com.simplecityapps.recycler_adapter.model.ViewModel)31 Stream (com.annimon.stream.Stream)20 List (java.util.List)20 R (com.simplecity.amp_library.R)19 View (android.view.View)18 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)18 Bundle (android.os.Bundle)17 Nullable (android.support.annotation.Nullable)17 LayoutInflater (android.view.LayoutInflater)17 RecyclerListener (com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener)17 ViewGroup (android.view.ViewGroup)16 MenuUtils (com.simplecity.amp_library.utils.MenuUtils)16 Disposable (io.reactivex.disposables.Disposable)16 PopupMenu (android.support.v7.widget.PopupMenu)15 MusicUtils (com.simplecity.amp_library.utils.MusicUtils)15 Observable (io.reactivex.Observable)15 Collections (java.util.Collections)15 UpgradeDialog (com.simplecity.amp_library.ui.dialog.UpgradeDialog)14 EmptyView (com.simplecity.amp_library.ui.modelviews.EmptyView)14 SelectableViewModel (com.simplecity.amp_library.ui.modelviews.SelectableViewModel)14