Skip to content

Commit 12c7b3f

Browse files
committed
Reader : Update stored images after preloading
1 parent e2262d6 commit 12c7b3f

File tree

5 files changed

+13
-19
lines changed

5 files changed

+13
-19
lines changed

app/src/main/java/me/devsaki/hentoid/adapters/ImagePagerAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ class ImagePagerAdapter(context: Context) :
408408
else imageAvailable = false
409409

410410
val isStreaming = img != null && !imageAvailable && img.status == StatusContent.ONLINE
411-
val isExtracting = img != null && !imageAvailable && !img.url.startsWith("http")
411+
val isExtracting = img != null && !imageAvailable && (img.isArchived || img.isPdf)
412412

413413
@StringRes var text: Int = R.string.image_not_found
414414
if (isStreaming) text = R.string.image_streaming

app/src/main/java/me/devsaki/hentoid/database/domains/ImageFile.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ data class ImageFile(
8888
var isForceRefresh: Boolean = false
8989

9090

91-
constructor(img: ImageFile, populateContent: Boolean, populateChapter: Boolean) : this(
91+
constructor(img: ImageFile, populateContent: Boolean = true, populateChapter: Boolean = true) : this(
9292
img.id,
9393
img.order,
9494
img.url,
@@ -107,6 +107,7 @@ data class ImageFile(
107107
this.uniqueHash = img.uniqueHash
108108
this.displayOrder = img.displayOrder
109109
this.displayUri = img.displayUri
110+
this.imageType = img.imageType
110111
this.backupUrl = img.backupUrl
111112
this.isBackup = img.isBackup
112113
this.isForceRefresh = img.isForceRefresh

app/src/main/java/me/devsaki/hentoid/json/sources/deviantart/DeviantArtGallection.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@ data class DeviantArtGallection(
1515
val result: MutableList<ImageFile> = ArrayList()
1616
results.forEach { res ->
1717
val imgs = res.getImages()
18-
result.addAll(imgs.filter { it.isReadable }.map { ImageFile(it,
19-
populateContent = true,
20-
populateChapter = true
21-
) })
18+
result.addAll(imgs.filter { it.isReadable }.map { ImageFile(it) })
2219
if (null == result.find { it.isCover }) {
23-
val cover = ImageFile(imgs.first { it.isCover },
24-
populateContent = true,
25-
populateChapter = true
26-
)
20+
val cover = ImageFile(imgs.first { it.isCover })
2721
result.add(0, cover)
2822
}
2923
}

app/src/main/java/me/devsaki/hentoid/util/ImportHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ private fun mapMetadata(recipient: List<ImageFile>, ref: List<ImageFile>) {
10401040
*/
10411041
fun createCover(images: MutableList<ImageFile>) {
10421042
if (images.isNotEmpty()) {
1043-
val img = ImageFile(images[0], populateContent = true, populateChapter = true)
1043+
val img = ImageFile(images[0])
10441044
img.isCover = true
10451045
img.name = THUMB_FILE_NAME
10461046
// Create a new cover entry from the 1st element

app/src/main/java/me/devsaki/hentoid/viewmodels/ReaderViewModel.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,12 +1379,7 @@ class ReaderViewModel(
13791379
if (viewerImagesInternal.size <= downloadedPageIndex) return@launch
13801380

13811381
// Instanciate a new ImageFile not to modify the one used by the UI
1382-
val downloadedPic =
1383-
ImageFile(
1384-
viewerImagesInternal[downloadedPageIndex],
1385-
populateContent = true,
1386-
populateChapter = true
1387-
)
1382+
val downloadedPic = ImageFile(viewerImagesInternal[downloadedPageIndex])
13881383
downloadedPic.displayUri = resultOpt.second
13891384
viewerImagesInternal.removeAt(downloadedPageIndex)
13901385
viewerImagesInternal.add(downloadedPageIndex, downloadedPic)
@@ -1578,7 +1573,7 @@ class ReaderViewModel(
15781573
refresh: Boolean
15791574
) {
15801575
// Instanciate a new ImageFile not to modify the one used by the UI
1581-
val extractedPic = ImageFile(img, populateContent = true, populateChapter = true)
1576+
val extractedPic = ImageFile(img)
15821577
extractedPic.displayUri = uri.toString()
15831578
synchronized(viewerImagesInternal) {
15841579
viewerImagesInternal.removeAt(idx)
@@ -2058,7 +2053,11 @@ class ReaderViewModel(
20582053
img.imageType = readImageType(application, uri.toUri())
20592054
Timber.d("${img.id} : Set image type to ${img.imageType}")
20602055
// Make image usable by reader if not set yet
2061-
if (img.displayUri.isBlank()) img.displayUri = img.fileUri
2056+
if (img.displayUri.isBlank()) {
2057+
val updatedImg = ImageFile(img)
2058+
updatedImg.displayUri = img.fileUri
2059+
viewerImagesInternal[it] = updatedImg
2060+
}
20622061
}
20632062
}
20642063
onDone?.invoke()

0 commit comments

Comments
 (0)