|
@@ -8,6 +8,7 @@ import android.view.GestureDetector
|
|
|
import android.view.MotionEvent
|
|
import android.view.MotionEvent
|
|
|
import android.view.ScaleGestureDetector
|
|
import android.view.ScaleGestureDetector
|
|
|
import android.widget.FrameLayout
|
|
import android.widget.FrameLayout
|
|
|
|
|
+import io.legato.kazusa.help.config.AppConfig
|
|
|
|
|
|
|
|
class WebtoonFrame : FrameLayout {
|
|
class WebtoonFrame : FrameLayout {
|
|
|
|
|
|
|
@@ -21,6 +22,7 @@ class WebtoonFrame : FrameLayout {
|
|
|
|
|
|
|
|
private val scaleDetector = ScaleGestureDetector(context, ScaleListener())
|
|
private val scaleDetector = ScaleGestureDetector(context, ScaleListener())
|
|
|
private val flingDetector = GestureDetector(context, FlingListener())
|
|
private val flingDetector = GestureDetector(context, FlingListener())
|
|
|
|
|
+ private val regionRects = mutableMapOf<String, RectF>()
|
|
|
|
|
|
|
|
var doubleTapZoom = true
|
|
var doubleTapZoom = true
|
|
|
set(value) {
|
|
set(value) {
|
|
@@ -34,45 +36,55 @@ class WebtoonFrame : FrameLayout {
|
|
|
private val recycler: WebtoonRecyclerView?
|
|
private val recycler: WebtoonRecyclerView?
|
|
|
get() = getChildAt(0) as? WebtoonRecyclerView
|
|
get() = getChildAt(0) as? WebtoonRecyclerView
|
|
|
|
|
|
|
|
- private val mcRect = RectF()
|
|
|
|
|
- private val blRect = RectF()
|
|
|
|
|
- private val brRect = RectF()
|
|
|
|
|
-
|
|
|
|
|
- private var mTouchMiddle: (() -> Unit)? = null
|
|
|
|
|
- fun onTouchMiddle(init: () -> Unit) = apply { this.mTouchMiddle = init }
|
|
|
|
|
- private var mNextPage: (() -> Unit)? = null
|
|
|
|
|
- fun onNextPage(init: () -> Unit) = apply { this.mNextPage = init }
|
|
|
|
|
- private var mPrevPage: (() -> Unit)? = null
|
|
|
|
|
- fun onPrevPage(init: () -> Unit) = apply { this.mPrevPage = init }
|
|
|
|
|
-
|
|
|
|
|
var disabledClickScroll = false
|
|
var disabledClickScroll = false
|
|
|
|
|
|
|
|
|
|
+ var actionHandler: ClickActionHandler? = null
|
|
|
|
|
+
|
|
|
override fun onAttachedToWindow() {
|
|
override fun onAttachedToWindow() {
|
|
|
super.onAttachedToWindow()
|
|
super.onAttachedToWindow()
|
|
|
- recycler?.tapListener = { ev ->
|
|
|
|
|
- when {
|
|
|
|
|
- mcRect.contains(ev.rawX, ev.rawY) -> {
|
|
|
|
|
- mTouchMiddle?.invoke()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- blRect.contains(ev.rawX, ev.rawY) && !disabledClickScroll -> {
|
|
|
|
|
- mPrevPage?.invoke()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- brRect.contains(ev.rawX, ev.rawY) && !disabledClickScroll -> {
|
|
|
|
|
- mNextPage?.invoke()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ recycler?.tapListener = tapListener@{ ev ->
|
|
|
|
|
+ val x = ev.rawX
|
|
|
|
|
+ val y = ev.rawY
|
|
|
|
|
+ val key =
|
|
|
|
|
+ regionRects.entries.find { it.value.contains(x, y) }?.key ?: return@tapListener
|
|
|
|
|
+
|
|
|
|
|
+ val action = when (key) {
|
|
|
|
|
+ "TL" -> AppConfig.mangaClickActionTL
|
|
|
|
|
+ "TC" -> AppConfig.mangaClickActionTC
|
|
|
|
|
+ "TR" -> AppConfig.mangaClickActionTR
|
|
|
|
|
+ "ML" -> AppConfig.mangaClickActionML
|
|
|
|
|
+ "MC" -> AppConfig.mangaClickActionMC
|
|
|
|
|
+ "MR" -> AppConfig.mangaClickActionMR
|
|
|
|
|
+ "BL" -> AppConfig.mangaClickActionBL
|
|
|
|
|
+ "BC" -> AppConfig.mangaClickActionBC
|
|
|
|
|
+ "BR" -> AppConfig.mangaClickActionBR
|
|
|
|
|
+ else -> -1
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ performClickAction(action)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
|
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
|
|
super.onSizeChanged(w, h, oldw, oldh)
|
|
super.onSizeChanged(w, h, oldw, oldh)
|
|
|
- mcRect.set(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f)
|
|
|
|
|
- blRect.set(0f, height * 0.66f, width * 0.33f, height.toFloat())
|
|
|
|
|
- brRect.set(width * 0.66f, height * 0.66f, width.toFloat(), height.toFloat())
|
|
|
|
|
|
|
+ val cellWidth = w / 3f
|
|
|
|
|
+ val cellHeight = h / 3f
|
|
|
|
|
+ val keys = listOf("TL", "TC", "TR", "ML", "MC", "MR", "BL", "BC", "BR")
|
|
|
|
|
+
|
|
|
|
|
+ keys.forEachIndexed { index, key ->
|
|
|
|
|
+ val row = index / 3
|
|
|
|
|
+ val col = index % 3
|
|
|
|
|
+ regionRects[key] = RectF(
|
|
|
|
|
+ col * cellWidth,
|
|
|
|
|
+ row * cellHeight,
|
|
|
|
|
+ (col + 1) * cellWidth,
|
|
|
|
|
+ (row + 1) * cellHeight
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
|
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
|
|
|
if (!disableMangaScale) {
|
|
if (!disableMangaScale) {
|
|
|
scaleDetector.onTouchEvent(ev)
|
|
scaleDetector.onTouchEvent(ev)
|
|
@@ -93,6 +105,18 @@ class WebtoonFrame : FrameLayout {
|
|
|
return super.dispatchTouchEvent(ev)
|
|
return super.dispatchTouchEvent(ev)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private fun performClickAction(action: Int) {
|
|
|
|
|
+ when (action) {
|
|
|
|
|
+ -1 -> return
|
|
|
|
|
+ 0 -> actionHandler?.showMenu()
|
|
|
|
|
+ 1 -> actionHandler?.nextPage()
|
|
|
|
|
+ 2 -> actionHandler?.prevPage()
|
|
|
|
|
+ 3 -> actionHandler?.nextChapter()
|
|
|
|
|
+ 4 -> actionHandler?.prevChapter()
|
|
|
|
|
+ else -> {}
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
inner class ScaleListener : ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
|
inner class ScaleListener : ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
|
|
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
|
|
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
|
|
|
recycler?.onScaleBegin()
|
|
recycler?.onScaleBegin()
|
|
@@ -123,4 +147,13 @@ class WebtoonFrame : FrameLayout {
|
|
|
return recycler?.zoomFling(velocityX.toInt(), velocityY.toInt()) ?: false
|
|
return recycler?.zoomFling(velocityX.toInt(), velocityY.toInt()) ?: false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ interface ClickActionHandler {
|
|
|
|
|
+ fun showMenu()
|
|
|
|
|
+ fun nextPage()
|
|
|
|
|
+ fun prevPage()
|
|
|
|
|
+ fun nextChapter()
|
|
|
|
|
+ fun prevChapter()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|