Generic Recycler Adapter

Generic adapters for Android based on https://github.com/MaximeJallu/generic-adapter-kotlin

License

License

The Code Project Open License (CPOL) 1.02
Categories

Categories

Kotlin Languages
GroupId

GroupId

com.github.maximejallu
ArtifactId

ArtifactId

adapters-kotlin
Last Version

Last Version

18.08.01
Release Date

Release Date

Type

Type

aar
Description

Description

Generic Recycler Adapter
Generic adapters for Android based on https://github.com/MaximeJallu/generic-adapter-kotlin
Project URL

Project URL

https://github.com/MaximeJallu/generic-adapter-kotlin
Source Code Management

Source Code Management

https://github.com/MaximeJallu/generic-adapter-kotlin

Download adapters-kotlin

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk7 jar 1.2.60
com.android.support » appcompat-v7 jar 27.1.1
com.android.support » recyclerview-v7 jar 27.1.1

Project Modules

There are no modules declared in this project.

Status

alt text API

Generic-Adapter-Kotlin:

This tool allows you to no longer worry about adapters. Now you will only create your ViewHolder. Communication management between your Views and your ViewHolders is possible. Creating sections is now very easily. Enjoy.

Download Maven Central

buildtool used is 27 use {exclude group: 'com.android.support'} only if you have problems

dependencies {
    ...
    implementation ('com.github.maximejallu:adapters-kotlin:18.08.01')
    ...
}

Decorators for : ButterKnife - Picasso - Glide ...

class SampleApplication: Application {

    override 
    fun onCreate() {
        super.onCreate()

        RecyclerAdapter.Companion.Helper()
                    .attachInitBindingView(decorator = object : InitBindingViewHolder {
                        override fun initBinding(target: Any, view: View) {
                            if (view.javaClass.simpleName.contains(".java")) {
                                //TODO e.g. butter-knife binding...
                            }
                        }
                    })
    }
}

1- Create yours RecyclerViewHolder (Easy sample method)

class ViewOne(parent: ViewGroup) : RecyclerViewHolder<Int>(
            parent, R.layout.support_simple_spinner_dropdown_item
        ) {

        init {
            itemView.setOnClickListener {
                (getCommunication() as ViewOneListener).onClick(item)
            }
        }
       
        override fun onBind() {
            itemView.myTextViewId.text = "text: $item"
        }

        interface ViewOneListener: RecyclerViewListener{
            fun onClick(item: Int)
        }  
    }

2 - Create and init Adapter

fun sample(){
val adapter = RecyclerAdapter<Int>(
            items = ArrayList(),
            defaultViewHolder = ViewOne::class, /*for getItemViewType == 0*/
            listener = object :ViewOne.ViewOneListener{
                            override fun onClick(item: Int) {
                                TODO("not implemented")
                            }
            
                        }
        )
    /*attache others viewHolder*/    
    adapter.registerViewHolder(TYPE_2, ViewTwo::class, listener = null)      
} 

3 - Declare strategy view type is necessary (Multi cell method)

fun multicellSample(){
        /*sample for multi Cell [3 viewholder resgistered for this sample]*/
        adapter.setItemViewTypeStrategy(strategy = object : ViewTypeStrategy<Int> {
            override fun getItemViewType(position: Int, item: Int): Int {
                return when{
                    position == 0 -> TYPE_1
                    item > 5 -> TYPE_2
                    else -> TYPE_3
                }
            }
        })
}

Versions

Version
18.08.01
18.07.02
18.07.01