{"id":13463655,"url":"https://github.com/mazenrashed/RxPagination","last_synced_at":"2025-03-25T09:30:58.410Z","repository":{"id":123045968,"uuid":"247791840","full_name":"mazenrashed/RxPagination","owner":"mazenrashed","description":"Implement pagination in just few lines with RxPagination ","archived":false,"fork":false,"pushed_at":"2020-05-07T00:55:27.000Z","size":159,"stargazers_count":20,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-29T16:19:25.874Z","etag":null,"topics":["pagination","recyclerview","rx","rxandroid","rxjava","rxjava2","rxkotlin","rxpagination","rxrelay"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mazenrashed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-03-16T18:44:10.000Z","updated_at":"2021-11-24T07:34:14.000Z","dependencies_parsed_at":"2024-01-16T05:38:03.321Z","dependency_job_id":"fad8bb1c-6425-4bf7-b0d6-0a8f6c6b8800","html_url":"https://github.com/mazenrashed/RxPagination","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazenrashed%2FRxPagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazenrashed%2FRxPagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazenrashed%2FRxPagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazenrashed%2FRxPagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mazenrashed","download_url":"https://codeload.github.com/mazenrashed/RxPagination/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245435066,"owners_count":20614822,"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":["pagination","recyclerview","rx","rxandroid","rxjava","rxjava2","rxkotlin","rxpagination","rxrelay"],"created_at":"2024-07-31T14:00:25.581Z","updated_at":"2025-03-25T09:30:57.908Z","avatar_url":"https://github.com/mazenrashed.png","language":"Kotlin","funding_links":[],"categories":["Android"],"sub_categories":[],"readme":"\n# RxPagination\n\n[![](https://jitpack.io/v/mazenrashed/RxPagination.svg)](https://jitpack.io/#mazenrashed/RxPagination)\n\nImplement the pagination in a few lines, \n\n![](https://media.giphy.com/media/RN2oZPyBkUKQbi1WD1/giphy.gif)\n###  Add the JitPack repository to your build file\n```groovy\nallprojects {\n    repositories {\n        ...\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\n### Add dependency\n```groovy\ndependencies {\n    implementation 'com.github.mazenrashed:RxPagination:${LAST_VERSION}'\n}\n```\n# Usage\nWe will use the car example,\n## In Your repository\nJest implement ListRepository\\\u003cT\\\u003e\n```kotlin\nclass CarRepository : ListRepository\u003cCar\u003e{\n...\n}\n```\n\nThen, you need to override getDataList(page: Int, pageSize : Int) inside the repository\n```kotlin\nclass CarRepository : ListRepository\u003cCar\u003e {  \n  \n    override fun getDataList(page: Int, pageSize : Int): Single\u003cArrayList\u003cCar\u003e\u003e {  \n        return endPoints.getCars(pageSize, page) //For Example (You need to return your data source here)\n    }  \n      \n}\n```\n\n## In The View Model\nInehet from RxPagination\\\u003cT\\\u003e\n```kotlin\nclass CarsViewModel(carsRepository: CarRepository) :  \n    RxPagination\u003cCarRepository\u003e(carsRepository, PAGE_SIZE, FIRST_PAGE) {  \n      \n    init {  \n        loadDataList()  \n    }\n    \n }\n```\nThen, you need to override onFetchDataListSubscribed,\nonFetchDataListError and onFetchDataListSuccess\n```kotlin\nclass CarsViewModel(carsRepository: CarRepository) :  \n    RxPagination\u003cCarRepository\u003e(carsRepository, PAGE_SIZE, FIRST_PAGE) {  \n      \n    init {  \n        loadDataList()  \n    }\n    \n    override fun onFetchDataListSubscribed() {  \n\t   //Start fetching data\n    }  \n  \n    override fun onFetchDataListError(throwable: Throwable) {  \n\t   \n    }  \n  \n    override fun onFetchDataListSuccess(lastLoadedList: ArrayList\u003cGithubRepository\u003e) {  \n\t  //You don't need to handle the data, but if you need it, it's available\n\t  //This lastLoadedList is the new loaded part.\n    }\n }\n```\n## In the UI (Activity or Fragment)\nTo observe the data list, use viewModel.dataList, \ndataList is a BehaviorRelay\\\u003cArrayList\\\u003cT\\\u003e\\\u003e\n```kotlin\nviewModel  \n  .dataList  \n  .observeOn(AndroidSchedulers.mainThread())  \n  .subscribe { dataList -\u003e  \n\t// notify your list adapter here \n    }\n```\n## Load and reload data\n```kotlin\nviewModel.loadDataList() //To load the more data\n\nviewModel.reloadDataList() //To reload the data\n```\n\n## Access page informations\nTo access cerrent page\n```kotlin\nviewModel.page.value //Int\n```\nTo check if you reach the last page\n```kotlin\nviewModel.isLastPage.value //Boolean\n```\n\n\n## Contributing\n\nWe welcome contributions !\n* ⇄ Pull requests and ★ Stars are always welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazenrashed%2FRxPagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmazenrashed%2FRxPagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazenrashed%2FRxPagination/lists"}