Fix webtoon reader touch events. #561

This commit is contained in:
len 2016-12-10 14:01:16 +01:00
parent 8c1b07c4ba
commit 26b283d44d
3 changed files with 56 additions and 33 deletions

View file

@ -22,7 +22,12 @@ class WebtoonAdapter(val fragment: WebtoonReader) : RecyclerView.Adapter<Webtoon
/**
* Touch listener for images in holders.
*/
val touchListener = View.OnTouchListener { v, ev -> fragment.gestureDetector.onTouchEvent(ev) }
val imageTouchListener = View.OnTouchListener { v, ev -> fragment.imageGestureDetector.onTouchEvent(ev) }
/**
* Touch listener for the other views.
*/
val viewTouchListener = View.OnTouchListener { v, ev -> fragment.viewGestureDetector.onTouchEvent(ev) }
/**
* Returns the number of pages.

View file

@ -63,7 +63,7 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter)
setRegionDecoderClass(webtoonReader.regionDecoderClass)
setBitmapDecoderClass(webtoonReader.bitmapDecoderClass)
setVerticalScrollingParent(true)
setOnTouchListener(adapter.touchListener)
setOnTouchListener(adapter.imageTouchListener)
setOnImageEventListener(object : SubsamplingScaleImageView.DefaultOnImageEventListener() {
override fun onReady() {
onImageDecoded()
@ -77,7 +77,7 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter)
view.progress_container.minimumHeight = view.resources.displayMetrics.heightPixels * 2
view.setOnTouchListener(adapter.touchListener)
view.setOnTouchListener(adapter.viewTouchListener)
view.retry_button.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_UP) {
readerActivity.presenter.retryPage(page)

View file

@ -55,9 +55,14 @@ class WebtoonReader : BaseReader() {
private set
/**
* Gesture detector for touch events.
* Gesture detector for image touch events.
*/
val gestureDetector by lazy { createGestureDetector() }
val imageGestureDetector by lazy { GestureDetector(context, ImageGestureListener()) }
/**
* Gesture detector for other views touch events.
*/
val viewGestureDetector by lazy { GestureDetector(context, ViewGestureListener()) }
/**
* Subscriptions used while the view exists.
@ -122,12 +127,15 @@ class WebtoonReader : BaseReader() {
}
/**
* Creates the gesture detector for the reader.
*
* @return a gesture detector.
* Gesture detector for Subsampling Scale Image View. [onDown] needs to be false or else
* double tap to zoom doesn't work.
*/
protected fun createGestureDetector(): GestureDetector {
return GestureDetector(context, object : SimpleOnGestureListener() {
inner open class ImageGestureListener : SimpleOnGestureListener() {
override fun onDown(e: MotionEvent): Boolean {
return false
}
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
if (isAdded) {
val positionX = e.x
@ -154,7 +162,17 @@ class WebtoonReader : BaseReader() {
context.toast(getString(R.string.unknown_error))
}
}
})
}
/**
* Gesture detector for other views. [onDown] needs to be true here or it will incorrectly
* detect events.
*/
inner class ViewGestureListener : ImageGestureListener() {
override fun onDown(e: MotionEvent): Boolean {
return true
}
}
/**