Coder Social home page Coder Social logo

middleman's Introduction

MiddleMan

A Better way to handle items in the Simple list and Paged list in RecyclerView.

Middleman is a library for helping handling items in recyclerView adapters with better following SOLID rules.
it supports both simple list and paging list in recyclerView.

Download

why use Middleman?

Recyclerview Mess: In almost all mobile applications there is a need for at least one page that shows a list of items it might be a list of products, contacts messages,... In big projects like e-commerce applications when you have a lot of different items in a list and a lot of list pages it kind of becomes a big problem when you want to add a new item in Recyclerview you have to create new Viewholder then change your adapter to handling that kind of the view and what if your new item needed to talk to fragment then you have to change more in your adapter, what if you want to use this new item in other Recyclerviews in other pages? a lot of things to do right.

you can find out more here.

Gradle

implementation "com.mohamadk:middleman:{last-version}"


allprojects {
    repositories {
        google()
        jcenter()
        
        maven {
                url  "https://dl.bintray.com/mohamad-khaleghy/MiddleMan"
              }
    }
}

How to use it

1- create an instance of GeneralViewAdapter and set it to recyclerView

 recyclerView.apply {

        adapter = GeneralViewAdapter(this@SampleListFragment)
        // or for support paging in your list
        adapter = GeneralPagingViewAdapter(this@SampleListFragment)
        
        layoutManager = LinearLayoutManager(activity)
    }

2- implement BaseModel in every item model. implement defaultResLayout or defaultViewClass method.
you can declare a reslayout or a class of your customView item.

@Parcelize
class ItemModel(val id:String,val name:String):BaseModel{
    override fun defaultResLayout(position: Int): Int? {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun defaultViewClass(position: Int): Class<*>? {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

}

3- create a customView for each item in your recycler view that implement Binder interface and if need to interact with activity or fragment implement the corresponding interactor.

open class ItemView @JvmOverloads constructor(
    context: Context,
    attributes: AttributeSet? = null,
    defStyleAttributes: Int = 0
) : LinearLayoutCompat(context, attributes, defStyleAttributes)
    , Binder<ItemModel>
    , RequireInteractor<SomeIntractor> {

    private lateinit var someIntractor: SomeIntractor

    override fun setInteractor(intractor: SomeIntractor) {
        this.someIntractor = intractor
    }

    override fun bind(item: ItemModel?) {
        ....
    }
}

and that's it.

middleman's People

Contributors

mohamadk avatar

Stargazers

Pranav Lathigara avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

morristech

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.