Skip to content

Instantly share code, notes, and snippets.

View Jericho2Code's full-sized avatar

Mikhail Panchukov Jericho2Code

View GitHub Profile
@Jericho2Code
Jericho2Code / BaseDiffCallback.kt
Last active July 31, 2019 08:36
Simple implementation of DiffUtil.ItemCallback uses Kotlin
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)
}
//sample
import android.content.SharedPreferences
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
class Preference<T>(
private val preferences: SharedPreferences,
private val name: String,
private val default: T
) : ReadWriteProperty<Any?, T> {
import android.arch.persistence.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.lang.reflect.Type
open class BaseConverter<T>(private val type: Class<T>) {
private val gson = Gson()
@TypeConverter