Giter VIP home page Giter VIP logo

simplepagingadapter's Introduction

SimplePagingAdapter

Wrap of Google's Paging library making it easy to implement

Result


Setup

Paging component implementation is encapsulated in PagingManager

pagingManager = PagingManager
.builder<SimpleModel>()
.setLifecycle(this)
.setPageSize(10)
.setLayout(R.layout.simple_item)
.onItemBind { itemView, position, item ->
    onBindItem(position, itemView, item)
}.checkItemIds { oldItem, newItem ->
    oldItem.id == newItem.id
}.checkItemContent { oldItem, newItem ->
    oldItem == newItem
}.onDataRequested { pageIndex, lastItem ->
    loadData(pageIndex, lastItem)
}.build()

PagingManager has public method for getting adapter: recyclerView.adapter = pagingManager.getAdapter()

PagingManager is generic on data type

setLifecycle is to set lifecycle owner that is used by manager to observe component's PagedList

setPageSize initializes page size including initial page

setLayout is to set item's layout id

onItemBind is called on adapter's onBindViewHolder

checkItemIds and checkItemContent are used by DiffUtil's callback

Loading data

onDataRequested is called every time when DataSource's callbacks are triggered,

there is passing two parameters:pageIndex ans lastItem for loading relevant data

after loading data PagingManager has public method setData(pageIndex: Int, data: List<T>) for populating corresponding page

Additional setup

you can additionally set .onReflectLoader { isVisible -> } and .onReflectPlaceHolder { isVisible -> },

onReflectLoader is called every time page starts loading

onReflectPlaceHolder is called if initial page is loaded empty

PagingManager also has two public methods for updating data

pagingManager.refreshData() to reset whole content

pagingManager.updateItemAt(newItem: T, position: Int) to update particular item at position


Import in project via Gradle:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.github.Saba-21:SimplePagingAdapter:0.2'
    implementation 'androidx.paging:paging-runtime-ktx:2.1.1'
}

Sample usage

A sample project which demonstrates sample usage is available in the test module.

simplepagingadapter's People

Contributors

sabafromwandio avatar saba-21 avatar

Stargazers

cheny avatar  avatar Bacho Kurtanidze avatar

Watchers

James Cloos avatar  avatar

Forkers

zuluft

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.