{"id":19281809,"url":"https://github.com/adevintaspain/rxpager","last_synced_at":"2025-04-22T01:31:11.383Z","repository":{"id":94696040,"uuid":"65395895","full_name":"AdevintaSpain/RxPager","owner":"AdevintaSpain","description":"RxPager is an Android library that helps handling paginated results in a reactive way","archived":false,"fork":false,"pushed_at":"2018-10-31T06:39:08.000Z","size":168,"stargazers_count":56,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T17:53:40.503Z","etag":null,"topics":["android-library","java","pager","pageradapter","paginated-results","reactivex","rxjava2","rxpager"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AdevintaSpain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-10T15:54:07.000Z","updated_at":"2021-04-08T20:19:30.000Z","dependencies_parsed_at":"2023-05-12T07:15:46.817Z","dependency_job_id":null,"html_url":"https://github.com/AdevintaSpain/RxPager","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdevintaSpain%2FRxPager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdevintaSpain%2FRxPager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdevintaSpain%2FRxPager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdevintaSpain%2FRxPager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AdevintaSpain","download_url":"https://codeload.github.com/AdevintaSpain/RxPager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250161987,"owners_count":21385019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android-library","java","pager","pageradapter","paginated-results","reactivex","rxjava2","rxpager"],"created_at":"2024-11-09T21:24:18.754Z","updated_at":"2025-04-22T01:31:11.374Z","avatar_url":"https://github.com/AdevintaSpain.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[ ![Download](https://api.bintray.com/packages/schibstedspain/maven/rxpager/images/download.svg) ](https://bintray.com/schibstedspain/maven/rxpager/_latestVersion)\n# RxPager\nRxPager is an Android library that helps handling paginated results in a reactive way\n\nIs based on [this gist](https://gist.github.com/mttkay/24881a0ce986f6ec4b4d) from [@mttkay](https://gist.github.com/mttkay)\n\n##Download\nGrab the latest version from jCenter:\n\n```gradle\ndependencies {\n  compile 'com.schibstedspain.android:rxpager:2.0.0'\n}\n```\n\n##Creation\n`Pager pager = new Pager(initialPageToken, (oldPageToken, pageResult) -\u003e pageResult.getNextPageToken(), token -\u003e getPage(token) )`\n\nor if you want to use offset instead of token:\n\n`Pager pager = new Pager(0, (offset, pageResult) -\u003e offset + pageResult.size(), offset -\u003e getPageWithOffset(offset)`\n\nThe first 2 parameter are like rxjava [scan](http://reactivex.io/documentation/operators/scan.html).\n\nThe third parameter is a Func1 wich returns an Observable, is your repository/datasource call, and **you** are responsible to set subscribeOn() to this observable if you want it to be executed out of the main thread.\n\n##Usage\nTo get the content, just subscribe to: `pager.getPageObservable()`\nIt will call onNext with the first page, and will continue giving to you the next pages when you call `pager.next()` and `complete` when the returned page have `null`as nextPageToken\n\nTo know if its loading, there is another observable available: `pager.getIsLoadingObservable()`\nand last, there is `pager.hasNext()` wich returns a Boolean.\n\n##Common data types\nThere is available a POJO called: TokenPage\n\n`TokenPage(String nextPageToken, List\u003cITEM\u003e results)`\nbeing ITEM the type of your elements in the list.\n\n##Example\nThis library includes tests to describe the behavior and also a Sample, in order to show you how it works I'll take the code from the Sample MainActivity.\n```java\npublic class MainActivity extends AppCompatActivity {\n  private final CompositeSubscription compositeSubscription = new CompositeSubscription();\n\n  @Override\n  protected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n\n    DataSource dataSource = new DataSource();\n    Pager\u003cTokenPage\u003cString\u003e, String\u003e pager = new Pager\u003c\u003e(\n        DataSource.FIRST_PAGE_TOKEN,\n        (oldToken, tokenPage) -\u003e tokenPage.getNextPageToken(),\n        dataSource::getPage);\n\n    Adapter adapter = new Adapter();\n    MainActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.main_activity);\n    binding.list.setLayoutManager(new LinearLayoutManager(this));\n    binding.list.setAdapter(adapter);\n    binding.list.addOnScrollListener(new OnScrollToBottomListener(pager::next));\n\n    Subscription pageSubscription = pager.getPageObservable()\n        .map(TokenPage::getResults)\n        .observeOn(AndroidSchedulers.mainThread())\n        .subscribe(adapter::addItems);\n    compositeSubscription.add(pageSubscription);\n\n    Subscription loadingSubscription = pager.getIsLoadingObservable()\n        .observeOn(AndroidSchedulers.mainThread())\n        .subscribe(adapter::setIsLoading);\n    compositeSubscription.add(loadingSubscription);\n  }\n\n  @Override\n  protected void onDestroy() {\n    compositeSubscription.clear();\n    super.onDestroy();\n  }\n}\n```\n\n# License\n\n```\nCopyright 2016 Schibsted Classified Media Spain S.L.\n\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadevintaspain%2Frxpager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadevintaspain%2Frxpager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadevintaspain%2Frxpager/lists"}