Initial support of long press in reader
This commit is contained in:
@@ -52,6 +52,23 @@ class GridTouchHelper(
|
|||||||
return true
|
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 {
|
companion object {
|
||||||
|
|
||||||
const val AREA_CENTER = 1
|
const val AREA_CENTER = 1
|
||||||
@@ -65,6 +82,8 @@ class GridTouchHelper(
|
|||||||
|
|
||||||
fun onGridTouch(area: Int)
|
fun onGridTouch(area: Int)
|
||||||
|
|
||||||
|
fun onGridLongTouch(area: Int)
|
||||||
|
|
||||||
fun onProcessTouch(rawX: Int, rawY: Int): Boolean
|
fun onProcessTouch(rawX: Int, rawY: Int): Boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import androidx.core.view.updateLayoutParams
|
|||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.Dispatchers
|
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.GridTouchHelper
|
||||||
import org.koitharu.kotatsu.core.util.IdlingDetector
|
import org.koitharu.kotatsu.core.util.IdlingDetector
|
||||||
import org.koitharu.kotatsu.core.util.ShareHelper
|
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.hasGlobalPoint
|
||||||
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
||||||
import org.koitharu.kotatsu.core.util.ext.isRtl
|
import org.koitharu.kotatsu.core.util.ext.isRtl
|
||||||
@@ -204,6 +206,10 @@ class ReaderActivity :
|
|||||||
controlDelegate.onGridTouch(area, viewBinding.container)
|
controlDelegate.onGridTouch(area, viewBinding.container)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onGridLongTouch(area: Int) {
|
||||||
|
controlDelegate.onGridLongTouch(area, viewBinding.container)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onProcessTouch(rawX: Int, rawY: Int): Boolean {
|
override fun onProcessTouch(rawX: Int, rawY: Int): Boolean {
|
||||||
return if (
|
return if (
|
||||||
rawX <= gestureInsets.left ||
|
rawX <= gestureInsets.left ||
|
||||||
@@ -336,6 +342,13 @@ class ReaderActivity :
|
|||||||
setUiIsVisible(!viewBinding.appbarTop.isVisible)
|
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 {
|
override fun isReaderResumed(): Boolean {
|
||||||
val reader = readerManager.currentReader ?: return false
|
val reader = readerManager.currentReader ?: return false
|
||||||
return reader.isResumed && supportFragmentManager.fragments.lastOrNull() === reader
|
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) {
|
fun onKeyDown(keyCode: Int, @Suppress("UNUSED_PARAMETER") event: KeyEvent?): Boolean = when (keyCode) {
|
||||||
KeyEvent.KEYCODE_VOLUME_UP -> if (isVolumeKeysSwitchEnabled) {
|
KeyEvent.KEYCODE_VOLUME_UP -> if (isVolumeKeysSwitchEnabled) {
|
||||||
listener.switchPageBy(-1)
|
listener.switchPageBy(-1)
|
||||||
@@ -155,6 +164,8 @@ class ReaderControlDelegate(
|
|||||||
|
|
||||||
fun switchPageBy(delta: Int)
|
fun switchPageBy(delta: Int)
|
||||||
|
|
||||||
|
fun viewDialog()
|
||||||
|
|
||||||
fun scrollBy(delta: Int, smooth: Boolean): Boolean
|
fun scrollBy(delta: Int, smooth: Boolean): Boolean
|
||||||
|
|
||||||
fun toggleUiVisibility()
|
fun toggleUiVisibility()
|
||||||
|
|||||||
Reference in New Issue
Block a user