Initial support of long press in reader
This commit is contained in:
@@ -52,6 +52,23 @@ class GridTouchHelper(
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onLongPress(event: MotionEvent) {
|
||||
super.onLongPress(event)
|
||||
val xIndex = (event.rawX * 2f / width).roundToInt()
|
||||
val yIndex = (event.rawY * 2f / height).roundToInt()
|
||||
listener.onGridLongTouch(
|
||||
when(xIndex) {
|
||||
1 -> {
|
||||
when (yIndex) {
|
||||
1 -> AREA_CENTER
|
||||
else -> -1
|
||||
}
|
||||
}
|
||||
else -> -1
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val AREA_CENTER = 1
|
||||
@@ -65,6 +82,8 @@ class GridTouchHelper(
|
||||
|
||||
fun onGridTouch(area: Int)
|
||||
|
||||
fun onGridLongTouch(area: Int)
|
||||
|
||||
fun onProcessTouch(rawX: Int, rawY: Int): Boolean
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -43,6 +44,7 @@ import org.koitharu.kotatsu.core.ui.widgets.ZoomControl
|
||||
import org.koitharu.kotatsu.core.util.GridTouchHelper
|
||||
import org.koitharu.kotatsu.core.util.IdlingDetector
|
||||
import org.koitharu.kotatsu.core.util.ShareHelper
|
||||
import org.koitharu.kotatsu.core.util.ext.DIALOG_THEME_CENTERED
|
||||
import org.koitharu.kotatsu.core.util.ext.hasGlobalPoint
|
||||
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
||||
import org.koitharu.kotatsu.core.util.ext.isRtl
|
||||
@@ -204,6 +206,10 @@ class ReaderActivity :
|
||||
controlDelegate.onGridTouch(area, viewBinding.container)
|
||||
}
|
||||
|
||||
override fun onGridLongTouch(area: Int) {
|
||||
controlDelegate.onGridLongTouch(area, viewBinding.container)
|
||||
}
|
||||
|
||||
override fun onProcessTouch(rawX: Int, rawY: Int): Boolean {
|
||||
return if (
|
||||
rawX <= gestureInsets.left ||
|
||||
@@ -336,6 +342,13 @@ class ReaderActivity :
|
||||
setUiIsVisible(!viewBinding.appbarTop.isVisible)
|
||||
}
|
||||
|
||||
override fun viewDialog() {
|
||||
MaterialAlertDialogBuilder(this, DIALOG_THEME_CENTERED)
|
||||
.setMessage("Called dialog on long press")
|
||||
.setPositiveButton(R.string.got_it, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun isReaderResumed(): Boolean {
|
||||
val reader = readerManager.currentReader ?: return false
|
||||
return reader.isResumed && supportFragmentManager.fragments.lastOrNull() === reader
|
||||
|
||||
@@ -69,6 +69,15 @@ class ReaderControlDelegate(
|
||||
}
|
||||
}
|
||||
|
||||
fun onGridLongTouch(area: Int, view: View) {
|
||||
when (area) {
|
||||
GridTouchHelper.AREA_CENTER -> {
|
||||
listener.viewDialog()
|
||||
view.playSoundEffect(SoundEffectConstants.CLICK)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onKeyDown(keyCode: Int, @Suppress("UNUSED_PARAMETER") event: KeyEvent?): Boolean = when (keyCode) {
|
||||
KeyEvent.KEYCODE_VOLUME_UP -> if (isVolumeKeysSwitchEnabled) {
|
||||
listener.switchPageBy(-1)
|
||||
@@ -155,6 +164,8 @@ class ReaderControlDelegate(
|
||||
|
||||
fun switchPageBy(delta: Int)
|
||||
|
||||
fun viewDialog()
|
||||
|
||||
fun scrollBy(delta: Int, smooth: Boolean): Boolean
|
||||
|
||||
fun toggleUiVisibility()
|
||||
|
||||
Reference in New Issue
Block a user