mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #3500 from mrwhoknows55/feat/scroll-with-vol-btns
feat(android): scroll with volume buttons
This commit is contained in:
commit
723e59db41
1 changed files with 31 additions and 0 deletions
|
|
@ -23,6 +23,7 @@ import androidx.compose.runtime.*
|
|||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import app.omnivore.omnivore.R
|
||||
import app.omnivore.omnivore.ui.reader.OmnivoreWebView.Direction
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
|
@ -160,6 +161,24 @@ fun WebReader(
|
|||
"utf-8",
|
||||
null
|
||||
)
|
||||
requestFocus()
|
||||
setOnKeyListener { _, keyCode, event ->
|
||||
if (event.action == KeyEvent.ACTION_DOWN) {
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_VOLUME_UP -> {
|
||||
scrollVertically(Direction.UP)
|
||||
return@setOnKeyListener true
|
||||
}
|
||||
|
||||
KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
||||
scrollVertically(Direction.DOWN)
|
||||
return@setOnKeyListener true
|
||||
}
|
||||
}
|
||||
}
|
||||
// default value
|
||||
false
|
||||
}
|
||||
}
|
||||
}, update = {
|
||||
if (javascriptActionLoopUUID != webReaderViewModel.lastJavascriptActionLoopUUID) {
|
||||
|
|
@ -194,6 +213,18 @@ class OmnivoreWebView(context: Context) : WebView(context), OnScrollChangeListen
|
|||
setOnScrollChangeListener(this)
|
||||
}
|
||||
|
||||
enum class Direction(val value: Int) {
|
||||
UP(-1),
|
||||
DOWN(1)
|
||||
}
|
||||
|
||||
fun scrollVertically(direction: Direction, heightFactor: Int = 10) {
|
||||
if (canScrollVertically(direction.value)) {
|
||||
val scrollByValue = height.div(heightFactor)
|
||||
scrollBy(0, direction.value.times(scrollByValue))
|
||||
}
|
||||
}
|
||||
|
||||
private val actionModeCallback = object : ActionMode.Callback2() {
|
||||
// Called when the action mode is created; startActionMode() was called
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
|
|
|
|||
Loading…
Reference in a new issue