Kotlin Paging Pagination (KPP)

Most applications display large lists of data, however, users typically only see a small portion of it, so fetching the entire list of data from the network is not an optimal solution. The Paging library is a much easier way to implement this approach. Currently, Paging 3 is available as an alpha release. If you want to use the stable version you can use Paging 2.

Paging3 is one of the new Jetpack libraries to manage and load large datasets from various data sources efficiently. It allows us to load pages of data from the network or local database easily and saves our development time. Paging3 is designed to follow the Android application architecture and coordinate with other Jetpack components. It is Kotlin first and works with some of the new asynchronous threading solutions like Coroutines and Flow and of course, it also has support for RxJava & LiveData users.

What's different:

  • It caches page data in memory for better utilization of system resources which not only provides fast response but also helps in loading data without any hiccups.
  • It handles duplicate network requests very elegantly thereby saving user bandwidth and system resources.
  • A much more flexible Recyclerview adapter that gracefully requests & loads data every time the user reaches the end of the page, yes now the adapter controls when and what to load with a one time setting.
  • It is Kotlin first meaning the entire library is written in Kotlin and works great with other Kotlin offerings like Coroutines and Flow. Also, it supports widely used libraries like RxJava and LiveData as well.
  • It has built-in support for error handling, retry, and refresh use cases.

This is a codelab that demonstrates advanced usage of the Paging Library. If you are new to pagination as a concept, or to the Paging Library as a whole, check out the Paging Basics codelab.

What will you learn?

  1. What are the main components of Page 3?
  2. How to add Paging 3 to your project.
  3. How to add a header or footer to your list using the Paging 3 API.
  4. How to add list separator using Paging 3 API.
  5. How the pages of the network and database.

What will you build?

In this codelab, you start with a sample app that already displays a list of GitHub repositories. Each time the user scrolls to the end of the displayed list, a new network request is triggered and the results are displayed on the screen.

You will add code through a series of steps, to accomplish the following:

  1. Migrating to Paging library components.
  2. Add loading status headers and footers to your list.
  3. Show loading progress between each new repository search.
  4. Add separators to your list.
  5. Add database support for paging from network and database.

This is what your final app will look like:

What do you need?

  1. Android Studio Arctic Fox.
  2. Familiarity with the following Architecture Components: LiveData, ViewModel, View. Binding and with the architecture suggested in the "Application Architecture Guide".
  3. Familiarity with coroutines and Kotlin Flow.

For an introduction to Architecture Components, see the Room with a View codelab. For an introduction to Flow, see the Advanced Coroutines with Kotlin Flow and LiveData codelabs.

Source


Post a Comment

Previous Next

نموذج الاتصال