@@ -436,22 +436,6 @@ class EpubNavigatorFragment private constructor(
436436
437437 override fun onPageChanged (pageIndex : Int , totalPages : Int , url : String ) {
438438 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- }
455439 }
456440
457441 override fun onPageEnded (end : Boolean ) {
@@ -702,16 +686,17 @@ class EpubNavigatorFragment private constructor(
702686 debounceLocationNotificationJob = launch {
703687 delay(100L )
704688
705- if (pendingLocator != null ) {
689+ val webView = currentFragment?.webView
690+ if (pendingLocator != null || webView == null ) {
706691 return @launch
707692 }
708693
709694 // The transition has stabilized, so we can ask the web view to refresh its current
710695 // item to reflect the current scroll position.
711- currentFragment?. webView? .updateCurrentItem()
696+ webView.updateCurrentItem()
712697
713698 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 )
715700 val positions = publication.positionsByResource[resource.href]?.takeIf { it.isNotEmpty() }
716701 ? : return @launch
717702
@@ -724,12 +709,16 @@ class EpubNavigatorFragment private constructor(
724709 .copy(title = tableOfContentsTitleByHref[resource.href])
725710 .copyWithLocations(progression = progression)
726711
727- if (locator == _currentLocator .value) {
728- return @launch
729- }
730-
731712 _currentLocator .value = locator
713+
714+ // Deprecated notifications
715+
732716 navigatorDelegate?.locationDidChange(navigator = navigator, locator = locator)
717+ paginationListener?.onPageChanged(
718+ pageIndex = webView.mCurItem,
719+ totalPages = webView.numPages,
720+ locator = locator
721+ )
733722 }
734723 }
735724
0 commit comments