Search in sources :

Example 1 with FlexibleAdapter

use of eu.davidea.flexibleadapter.FlexibleAdapter in project FlexibleAdapter by davideas.

the class DividerItemDecoration method getItemOffsets.

/**
	 * @since 5.0.0-b4
	 */
@SuppressWarnings({ "ConstantConditions", "unchecked", "SuspiciousNameCombination" })
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView recyclerView, RecyclerView.State state) {
    int offset = (mDivider != null && withOffset ? mDivider.getIntrinsicHeight() : 0);
    if (mSectionOffset > 0 && recyclerView.getAdapter() instanceof FlexibleAdapter) {
        FlexibleAdapter flexibleAdapter = (FlexibleAdapter) recyclerView.getAdapter();
        int position = recyclerView.getChildAdapterPosition(view);
        //Only ISectionable items can finish with a gap and only if next item is a IHeader item
        if (flexibleAdapter.getItem(position) instanceof ISectionable && (flexibleAdapter.isHeader(flexibleAdapter.getItem(position + 1)) || position >= recyclerView.getAdapter().getItemCount() - 1)) {
            offset += mSectionOffset;
        }
    }
    if (Utils.getOrientation(recyclerView.getLayoutManager()) == RecyclerView.VERTICAL) {
        outRect.set(0, 0, 0, offset);
    } else {
        outRect.set(0, 0, offset, 0);
    }
}
Also used : FlexibleAdapter(eu.davidea.flexibleadapter.FlexibleAdapter) ISectionable(eu.davidea.flexibleadapter.items.ISectionable)

Aggregations

FlexibleAdapter (eu.davidea.flexibleadapter.FlexibleAdapter)1 ISectionable (eu.davidea.flexibleadapter.items.ISectionable)1