2021-05-16 05:44:15 +00:00
|
|
|
package org.schabi.newpipe.database
|
2017-08-12 04:50:25 +00:00
|
|
|
|
2021-05-16 05:44:15 +00:00
|
|
|
import androidx.room.TypeConverter
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamType
|
|
|
|
import org.schabi.newpipe.local.subscription.FeedGroupIcon
|
|
|
|
import java.time.Instant
|
|
|
|
import java.time.OffsetDateTime
|
|
|
|
import java.time.ZoneOffset
|
2017-08-12 04:50:25 +00:00
|
|
|
|
2023-11-01 02:39:11 +00:00
|
|
|
class Converters {
|
2017-08-12 04:50:25 +00:00
|
|
|
/**
|
2021-05-16 05:44:15 +00:00
|
|
|
* Convert a long value to a [OffsetDateTime].
|
2020-03-31 17:20:15 +00:00
|
|
|
*
|
2017-08-12 04:50:25 +00:00
|
|
|
* @param value the long value
|
2021-05-16 05:44:15 +00:00
|
|
|
* @return the `OffsetDateTime`
|
2017-08-12 04:50:25 +00:00
|
|
|
*/
|
|
|
|
@TypeConverter
|
2021-05-16 05:44:15 +00:00
|
|
|
fun offsetDateTimeFromTimestamp(value: Long?): OffsetDateTime? {
|
|
|
|
return value?.let { OffsetDateTime.ofInstant(Instant.ofEpochMilli(it), ZoneOffset.UTC) }
|
2017-08-12 04:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-05-16 05:44:15 +00:00
|
|
|
* Convert a [OffsetDateTime] to a long value.
|
2020-03-31 17:20:15 +00:00
|
|
|
*
|
2021-05-16 05:44:15 +00:00
|
|
|
* @param offsetDateTime the `OffsetDateTime`
|
2017-08-12 04:50:25 +00:00
|
|
|
* @return the long value
|
|
|
|
*/
|
|
|
|
@TypeConverter
|
2021-05-16 05:44:15 +00:00
|
|
|
fun offsetDateTimeToTimestamp(offsetDateTime: OffsetDateTime?): Long? {
|
|
|
|
return offsetDateTime?.withOffsetSameInstant(ZoneOffset.UTC)?.toInstant()?.toEpochMilli()
|
2017-08-12 04:50:25 +00:00
|
|
|
}
|
2018-01-15 20:30:52 +00:00
|
|
|
|
|
|
|
@TypeConverter
|
2021-05-16 05:44:15 +00:00
|
|
|
fun streamTypeOf(value: String): StreamType {
|
|
|
|
return StreamType.valueOf(value)
|
2018-01-15 20:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@TypeConverter
|
2021-05-16 05:44:15 +00:00
|
|
|
fun stringOf(streamType: StreamType): String {
|
|
|
|
return streamType.name
|
2018-01-15 20:30:52 +00:00
|
|
|
}
|
2019-04-28 20:43:54 +00:00
|
|
|
|
|
|
|
@TypeConverter
|
2021-05-16 05:44:15 +00:00
|
|
|
fun integerOf(feedGroupIcon: FeedGroupIcon): Int {
|
|
|
|
return feedGroupIcon.id
|
2019-04-28 20:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@TypeConverter
|
2021-05-16 05:44:15 +00:00
|
|
|
fun feedGroupIconOf(id: Int): FeedGroupIcon {
|
2023-11-01 01:25:11 +00:00
|
|
|
return FeedGroupIcon.entries.first { it.id == id }
|
2019-04-28 20:43:54 +00:00
|
|
|
}
|
2017-08-12 04:50:25 +00:00
|
|
|
}
|