Slide 1

Slide 1 text

ANDROID PAGING LIBRARY Managing Infinite lists

Slide 2

Slide 2 text

ValentineRutto @valentinerutto -Android Developer at KountableInc -Magician

Slide 3

Slide 3 text

ClareMburu @Mburuclare -Android Developer

Slide 4

Slide 4 text

Android Paging Library Eldoret & Nakuru

Slide 5

Slide 5 text

What you’ll need -Android studio 3.0 or later Familiarity with android architecture components: RecyclerView,Rest Api, LiveData and ViewModel

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Components of paging library It has 3 main classes -PagedList -DataSource -PagedListAdapter

Slide 9

Slide 9 text

Components of paging library 9

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Components of paging library DATA SOURCE: PositionalDataSource Used when the user wants to jump to arbitrary positions. Eg. contacts app in android 11

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Data Flow 16

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

ACTUAL CODE github rest api paging library github code 18

Slide 19

Slide 19 text

RESOURCES Eldoret & Nakuru ● https://developer.android.com/topic/libraries/architecture/paging/ ● https://developer.android.com/topic/libraries/architecture/paging/#update- existing-app ● https://www.youtube.com/watch?v=QVMqCRs0BNA/ ● https://codelabs.developers.google.com/codelabs/android-paging/index.ht ml

Slide 20

Slide 20 text

Thank you