pull/32/head
kunfei 5 years ago
parent 425a24bd1c
commit debcf6836d
  1. 33
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt
  3. 2
      app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt
  4. 5
      app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt

@ -37,6 +37,7 @@ import io.legado.app.ui.sourceedit.SourceEditActivity
import io.legado.app.ui.widget.page.ChapterProvider
import io.legado.app.ui.widget.page.PageView
import io.legado.app.ui.widget.page.TextChapter
import io.legado.app.ui.widget.page.delegate.PageDelegate
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_read_book.*
import kotlinx.android.synthetic.main.view_book_page.*
@ -248,10 +249,17 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
}
KeyEvent.KEYCODE_VOLUME_UP -> {
if (volumeKeyPage(PageDelegate.Direction.PREV)) {
return true
}
}
KeyEvent.KEYCODE_VOLUME_DOWN -> {
if (volumeKeyPage(PageDelegate.Direction.NEXT)) {
return true
}
}
KeyEvent.KEYCODE_SPACE -> {
}
}
return super.onKeyDown(keyCode, event)
@ -260,12 +268,35 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN -> {
if (volumeKeyPage(PageDelegate.Direction.NONE)) {
return true
}
}
}
return super.onKeyUp(keyCode, event)
}
private fun volumeKeyPage(direction: PageDelegate.Direction): Boolean {
if (!read_menu.isVisible) {
if (getPrefBoolean("volumeKeyPage", true)) {
if (getPrefBoolean("volumeKeyPageOnPlay")
|| readAloudStatus != Status.PLAY
) {
when (direction) {
PageDelegate.Direction.PREV -> {
}
PageDelegate.Direction.NEXT -> {
}
}
return true
}
}
}
return false
}
/**
* 加载章节内容
*/

@ -156,11 +156,11 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
}
override fun hasNext(): Boolean {
return true
return pageFactory?.hasNext() == true
}
override fun hasPrev(): Boolean {
return true
return pageFactory?.hasPrev() == true
}
fun upStyle() {

@ -26,7 +26,7 @@ data class TextChapter(
}
fun isLastIndex(index: Int): Boolean {
return index == pages.size - 1
return index >= pages.size - 1
}
fun pageSize(): Int {

@ -10,11 +10,12 @@ class TextPageFactory private constructor(dataSource: DataSource) :
}
override fun hasPrev(): Boolean {
return true
return dataSource.hasPrevChapter() || dataSource.pageIndex() > 0
}
override fun hasNext(): Boolean {
return true
return dataSource.hasNextChapter()
|| dataSource.getCurrentChapter()?.isLastIndex(dataSource.pageIndex()) != true
}
override fun pageAt(index: Int): TextPage {

Loading…
Cancel
Save