mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-16 15:32:50 +01:00
ba533f30ce
* Add support to update strategy. * Add JavaDoc and bump the LIB_VERSION_MAX constant. * Fix a word typo. * Store update strategy enum as integer in the DB.
31 lines
1.1 KiB
Kotlin
31 lines
1.1 KiB
Kotlin
package eu.kanade.data
|
|
|
|
import com.squareup.sqldelight.ColumnAdapter
|
|
import eu.kanade.tachiyomi.source.model.UpdateStrategy
|
|
import java.util.Date
|
|
|
|
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)
|
|
}
|
|
|
|
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()
|
|
}
|