AdapterHelper icon indicating copy to clipboard operation
AdapterHelper copied to clipboard

⛓ a simple adapter maker for RecyclerView 🔗

banner

License Download Title Highlight


Dirty Project, Don't use this!

Project for Practice Programming Skill











Download

repositories {
  mavenCentral()
  google()
  maven { 
    url 'https://jitpack.io' 
  }
}

dependencies {
  implementation 'com.github.sungbin5304:AdapterHelper:{version}'
}

Usage

Default

AdapterHelper
    .with(view: RecyclerView)
    .bindLayout(layoutRes: Int)
    .create(item: ArrayList<*>)

Binding your view

...
.addViewBindListener { item, view, position ->
  //Bind your view. 
}
.create(item: ArrayList<*>)

Add some options

...
.addOption(Option(divier: Divider?, padding: Padding?)) 
.addSwipeListener(SwipeController(object : SwipeControllerActions() {
  override fun onLeftClicked(items: ArrayList<*>, position: Int) {
    super.onLeftClicked(items, position)
    //code your action.
  }
  override fun onRightClicked(items: ArrayList<*>, position: Int) {
    super.onRightClicked(items, position)
    //code your action.
  }
}, buttonWidth: Float = 300f, buttonRadius: Float = 40f, leftButtonColor: Int? = null, rightButtonColor: Int? = null, leftButtonText: String? = null, rightButtonText: String? = null))
.create(item: ArrayList<*>)

Divider(orientation: Int = LinearLayout.VERTICAL)

Padding(left: Int = 0, top: Int = 0, right: Int = 0, bottom: Int = 0)

Example

preview
AdapterHelper
    .with(rv)
    .bindLayout(R.layout.test_layout)
    .addViewBindListener { item, view, position ->
        val tv = view as TextView
        tv.text = item[position].toString()
        tv.setOnClickListener { toast("${tv.text} Clicked.") }
    }
    .addOption(Option(null, Padding(16, 16, 16, 16)))
    .addSwipeListener(SwipeController(object : SwipeControllerActions() {
        override fun onLeftClicked(items: ArrayList<*>, position: Int) {
            super.onLeftClicked(items, position)
            toast("${items[position]} Left Clicked.")
        }
        override fun onRightClicked(items: ArrayList<*>, position: Int) {
            super.onRightClicked(items, position)
            toast("${items[position]} Right Clicked.")
        }
    }, 300f, 40f, Color.BLUE, Color.RED, "Left", "Right"))
    .create(arrayListOf("H", "E", "L", "L", "O"))
rv.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)

Gradle Error

If you error at gradle More than one file was found with OS independent path 'META-INF/library_release.kotlin_module' this, add below code at your gradle.

android {
  packagingOptions {
      exclude 'META-INF/library_release.kotlin_module'
  }
}

License

Apache License 2.0

Happy Coding :)