Skip to content

carousell/ConcatAdapterExtension

Repository files navigation

ConcatAdapterExtension

CircleCI

Extension for ConcatAdapter usage, now support SpanSizeLookup and ItemDecoration (only for spacing) feature.

Install

Add Jitpack repository to your root build.grable:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

Then add dependency in your module build.gradle:

dependencies {
  implementation 'com.github.carousell:ConcatAdapterExtension:1.1.0'
}

Usage

SpanSizeLookup

Let all of your child Adapter extends SpanSizeLookupOwner and link to the SpanSizeLookup you want to have for each Adapter. And then generate ConcatSpanSizeLookup by your ConcatAdapter and max span count.

val adapter = ConcatAdapter()
val layoutManager = GridLayoutManager(this, spanCount, GridLayoutManager.VERTICAL, false)
layoutManager.spanSizeLookup = ConcatSpanSizeLookup(spanCount) { adapter.adapters }
recyclerView.layoutManager = layoutManager

ItemDecoration

Let all of your child Adapter extends ItemDecorationOwner and link to the ItemDecoration you want to have for each Adapter. And then generate ConcatItemDecoration by your ConcatAdapter.

val adapter = ConcatAdapter()
recyclerView.addItemDecoration(ConcatItemDecoration { adapter.adapters })

Also please noted if you want to get the position of view inside Adapter, you should call getBindingAdapterPosition instead of getChildAdapterPosition because ConcatAdapter will be the middle layer and the position is not expected.

// This will not get the correct index.
final int adapterPosition = parent.getChildAdapterPosition(view);

// Please use this instead
final RecyclerView.ViewHolder holder = parent.getChildViewHolder(view);
final int adapterPosition = holder.getBindingAdapterPosition();

Go to ./app module for more information.

Contributing

Thank you for being interested in contributing to this project. Check out the CONTRIBUTING document for more info.

About

Carousell

ConcatAdapterExtension is created and maintained by Carousell. Help us improve this project! We'd love the feedback from you.

We're hiring! Find out more at http://careers.carousell.com/

License

ConcatAdapterExtension is released under Apache License 2.0. See LICENSE for more details.