Search in sources :

Example 11 with ViewModel

use of com.simplecityapps.recycler_adapter.model.ViewModel in project Shuttle by timusus.

the class SuggestedFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (recyclerView == null) {
        recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_suggested, container, false);
        recyclerView.addItemDecoration(new SuggestedDividerDecoration(getResources()));
        recyclerView.setRecyclerListener(new RecyclerListener());
        int spanCount = ShuttleUtils.isTablet() ? 12 : 6;
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), spanCount);
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                if (!adapter.items.isEmpty() && position >= 0) {
                    ViewModel item = adapter.items.get(position);
                    if (item instanceof HorizontalRecyclerView || item instanceof SuggestedHeaderView || (item instanceof AlbumView && item.getViewType() == ViewType.ALBUM_LIST) || (item instanceof AlbumView && item.getViewType() == ViewType.ALBUM_LIST_SMALL) || item instanceof EmptyView) {
                        return spanCount;
                    }
                    if (item instanceof AlbumView && item.getViewType() == ViewType.ALBUM_CARD_LARGE) {
                        return 3;
                    }
                }
                return 2;
            }
        });
        recyclerView.setLayoutManager(gridLayoutManager);
    }
    if (recyclerView.getAdapter() != adapter) {
        recyclerView.setAdapter(adapter);
    }
    return recyclerView;
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) SuggestedHeaderView(com.simplecity.amp_library.ui.modelviews.SuggestedHeaderView) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) SuggestedDividerDecoration(com.simplecity.amp_library.ui.views.SuggestedDividerDecoration) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) SuppressLint(android.annotation.SuppressLint) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView)

Example 12 with ViewModel

use of com.simplecityapps.recycler_adapter.model.ViewModel in project Shuttle by timusus.

the class BaseDetailFragment method getAlbumViewModels.

@NonNull
@Override
public List<ViewModel> getAlbumViewModels(List<Album> albums) {
    if (albums.isEmpty()) {
        return Collections.emptyList();
    }
    List<ViewModel> items = new ArrayList<>();
    if (setHorizontalItemsDisposable != null) {
        setHorizontalItemsDisposable.dispose();
    }
    setHorizontalItemsDisposable = horizontalRecyclerView.setItems(Stream.of(albums).map(album -> {
        HorizontalAlbumView horizontalAlbumView = new HorizontalAlbumView(album, requestManager);
        horizontalAlbumView.setClickListener(BaseDetailFragment.this);
        horizontalAlbumView.showYear(true);
        return horizontalAlbumView;
    }).collect(Collectors.toList()));
    items.add(new SubheaderView(StringUtils.makeAlbumsLabel(getContext(), albums.size())));
    items.add(horizontalRecyclerView);
    return items;
}
Also used : R(com.simplecity.amp_library.R) CompletionListUpdateCallbackAdapter(com.simplecityapps.recycler_adapter.adapter.CompletionListUpdateCallbackAdapter) Bundle(android.os.Bundle) SongView(com.simplecity.amp_library.ui.modelviews.SongView) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) ImageView(android.widget.ImageView) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) Random(java.util.Random) Drawable(android.graphics.drawable.Drawable) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) OnClick(butterknife.OnClick) BindView(butterknife.BindView) ColorStateList(android.content.res.ColorStateList) Song(com.simplecity.amp_library.model.Song) Aesthetic(com.afollestad.aesthetic.Aesthetic) Optional(com.annimon.stream.Optional) Priority(com.bumptech.glide.Priority) RequestManager(com.bumptech.glide.RequestManager) HorizontalAlbumView(com.simplecity.amp_library.ui.modelviews.HorizontalAlbumView) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) View(android.view.View) ResourceUtils(com.simplecity.amp_library.utils.ResourceUtils) Schedulers(io.reactivex.schedulers.Schedulers) ViewCompat(android.support.v4.view.ViewCompat) Transition(android.transition.Transition) Unbinder(butterknife.Unbinder) ActionBarUtils(com.simplecity.amp_library.utils.ActionBarUtils) LogUtils(com.simplecity.amp_library.utils.LogUtils) ContextualToolbarHelper(com.simplecity.amp_library.utils.ContextualToolbarHelper) FloatingActionButton(android.support.design.widget.FloatingActionButton) SortManager(com.simplecity.amp_library.utils.SortManager) ObjectAnimator(android.animation.ObjectAnimator) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) ArtworkProvider(com.simplecity.amp_library.model.ArtworkProvider) ViewGroup(android.view.ViewGroup) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ContextualToolbarHost(com.simplecity.amp_library.ui.views.ContextualToolbarHost) Nullable(android.support.annotation.Nullable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Album(com.simplecity.amp_library.model.Album) TypefaceManager(com.simplecity.amp_library.utils.TypefaceManager) Stream(com.annimon.stream.Stream) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) ButterKnife(butterknife.ButterKnife) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) DrawerLockManager(com.simplecity.amp_library.ui.drawer.DrawerLockManager) TransitionListenerAdapter(com.simplecity.amp_library.ui.fragments.TransitionListenerAdapter) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) NonNull(android.support.annotation.NonNull) StringUtils(com.simplecity.amp_library.utils.StringUtils) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) AnimationUtils(android.view.animation.AnimationUtils) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) AnimatorSet(android.animation.AnimatorSet) Observable(io.reactivex.Observable) UpgradeDialog(com.simplecity.amp_library.ui.dialog.UpgradeDialog) PlaceholderProvider(com.simplecity.amp_library.utils.PlaceholderProvider) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) Rx.distinctToMainThread(com.afollestad.aesthetic.Rx.distinctToMainThread) SharedElementCallback(android.support.v4.app.SharedElementCallback) AlwaysCrossFade(com.simplecity.amp_library.glide.utils.AlwaysCrossFade) TaggerDialog(com.simplecity.amp_library.tagger.TaggerDialog) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) SubheaderView(com.simplecity.amp_library.ui.modelviews.SubheaderView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) TimeUnit(java.util.concurrent.TimeUnit) RecyclerView(android.support.v7.widget.RecyclerView) CustomCollapsingToolbarLayout(android.support.design.widget.CustomCollapsingToolbarLayout) Glide(com.bumptech.glide.Glide) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView) Toolbar(android.support.v7.widget.Toolbar) Pair(android.support.v4.util.Pair) TransitionInflater(android.transition.TransitionInflater) BaseFragment(com.simplecity.amp_library.ui.fragments.BaseFragment) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) HorizontalAlbumView(com.simplecity.amp_library.ui.modelviews.HorizontalAlbumView) SubheaderView(com.simplecity.amp_library.ui.modelviews.SubheaderView) ArrayList(java.util.ArrayList) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) NonNull(android.support.annotation.NonNull)

