Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android paging library

ValentineRutto
November 10, 2018
250

Android paging library

ValentineRutto

November 10, 2018
Tweet

Transcript

  1. What you’ll need -Android studio 3.0 or later Familiarity with

    android architecture components: RecyclerView,Rest Api, LiveData and ViewModel
  2. Why use paging library? Benefits of paging library Flexible;supports any

    data source;Works out of the box with room and recyclerview -Supports large and infinite length lists -Saves the user's battery and consumes less bandwidth. Because it only requests data that are needed, this saves some device resources. -Loaded data is shown automatically with LiveData -Supports RXJava
  3. What is paging library -Its part of the android jetpack

    -its a component of the architecture components -The library makes it easier for you to load data gradually within your app’s recycler view
  4. Components of paging library DATA SOURCE • The DataSource is

    an interface for page source to provide the data gradually • DataSource usecases: -PositionalData source -ItemKeyedDataSource -PageKeyedDataSource 10
  5. Components of paging library DATA SOURCE: PositionalDataSource Used when the

    user wants to jump to arbitrary positions. Eg. contacts app in android 11
  6. Components of paging library DATA SOURCE: ItemKeyedDataSource used when you

    can read the next X items starting from a key or the previous X items starting from a key. 12
  7. Components of paging library DATA SOURCE: PageKeyedDataSource -Most common way

    of paging -used on server side apps -Your client sends a request, and when the response comes from the server, it includes the data. It also includes pointers for the next and previous keys. 13
  8. Components of paging library PAGELIST -that loads the data automatically

    and can provide update signal, for example, to the RecyclerViewAdapter. -The data is loaded automatically from a DataSource on the background thread.But then, it’s consumed on the main thread. -It supports both an infinite scrolling list, but also countable lists. 14
  9. Components of paging library PAGELISTADAPTER -This class is an implementation

    of RecyclerView.Adapter that presents data from a PagedList. For example, when a new page is loaded, the PagedListAdapter signals the RecyclerView that the data has arrived; this lets the RecyclerView replace any placeholders with the actual items, performing the appropriate animation. -uses a background thread to compute changes from one PagedList to the next 15
  10. Data Flow We have some data that we put on

    the DataSource in the background thread.The DataSource invalidates the PagedListand +updates its value. Then on the main thread, the PagedList notifies its observers of the new value.Now the PagedListAdapter knows about the new value. The background thread, the PageListAdapter needs to compute what’s changed, whats’ the difference and back on the UI thread, the View is updated in the onBinderViewHolder. 17