This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |