-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathConverters.kt
More file actions
48 lines (41 loc) · 1.17 KB
/
Converters.kt
File metadata and controls
48 lines (41 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.schabi.newpipe.database
import androidx.room.TypeConverter
import org.schabi.newpipe.extractor.stream.StreamType
import org.schabi.newpipe.local.subscription.FeedGroupIcon
import java.time.Instant
class Converters {
/**
* Convert a long value to an [Instant].
*
* @param value the long value
* @return the `Instant`
*/
@TypeConverter
fun timestampToInstant(value: Long?): Instant? {
return value?.let { Instant.ofEpochMilli(it) }
}
/**
* Convert an [Instant] to a long value.
*
* @param instant the `Instant`
* @return the long value
*/
@TypeConverter
fun instantToTimestamp(instant: Instant?) = instant?.toEpochMilli()
@TypeConverter
fun streamTypeOf(value: String): StreamType {
return StreamType.valueOf(value)
}
@TypeConverter
fun stringOf(streamType: StreamType): String {
return streamType.name
}
@TypeConverter
fun integerOf(feedGroupIcon: FeedGroupIcon): Int {
return feedGroupIcon.id
}
@TypeConverter
fun feedGroupIconOf(id: Int): FeedGroupIcon {
return FeedGroupIcon.entries.first { it.id == id }
}
}