Example 13 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(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)

Example 14 with ViewModel

use of com.simplecityapps.recycler_adapter.model.ViewModel in project Shuttle by timusus.

the class GridDividerDecoration method getItemOffsets.

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if (!(parent.getLayoutManager() instanceof GridLayoutManager)) {
        throw new IllegalStateException("GridDividerDecoration can only be used with GridLayoutManager");
    }
    int spanCount = ((GridLayoutManager) parent.getLayoutManager()).getSpanCount();
    int position = parent.getChildAdapterPosition(view);
    if (position < 0) {
        return;
    }
    int spanIndex = ((GridLayoutManager) parent.getLayoutManager()).getSpanSizeLookup().getSpanIndex(position, spanCount);
    int groupIndex = ((GridLayoutManager) parent.getLayoutManager()).getSpanSizeLookup().getSpanGroupIndex(position, spanCount);
    RecyclerView.Adapter adapter = parent.getAdapter();
    if (adapter instanceof ViewModelAdapter) {
        ViewModel viewModel = ((ViewModelAdapter) adapter).items.get(position);
        // in which case we add bottom spacing if includeEdge is true)
        if (viewModel.getSpanSize(spanCount) == spanCount) {
            if (includeEdge && groupIndex == 0) {
                outRect.bottom = spacing;
            }
            return;
        }
    }
    if (includeEdge) {
        outRect.left = spacing - spanIndex * spacing / spanCount;
        outRect.right = (spanIndex + 1) * spacing / spanCount;
        if (groupIndex == 0) {
            outRect.top = spacing;
        }
        outRect.bottom = spacing;
    } else {
        outRect.left = spanIndex * spacing / spanCount;
        outRect.right = spacing - (spanIndex + 1) * spacing / spanCount;
        if (groupIndex > 0) {
            outRect.top = spacing;
        }
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter)

Example 15 with ViewModel

use of com.simplecityapps.recycler_adapter.model.ViewModel in project Shuttle by timusus.

the class ViewModelAdapter method moveItem.

/**
 * Moves an item from {@param fromPosition} to {@param toPosition}
 *
 * @param fromPosition int
 * @param toPosition   int
 */
public void moveItem(int fromPosition, int toPosition) {
    final ViewModel model = items.remove(fromPosition);
    items.add(toPosition, model);
    notifyItemMoved(fromPosition, toPosition);
}
Also used : ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel)

Aggregations

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