Coder Social home page Coder Social logo

paging's Introduction

Paging

A library to help handle simple and paging list fragments and interact with activity from fragments and items in Recyclerview

Download

What's the problem?

in applications with a lot of lists there is always a boilerplate code that we have to write for showing a list to the user:

-show initial loading
-fetching data from the server
-show the data in Recyclerview
-hide initial loading
<paging lists when user go to the end of the list>
-show recycler loading
-fetching data from the server
-show the data in Recyclerview

a lot of these codes are the same in each page of your application despite the how you fetch data and how you show in your Recyclerview." linear, grid, dividers, ..."

Here the Paging came trough with help of Middleman.
with Paging you can just extends your fragments from BaseListFragment or BasePagingFragment and extends your viewmodels from BaseListFragmentViewModel or BasePagingViewModel to handle this boiler plate codes.

this is your recyclerview fragment:

class HomeFragment : BasePagingFragment<HomeViewModel>() {

    override val viewModel: HomeViewModel by viewModel()

    class HomePage : PageFactory(HomeFragment::class.java) {
        override fun addToBackStack(): Boolean {
            return false
        }

        override fun tag(): String? {
            return this::class.java.name
        }
    }
}

and your view model look like:

class HomeViewModel(private val homeRepository: HomeRepository) : BasePagingViewModel<PagedList<BaseModel>>() {

    override fun getListingPage(vararg args: Any): Listing<PagedList<BaseModel>> {
        val location: Location = args[0] as Location
        return homeRepository.loadPage(location)
    }

}

so simple Right.

don't worry about customization of your recyclerviews and layout or time for fetching data you can always override

fun getRecycler(baseView: View): RecyclerView

and

 fun getLayout(): Int

and

 fun loadItems(vararg args: Any) 

functions.

in the example, you can see a full application that works with foursquare APIs.
I strongly recommended you to look at the middleman library if you don't know it already.

install

implementation 'com.mohamadk:paging:$latest_version'

repositories {
    maven {
        url  "https://dl.bintray.com/mohamad-khaleghy/MiddleMan"
    }
}

Sample app

In sample you can find an application that get places near user location by FourSquare api

home detail

paging's People

Contributors

mohamadk avatar

Stargazers

Meysam Valiolahi avatar  avatar

Watchers

James Cloos avatar  avatar

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.