2022-04-22 23:29:24 +02:00
|
|
|
package eu.kanade.data
|
|
|
|
|
|
|
|
import com.squareup.sqldelight.ColumnAdapter
|
2022-09-25 16:12:36 +02:00
|
|
|
import eu.kanade.tachiyomi.source.model.UpdateStrategy
|
2022-04-30 17:59:39 +02:00
|
|
|
import java.util.Date
|
2022-04-22 23:29:24 +02:00
|
|
|
|
|
|
|
val dateAdapter = object : ColumnAdapter<Date, Long> {
|
|
|
|
override fun decode(databaseValue: Long): Date = Date(databaseValue)
|
|
|
|
override fun encode(value: Date): Long = value.time
|
|
|
|
}
|
|
|
|
|
|
|
|
private const val listOfStringsSeparator = ", "
|
|
|
|
val listOfStringsAdapter = object : ColumnAdapter<List<String>, String> {
|
|
|
|
override fun decode(databaseValue: String) =
|
|
|
|
if (databaseValue.isEmpty()) {
|
|
|
|
listOf()
|
|
|
|
} else {
|
|
|
|
databaseValue.split(listOfStringsSeparator)
|
|
|
|
}
|
|
|
|
override fun encode(value: List<String>) = value.joinToString(separator = listOfStringsSeparator)
|
|
|
|
}
|
2022-09-25 16:12:36 +02:00
|
|
|
|
|
|
|
val updateStrategyAdapter = object : ColumnAdapter<UpdateStrategy, Long> {
|
|
|
|
private val enumValues by lazy { UpdateStrategy.values() }
|
|
|
|
|
|
|
|
override fun decode(databaseValue: Long): UpdateStrategy =
|
|
|
|
enumValues.getOrElse(databaseValue.toInt()) { UpdateStrategy.ALWAYS_UPDATE }
|
|
|
|
|
|
|
|
override fun encode(value: UpdateStrategy): Long = value.ordinal.toLong()
|
|
|
|
}
|