0

Is there any way to signal an Observable to produce more data?

I have a buffered Observable that produces 10 items and i want it to continue producing more items only when i want to.

To be more specific, i have an infinite scrolling Recycler View, i want to produce more items only when i continue scrolling to the end.

  • https://stackoverflow.com/questions/26543131/how-to-implement-endless-list-with-recyclerview this is the main idea, simply add your logic to the `onScrolled` event – MatPag Dec 11 '17 at 20:58
  • Possible duplicate of [How to implement endless list with RecyclerView?](https://stackoverflow.com/questions/26543131/how-to-implement-endless-list-with-recyclerview) – mschmidt Dec 11 '17 at 21:41

2 Answers2

0

Assuming you have already some sort of a back-pressured data source.

You can use request(n) to let your data source know that you are ready for more items.

elmorabea
  • 3,243
  • 1
  • 14
  • 20
0

What you can do is have an Observer that emits page scrool events, let's call it paginator.

On each emission you can switch to another observer that brings more data,

            paginator
                    .onBackpressureDrop()
                    .map { lastVisibleIndex -> (lastVisibleIndex + 2) / PAGE_SIZE + 1 }
                    .distinct()
                    .concatMap { page -> getCollectionsObservable(page, pageSize)
                    }
                    .subscribeWith(GetCollectionObserver())
    )
}
Calin
  • 6,661
  • 7
  • 49
  • 80