2023-03-01 19:49:27 +05:30
|
|
|
package com.github.libretube.db
|
|
|
|
|
|
|
|
import androidx.room.TypeConverter
|
2023-03-28 15:46:47 +05:30
|
|
|
import com.github.libretube.api.JsonHelper
|
2023-03-07 07:14:09 +05:30
|
|
|
import java.nio.file.Path
|
|
|
|
import java.nio.file.Paths
|
2023-03-01 19:49:27 +05:30
|
|
|
import kotlinx.datetime.LocalDate
|
|
|
|
import kotlinx.datetime.toLocalDate
|
2023-03-28 15:46:47 +05:30
|
|
|
import kotlinx.serialization.decodeFromString
|
|
|
|
import kotlinx.serialization.encodeToString
|
2023-03-01 19:49:27 +05:30
|
|
|
|
|
|
|
object Converters {
|
|
|
|
@TypeConverter
|
|
|
|
fun localDateToString(localDate: LocalDate?) = localDate?.toString()
|
|
|
|
|
|
|
|
@TypeConverter
|
|
|
|
fun stringToLocalDate(string: String?) = string?.toLocalDate()
|
2023-03-07 07:14:09 +05:30
|
|
|
|
|
|
|
@TypeConverter
|
|
|
|
fun pathToString(path: Path?) = path?.toString()
|
|
|
|
|
|
|
|
@TypeConverter
|
|
|
|
fun stringToPath(string: String?) = string?.let { Paths.get(it) }
|
2023-03-28 15:46:47 +05:30
|
|
|
|
|
|
|
@TypeConverter
|
|
|
|
fun stringListToJson(value: List<String>) = JsonHelper.json.encodeToString(value)
|
|
|
|
|
|
|
|
@TypeConverter
|
|
|
|
fun jsonToStringList(value: String) = JsonHelper.json.decodeFromString<List<String>>(value)
|
2023-03-01 19:49:27 +05:30
|
|
|
}
|