File: improve a bit pdf loading
This commit is contained in:
parent
e322ba1b32
commit
be009baed7
1 changed files with 11 additions and 5 deletions
|
|
@ -43,11 +43,11 @@ class PdfRendererManager(
|
|||
mutex.withLock {
|
||||
withContext(Dispatchers.IO) {
|
||||
pdfRenderer = PdfRenderer(parcelFileDescriptor).apply {
|
||||
(0 until pageCount).map { pageIndex ->
|
||||
PdfPage(width, pageIndex, mutex, this, coroutineScope)
|
||||
}.also {
|
||||
mutablePdfPages.value = it
|
||||
}
|
||||
// Preload just 3 pages so we can render faster
|
||||
val firstPages = loadPages(from = 0, to = 3)
|
||||
mutablePdfPages.value = firstPages
|
||||
val nextPages = loadPages(from = 3, to = pageCount)
|
||||
mutablePdfPages.value = firstPages + nextPages
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -65,4 +65,10 @@ class PdfRendererManager(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun PdfRenderer.loadPages(from: Int, to: Int): List<PdfPage> {
|
||||
return (from until minOf(to, pageCount)).map { pageIndex ->
|
||||
PdfPage(width, pageIndex, mutex, this, coroutineScope)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue