itemsadapter

The simple adapter to render static data in RecyclerView

License

License

GroupId

GroupId

com.redmadrobot.itemsadapter
ArtifactId

ArtifactId

itemsadapter
Last Version

Last Version

1.1
Release Date

Release Date

Type

Type

aar
Description

Description

itemsadapter
The simple adapter to render static data in RecyclerView
Project URL

Project URL

https://github.com/RedMadRobot/itemsadapter
Source Code Management

Source Code Management

https://github.com/RedMadRobot/itemsadapter

Download itemsadapter

How to add to project

<!-- https://jarcasting.com/artifacts/com.redmadrobot.itemsadapter/itemsadapter/ -->
<dependency>
    <groupId>com.redmadrobot.itemsadapter</groupId>
    <artifactId>itemsadapter</artifactId>
    <version>1.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.redmadrobot.itemsadapter/itemsadapter/
implementation 'com.redmadrobot.itemsadapter:itemsadapter:1.1'
// https://jarcasting.com/artifacts/com.redmadrobot.itemsadapter/itemsadapter/
implementation ("com.redmadrobot.itemsadapter:itemsadapter:1.1")
'com.redmadrobot.itemsadapter:itemsadapter:aar:1.1'
<dependency org="com.redmadrobot.itemsadapter" name="itemsadapter" rev="1.1">
  <artifact name="itemsadapter" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.redmadrobot.itemsadapter', module='itemsadapter', version='1.1')
)
libraryDependencies += "com.redmadrobot.itemsadapter" % "itemsadapter" % "1.1"
[com.redmadrobot.itemsadapter/itemsadapter "1.1"]

Dependencies

compile (3)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.30
androidx.annotation » annotation jar 1.1.0
androidx.recyclerview » recyclerview jar 1.1.0

Project Modules

There are no modules declared in this project.

ItemsAdapter

Version Build Status License

The simple adapter to render static data in RecyclerView.


Installation

Add the dependency:

repositories {
    mavenCentral()
    google()
}

dependencies {
    implementation("com.redmadrobot.itemsadapter:itemsadapter:1.1")
    // or if you use viewbinding
    implementation("com.redmadrobot.itemsadapter:itemsadapter-viewbinding:1.1")
}

Rationale

There are cases when you just need to render a simple list of static data without the hassle. You don't want to use complex solutions like Epoxy or Groupie for this purpose. This task is ItemsAdapter was created for. ItemsAdapter offers you simple DSL to create adapters.

When should I not use ItemsAdapter?

  • When you need to update and re-draw data in adapter
  • When you need to render elements with complex logic

Usage

The simplest case of usage is:

recyclerView.adapter = itemsAdapter(regions) { region ->
    bind(R.layout.view_region) { // this: View
        view_region_title.text = region.title
        view_region_description.text = region.description
    }
}

If you have more than one view type, you can use operator when:

recyclerView.adapter = itemsAdapter(contactsItems) { item ->
    when (item) {
        is ContactsItem.Header -> bind(R.layout.view_contacts_header) {
            view_contacts_header_letter.text = item.letter
        }

        is ContactsItem.Entry -> bind(R.layout.view_contacts_entry) {
            view_contacts_entry_name.text = item.name
            view_contacts_entry_phone.text = item.phone
        }
    }
}

Note that kotlin synthetics are deprecated since Kotlin 1.4.20, so it is better to use ViewBinding or findViewById.

ViewBinding support

If you use ViewBinding, use itemsadapter-viewbinding in place of itemsadapter.
Then you can use method bind with ViewBinding:

recyclerView.adapter = itemsAdapter(regions) { region ->
    bind<ViewRegionBinding>(R.layout.view_region) { // this: ViewRegionBinding
        title.text = region.title
        description.text = region.description
    }
}

Features

Context

Within itemsAdapter block you can use contextual data:

Field Description
index: Int Index of the current item

Looping mode

Set parameter isLooping to true to use ItemsAdapter in looping mode. It will only work if you have more than one element in data list.

Contributing

Merge requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

com.redmadrobot.itemsadapter

red_mad_robot

knows its onions in mobile application development

Versions

Version
1.1