Skip to content

Instantly share code, notes, and snippets.

@Mun0n
Mun0n / GridSpacingItemDecoration.kt
Created February 21, 2019 12:09
GridSpacingItemDecoration in kotlin for Grid RecyclerViews
import android.graphics.Rect
import android.support.v7.widget.RecyclerView
import android.view.View
class GridSpacingItemDecoration(private val spanCount: Int, private val spacing: Int, private val includeEdge: Boolean) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val position = parent.getChildAdapterPosition(view) // item position
val column = position % spanCount // item column
@hector6872
hector6872 / BindableRecyclerView.kt
Created January 28, 2019 18:20
BindableRecyclerView for Kotlin
abstract class BindableAdapter<TYPE : MultiType>(private val list: MutableList<TYPE>) : RecyclerView.Adapter<BindableViewHolder<TYPE>>() {
override fun onBindViewHolder(
holder: BindableViewHolder<TYPE>,
position: Int
) = holder.bind(list[position])
override fun getItemViewType(position: Int): Int = list[position].type
override fun getItemCount(): Int = list.size
}