1

I'm using Android Paging Library, and probably don't use it 100% correct.

I have a RecyclerView and a SnapHelper to basically implement a ViewPager. My pages are per date, e.g. 2019-03-21, so there can be infinite amount of pages. What I implemented is a ItemKeyedDataSource<String,String> which has the date as its param, and on loadAfter and loadBefore, all I do is add/sub a day.

This currently works just fine. If, for example, I load 2019-03-21, then I can easily cycle to its neighbors 2019-03-20 and 2019-03-22.

However, I'd like to add a feature to load a specific date, and then scroll there. Using PositionalDataSource doesn't sound good either, since I can't say there's a finite count of items in my list.

I feel like I'm doing it wrong. Just not really sure what. Also, if there's another way that doesn't include paging (sounds reasonable, since my paging is just doing some calculations but doesn't retrieve data), that's good too.

Doron Sagi
  • 79
  • 1
  • 6

1 Answers1

0

Well, I went for the alternative approach. I'm using a regular list and adapter. I'm using a list with padding for both sides (a list of 50 dates, while the initial date is at index 24), and when reaching index 10 or 40 (depending if we go up or down) I'm calculating a new list and post it instead of the old one. It looks like an infinite list and everything looks good enough, so it works for me.

If anyone wants more details, please comment and I'll try to help.

Doron Sagi
  • 79
  • 1
  • 6