Rekata Adapter

Additional

Language
Kotlin
Version
N/A
Created
Jun 8, 2019
Updated
Aug 9, 2019
Owner
Gian Patrick Quintana (HirogaKatageri)
Contributor
Gian Patrick Quintana (HirogaKatageri)
1
Activity
Badge
Generate
Download
Source code
APK file

Commercial

Rekata Adapter

Recycler View Adapter that supports multiple views.

Benefits

  • No need for ViewHolders.
  • Easily add Item Click Listeners.
  • Easily bind Item Views and their behavior.
  • Easily communicate between ItemView, Activity and Fragment.
  • Easily modify items that share common ids. (e.g. Whether a user is following someone or not)

Example

    private val binder: bindView<IRekataItem> = { holder, view, item ->
        when (item) {
            is SampleTextItem -> {
                view.txt_sample.text = "Position ${holder.adapterPosition}"
            }
            is SampleImageItem -> {
                GlideApp.with(view)
                    .load("https://picsum.photos/1280/720.jpg")
                    .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                    .centerCrop()
                    .into(view.img_sample)
            }
        }
    }

    private val clickBinder: bindClick<IRekataItem> = { holder, view, data ->
        Toast.makeText(this, "You have clicked item at position: ${holder.adapterPosition}", Toast.LENGTH_SHORT)
            .show()
    }

    private val config = RekataConfig(
        enableStableIds = true,
        enabledInfiniteLoading = false,
        infiniteLoadingMode = InfiniteLoadingMode.VERTICAL,
        bindView = binder
    ).apply {
        addViewType(
            VIEW_SAMPLE_IMAGE,
            R.layout.item_sample_image, onClick = clickBinder
        )
        addViewType(
            VIEW_SAMPLE_TEXT,
            R.layout.item_sample_text, onClick = clickBinder
        )
    }

    private val adapter = RekataAdapter(config)

Gradle Setup

Project Gradle

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

App Gradle

dependencies {
    implementation 'com.github.HirogaKatageri:rekata-adapter:TAG'
}