@@ -3,6 +3,7 @@ package com.docs.docwatcher
33import android.content.Context
44import android.graphics.Bitmap
55import android.graphics.pdf.PdfRenderer
6+ import android.os.Build
67import android.os.ParcelFileDescriptor
78import android.util.AttributeSet
89import android.view.LayoutInflater
@@ -90,16 +91,30 @@ class DocView @JvmOverloads constructor(
9091 val cardText = " 1 / ${list.size} "
9192 pageText.text = cardText
9293 pageCard.showPagesViewForSomeSeconds(coroutineScope, context)
93- rv.setOnScrollChangeListener { _, _, _, _, _ ->
94- val visiblePosition = (rv.layoutManager as LinearLayoutManager ).findFirstCompletelyVisibleItemPosition()
95- if (visiblePosition != - 1 ) {
96- val currPage = visiblePosition + 1
97- if (! noOfPages.isNullOrEmpty()) {
98- pageCard.show()
99- val text = " $currPage / $noOfPages "
100- pageText.text = text
101- pageCard.showPagesViewForSomeSeconds(coroutineScope, context)
94+ if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .M ) {
95+ rv.addOnScrollListener(object : RecyclerView .OnScrollListener () {
96+
97+ override fun onScrolled (recyclerView : RecyclerView , dx : Int , dy : Int ) {
98+ super .onScrolled(recyclerView, dx, dy)
99+ handleOnScroll()
102100 }
101+ })
102+ } else {
103+ rv.setOnScrollChangeListener { _, _, _, _, _ ->
104+ handleOnScroll()
105+ }
106+ }
107+ }
108+
109+ private fun handleOnScroll () {
110+ val visiblePosition = (rv.layoutManager as LinearLayoutManager ).findFirstCompletelyVisibleItemPosition()
111+ if (visiblePosition != - 1 ) {
112+ val currPage = visiblePosition + 1
113+ if (! noOfPages.isNullOrEmpty()) {
114+ pageCard.show()
115+ val text = " $currPage / $noOfPages "
116+ pageText.text = text
117+ pageCard.showPagesViewForSomeSeconds(coroutineScope, context)
103118 }
104119 }
105120 }
0 commit comments