Skip to content

Commit a34f4a4

Browse files
Refactor page navigation logic to preserve current page on load and simplify cache clearing.
1 parent c250eba commit a34f4a4

File tree

1 file changed

+8
-3
lines changed
  • pdfpreview/src/main/java/com/harissk/pdfpreview

1 file changed

+8
-3
lines changed

pdfpreview/src/main/java/com/harissk/pdfpreview/PDFView.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,8 @@ class PDFView(context: Context?, attrs: AttributeSet?) : RelativeLayout(context,
435435
currentPage = userPage
436436

437437
// In single page mode, clear cache of the old page to prevent old parts from showing
438-
if (viewConfiguration.singlePageMode && oldPage != currentPage) {
438+
if (viewConfiguration.singlePageMode && oldPage != currentPage)
439439
cacheManager.clearPageCache(oldPage)
440-
}
441440

442441
loadPages()
443442
if (!documentFitsView()) scrollHandle?.setPageNum(currentPage + 1)
@@ -1004,7 +1003,13 @@ class PDFView(context: Context?, attrs: AttributeSet?) : RelativeLayout(context,
10041003

10051004
postDelayed({
10061005
if (!isRecycled && !isRecycling && _pdfFile != null)
1007-
jumpTo(defaultPage, false)
1006+
jumpTo(
1007+
page = when {
1008+
currentPage > 0 -> currentPage
1009+
else -> defaultPage
1010+
},
1011+
withAnimation = false
1012+
)
10081013
}, initDelay)
10091014
} catch (e: Exception) {
10101015
loadError(e)

0 commit comments

Comments
 (0)