Skip to content

Instantly share code, notes, and snippets.

Avatar

Mikhail Panchukov Jericho2Code

View GitHub Profile
View RoomBaseConverters.kt
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
View Preference.kt
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> {
@Jericho2Code
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)
}
//sample