Yaksa

A lightweight RecyclerView tool that lets you render items like Javascript.

As we all know, using RecyclerView to display list data is a must-have feature for every Android developer.

However, RecyclerView still has its shortcomings, that is too cumbersome.

I believe every developer has had this experience:

To show a simple list of only a single type, we need to create an Adapter and we need to create a ViewHolder,

for a slightly more complicated list with multiple types, we need not only to create an Adapter, but also to create multiple ViewHolders

We repeated such boring work again and again and again, and it seemed so insensitive.

However, there is more to life than just present, poetry and distance!

Let's say goodbye to the same Adapter and ViewHolder as the nightmare, and embrace Yaksa together!

Yaksa(夜叉), Increases 16 Agility 15% Attack Speed ​​10% Movement Speed

Talk is cheap, show me the code

Render a Linear list:

recycler_view.linear {
    item {
        HeaderItem("This is a Header")
    }

    itemDsl(index = 0) {
        xml(R.layout.header_item)
        render {
            it.tv_header.text = "This is a dsl Header"
            it.setOnClickListener { toast("DSL Header Clicked") }
        }
    }

    data.forEach { each ->
        itemDsl {
            xml(R.layout.list_item)
            render {
                it.textView.text = each.title
            }
        }
    }
}

That's it, there is no Adapter, no ViewHolder, you just need to concentrate on rendering the Item just fine!

Output:

Render a Grid list:

rv_list.grid {
    spanCount(SPAN_COUNT)
    
    item {
        HeaderItem("This is a Header")
    }
    
    itemDsl(index = 0) {
        gridSpanSize(SPAN_COUNT)
        
        xml(R.layout.header_item)
        render {
            it.tv_header.text = "This is a dsl Header"
            it.setOnClickListener { toast("DSL Header Clicked") }
        }
    }
    
    data.forEach { each ->
        itemDsl {
            xml(R.layout.list_item)
            render {
                it.textView.text = each.title
            }
            renderX { position, it ->
                it.setOnClickListener { toast("Clicked $position") }
            }
        }
    }
}

Output:

Waterfall flow? No problem:

rv_list.stagger {
    spanCount(3)
    
    item {
        HeaderItem("This is a Header")
    }
    
    itemDsl(index = 0) {
        staggerFullSpan(true)
        
        xml(R.layout.header_item)
        render {
            it.tv_header.text = "This is a dsl Header"
            it.setOnClickListener { toast("DSL Header Clicked") }
        }
    }
    
    data.forEach { each ->
        item {
            ListItem(each.title, HEIGHTS[Random().nextInt(HEIGHTS.size)].px)
        }
    }
}

Output:

Others such as Header, Footer, and multiple type types also support,and importantly,
none of these require you to write any ViewHolder and Adapter

Start yaksa now and start your super-god!

Add to your project build.gradle file:

dependencies {
	implementation 'zlc.season:yaksa:x.x.x'
}

GitHub