recycleradapter-generator - Make displaying RecyclerViews easier by generating it's adapter with simple annotations. - Kotlin Resources

PsHegger by recycleradapter-generator

What is RecyclerAdapter Generator (RAG)?

Many Android Developers have to write the same boilerplate code for displaying a simple RecyclerView. This library tries to be a solution to minimize the written code which is required to write adapters for simple RecyclerViews.

Setup

RAG is currently only available on Jitpack.

Gradle

Check if jitpack is added as a repository.

// Project level build.gradle
allprojects {
    repositories {
        // your other repositories
        maven { url 'https://jitpack.io' }
    }
}

Dependencies

RAG consist of two separate artifacts: annotations which will be used to mark your classes for processing, and codegen which will generate the final code for you.

implementation "com.github.pshegger.recycleradapter-generator:annotations:0.1.0"

kapt "com.github.pshegger.recycleradapter-generator:codegen:0.1.0"

Add these 2 lines to your module dependencies and you can start using RAG.

Quick Start

Use @ModelBinding to annotate a class to be used for adapter generation.

@ModelBinding(
    R.layout.foo,           // layout id
    clickListener = false,  // if true an item click listener is generated for your adapter, default: false 
    namePrefix = ""         // default: empty -> generate name from the name of the data class
)
class UserBinding(private val user: User) {
    // binding methods
}

To create a method which binds the values of your data class to a View create a method annotated with @BindView inside your class.

@BindView(R.id.name)
fun setName(nameLabel: TextView) {
    nameLabel.text = user.name
}

If everything is ready press build and after it finishes your adapter will be generated (in the above example it will be called UserAdapter). From this point you can use at as it was written by you.

Features

  • Basic adapter generation
  • Item click listener support
  • Custom adapter name (only prefix)
  • Update Dispatching (using DiffUtil)
  • Click listener for specific Views
  • Artifacts for Maven Central

Feel free to suggest new features.

compile "com.github.PsHegger.recycleradapter-generator:recycleradapter-generator:0.1.0"

Related Libraries

materialdrawerkt

A Kotlin DSL wrapper around the mikepenz/MaterialDrawer library.

Last updated 3 mins ago

anvil

Minimal UI library for Android inspired by React

Last updated 3 mins ago

RichUtilsKt

Advancement Utils for Android Developer written in Kotlin

Last updated 3 mins ago

mapme

The Android maps adapter

Last updated 3 mins ago

bubble

Screen orientation detector for android

Last updated 3 mins ago