@@ -436,22 +436,6 @@ class EpubNavigatorFragment private constructor(
436
436
437
437
override fun onPageChanged (pageIndex : Int , totalPages : Int , url : String ) {
438
438
r2Activity?.onPageChanged(pageIndex = pageIndex, totalPages = totalPages, url = url)
439
- if (paginationListener != null ) {
440
- // Find current locator
441
- val resource = publication.readingOrder[resourcePager.currentItem]
442
- val progression = currentFragment?.webView?.progression?.coerceIn(0.0 , 1.0 ) ? : 0.0
443
- val positions = publication.positionsByResource[resource.href]?.takeIf { it.isNotEmpty() }
444
- ? : return
445
-
446
- val positionIndex = ceil(progression * (positions.size - 1 )).toInt()
447
- if (! positions.indices.contains(positionIndex)) {
448
- return
449
- }
450
-
451
- val locator = positions[positionIndex].copyWithLocations(progression = progression)
452
- // Pageindex is actually the page number so to get a zero based index we subtract one.
453
- paginationListener.onPageChanged(pageIndex - 1 , totalPages, locator)
454
- }
455
439
}
456
440
457
441
override fun onPageEnded (end : Boolean ) {
@@ -702,16 +686,17 @@ class EpubNavigatorFragment private constructor(
702
686
debounceLocationNotificationJob = launch {
703
687
delay(100L )
704
688
705
- if (pendingLocator != null ) {
689
+ val webView = currentFragment?.webView
690
+ if (pendingLocator != null || webView == null ) {
706
691
return @launch
707
692
}
708
693
709
694
// The transition has stabilized, so we can ask the web view to refresh its current
710
695
// item to reflect the current scroll position.
711
- currentFragment?. webView? .updateCurrentItem()
696
+ webView.updateCurrentItem()
712
697
713
698
val resource = publication.readingOrder[resourcePager.currentItem]
714
- val progression = currentFragment?. webView? .progression? .coerceIn(0.0 , 1.0 ) ? : 0.0
699
+ val progression = webView.progression.coerceIn(0.0 , 1.0 )
715
700
val positions = publication.positionsByResource[resource.href]?.takeIf { it.isNotEmpty() }
716
701
? : return @launch
717
702
@@ -724,12 +709,16 @@ class EpubNavigatorFragment private constructor(
724
709
.copy(title = tableOfContentsTitleByHref[resource.href])
725
710
.copyWithLocations(progression = progression)
726
711
727
- if (locator == _currentLocator .value) {
728
- return @launch
729
- }
730
-
731
712
_currentLocator .value = locator
713
+
714
+ // Deprecated notifications
715
+
732
716
navigatorDelegate?.locationDidChange(navigator = navigator, locator = locator)
717
+ paginationListener?.onPageChanged(
718
+ pageIndex = webView.mCurItem,
719
+ totalPages = webView.numPages,
720
+ locator = locator
721
+ )
733
722
}
734
723
}
735
724
0 commit comments