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
}
@hector6872
hector6872 / Demo.kt
Last active January 25, 2019 20:47 — forked from alexfu/Demo.kt
Making (Android) Spannable great again with Kotlin
val world = "World"
val spannedText = SpannableString("Hello $world!")
spannedText
.spanWith(world) {
what = BackgroundColorSpan(Color.RED)
flags = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
}
.spanWith(world) {
what = StyleSpan(Typeface.BOLD)
flags = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE