Skip to content

Instantly share code, notes, and snippets.


Mikhail Panchukov Jericho2Code

View GitHub Profile
View RoomBaseConverters.kt
import java.lang.reflect.Type
open class BaseConverter<T>(private val type: Class<T>) {
private val gson = Gson()
View Preference.kt
import android.content.SharedPreferences
import kotlin.reflect.KProperty
class Preference<T>(
private val preferences: SharedPreferences,
private val name: String,
private val default: T
) : ReadWriteProperty<Any?, T> {
Jericho2Code / BaseDiffCallback.kt
Last active Jul 31, 2019
Simple implementation of DiffUtil.ItemCallback uses Kotlin
View BaseDiffCallback.kt
class BaseDiffCallback<T>(
val isItemsSame: (old: T, new: T) -> Boolean,
val isContentsSame: (old: T, new: T) -> Boolean = { old, new -> old == new }
) : DiffUtil.ItemCallback<T>() {
override fun areItemsTheSame(old: T, new: T): Boolean = isItemsSame(old, new)
override fun areContentsTheSame(old: T, new: T): Boolean = isContentsSame(old, new)