Giter Club home page Giter Club logo

yaksa's Introduction

Yaksa

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

Read this in other languages: 中文English 

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'
}

(Please replace x with the latest version numbers: Download)

License

Copyright 2018 Season.Zlc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

yaksa's People

Contributors

ssseasonnn avatar

Watchers

 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.