mohamadk / Paging

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

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


Languages

Language:Kotlin 100.0%