tinkoff-mobile-tech / ScrollingPagerIndicator

Pager indicator inspired by Instagram. Lightweight and easy to set up.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use it with looped RecyclerView?

lion4ik opened this issue · comments

I am using InfiniteAdapter as a wrapper for wrappedAdapter with real positions.

So I have getItemCount in my InfiniteAdapter:

override fun getItemCount(): Int = Int.MAX_VALUE

RecyclerViewAttacher expects real count. So, this attacher gets adapter from my recyclerview via getAdapter(). RecyclerViewAttacher receives an instance of InfiniteAdapter which returns Int.MAX_VALUE as itemCount and shows wrong dots count. I expect to see dots count the same as I have in my wrappedAdapter. So, I have to copy RecyclerViewAttacher to project and just change code a little, that it works. My point is that I would like to reuse most of code of this library.

So, I would suggest to change RecyclerViewAttacher in the following way:

  1. Create some delegate interface like:
interface RecyclerViewAdapterDelegate{
     fun getAdapterItemCount(): Int

     fun registerDataSetObserver(dataObserver : RecyclerView.AdapterDataObserver)

     fun unregisterDataSetObserver(dataObserver : RecyclerView.AdapterDataObserver)
}

May be we need some other methods to delegate from adapter, it's possible to add.
2) Pass it to constructor

class RecyclerViewBaseAttacher(private val adapterDelegate: RecyclerViewAdapterDelegate) {
    ....  
}
  1. This additional abstraction helps to use some different adapters.

If you don't mind such changes I can implement it and create a pull request. Of course I will write it in Java.

What do you think guys?

I've created a PR for solving my problem.

@lion4ik there is a better way to resolve this issue. Just create your own attacher for InfiniteAdapter.
You can implement ScrollingPagerIndicator.PagerAttacher and use RecyclerViewAdapterDelegate interface as you did in pull request.

@lion4ik there is a better way to resolve this issue. Just create your own attacher for InfiniteAdapter.
You can implement ScrollingPagerIndicator.PagerAttacher and use RecyclerViewAdapterDelegate interface as you did in pull request.

@Evgeny-Rogachev, yeah, but most of the code in my implementation of ScrollingPagerIndicator.PagerAttacherwill be the same as in RecyclerViewAttacher. That's why I've just wanted to reuse it.