PaginationFast is a utility library for Android that provides a fast and generic solution for pagination using the Paging 3 library. It simplifies the process of implementing pagination in your Android app by abstracting away the complexity of managing data loading and pagination.
- Generic Pagination: Easily paginate any type of data fetched from a remote data source.
- Customizable Configuration: Configure page size and enable/disable placeholders according to your requirements.
- Simple Integration: Integrate pagination functionality into your app with just a few lines of code.
To integrate PaginationFast into your Android project, follow these steps:
-
Add the JitPack repository to your project's
build.gradle
file:allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
-
Add the dependency to your app's
build.gradle
file:dependencies { implementation("com.github.joaoeudes7:Pagination-Fast:Tag") }
Replace
YourUsername
with your GitHub username andTag
with the version tag of the library you want to use. -
Sync your project to fetch the new dependency.
To use PaginationFast in your app, follow these steps:
-
Create a
PagingSource
byGenericPagingSource
and implement theonFetchData
lambda function to fetch data from your backend.class ViewModelExample( private val useCase: ExamplePaginationUseCase ) : ViewModel() { var itemsPagination by mutableStateOf(flowOf(PagingData.empty<Any>())) private set fun fetchData() = viewModelScope.launch { useCase(search = null) .catch { // handle exception } .collect { itemsPagination = it.cachedIn(viewModelScope) } } } class ExamplePaginationUseCase { @VisibleForTesting fun getPagingSource(search: String?) = GenericPagingSource( enablePlaceholders = false, itemPerPage = 20, defaultFirstPage = 1, onFetchData = { fakeFetchFromRepository(search, it.page, it.itemsPerPage) } ) operator fun invoke(search: String?) = flow { val pagingSource = getPagingSource(search) emit(pagingSource.getPagingDataFlow()) } } fun fakeFetchFromRepository(search: String?, pag: Int, itemsPerPage: Int): PaginationItems<Any> { return PaginationItems( items = listOf(), pagination = PaginationRes( totalItems = 1, totalPages = 1 ) ) }
This library is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Feel free to open an issue or submit a pull request for any improvements or bug fixes.
PaginationFast is inspired by Paging 3 library and aims to provide a simplified and generic approach to pagination in Android apps.