luizgrp / SectionedRecyclerViewAdapter

An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.
MIT License
1.68k stars 372 forks source link

Can we have getItemViewTypeInSection #110

Closed yccheok closed 5 years ago

yccheok commented 6 years ago

Currently, in SectionedRecyclerViewAdapter, we already have

@Override
public int getItemViewType(int position)

I was wondering, can we have something like

public static int getItemViewTypeInSection(int itemViewType) {
    return itemViewType % VIEW_TYPE_QTY
}

One of the use case is during drag-n-move, in ItemTouchHelper.Callback (I don't want to drag-n-move non loaded item), instead of writing

@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    if (SectionedRecyclerViewAdapter.VIEW_TYPE_ITEM_LOADED != (viewHolder.getItemViewType() % Utils.VIEW_TYPE_QTY)) {
        final int dragFlags = 0;
        final int swipeFlags = 0;
        return makeMovementFlags(dragFlags, swipeFlags);
    }

I can write as

@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    if (SectionedRecyclerViewAdapter.VIEW_TYPE_ITEM_LOADED != SectionedRecyclerViewAdapter.getItemViewTypeInSection(viewHolder.getItemViewType())) {
        final int dragFlags = 0;
        final int swipeFlags = 0;
        return makeMovementFlags(dragFlags, swipeFlags);
    }

https://github.com/yccheok/SectionedRecyclerViewAdapter/commit/ee1e4bfccbff7a60bbda51cb6541b1c3f220835e

luizgrp commented 6 years ago

Sounds good 👍

luizgrp commented 6 years ago

Hi @yccheok,

We already have a method getSectionItemViewType(position), could you please call this new method getSectionItemViewTypeForAdapterViewType(viewType)?

Could you please submit a PR to merge into develop with your commit?

Thanks

yccheok commented 6 years ago

@luizgrp

Done. Hope you like my change.

https://github.com/luizgrp/SectionedRecyclerViewAdapter/pull/129

luizgrp commented 5 years ago

Closing as it's currently in develop.