-
Notifications
You must be signed in to change notification settings - Fork 85
/
JsonImageFile.kt
58 lines (53 loc) · 1.62 KB
/
JsonImageFile.kt
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
49
50
51
52
53
54
55
56
57
58
package me.devsaki.hentoid.json
import com.squareup.moshi.JsonClass
import me.devsaki.hentoid.database.domains.Chapter
import me.devsaki.hentoid.database.domains.ImageFile
import me.devsaki.hentoid.enums.StatusContent
@JsonClass(generateAdapter = true)
data class JsonImageFile(
val order: Int,
val url: String,
val pageUrl: String?,
val name: String,
val isCover: Boolean?,
val favourite: Boolean?,
val isRead: Boolean?,
val status: StatusContent,
val mimeType: String?,
val pHash: Long?,
val isTransformed: Boolean?,
val chapterOrder: Int?
) {
constructor(f: ImageFile) : this(
f.order,
f.url,
f.pageUrl,
f.name,
f.isCover,
f.favourite,
f.read,
f.status,
f.mimeType,
f.imageHash,
f.isTransformed,
f.linkedChapter?.order ?: -1
)
fun toEntity(chapters: List<Chapter>): ImageFile {
val result = if (url.isEmpty()) ImageFile.fromPageUrl(order, pageUrl ?: "", status, name)
else ImageFile.fromImageUrl(order, url, status, name)
result.name = name
result.isCover = isCover ?: false
result.favourite = favourite ?: false
result.read = isRead ?: false
result.mimeType = mimeType ?: ""
result.imageHash = pHash ?: 0
result.isTransformed = isTransformed ?: false
if (chapters.isNotEmpty() && (chapterOrder ?: -1) > -1) {
chapters.firstOrNull { it.order == chapterOrder }?.let {
result.setChapter(it)
it.imageFiles.add(result)
}
}
return result
}
}