diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 7322806bb..6616805de 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -237,7 +237,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } } - fun bookLoadFinish() { + private fun bookLoadFinish() { viewModel.bookData.value?.let { viewModel.loadContent(it, viewModel.durChapterIndex) viewModel.loadContent(it, viewModel.durChapterIndex + 1) diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt index b3105599f..ba3c9b845 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt @@ -39,10 +39,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { if (!bookUrl.isNullOrEmpty()) { execute { App.db.bookDao().getBook(bookUrl)?.let { book -> - bookData.postValue(book) durChapterIndex = book.durChapterIndex durPageIndex = book.durChapterPos isLocalBook = book.origin == BookType.local + bookData.postValue(book) bookSource = App.db.bookSourceDao().getBookSource(book.origin) bookSource?.let { webBook = WebBook(it) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt b/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt index 16b06e23b..7fe165942 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt @@ -1,14 +1,15 @@ package io.legado.app.ui.widget.page -class TextPageFactory private constructor(dataSource: DataSource) : PageFactory(dataSource) { +class TextPageFactory private constructor(dataSource: DataSource) : + PageFactory(dataSource) { - companion object{ - fun create(dataSource: DataSource): TextPageFactory{ + companion object { + fun create(dataSource: DataSource): TextPageFactory { return TextPageFactory(dataSource) } } - private var index: Int = 0 + var index: Int = 0 override fun hasPrev(): Boolean { return true @@ -27,22 +28,28 @@ class TextPageFactory private constructor(dataSource: DataSource) : PageFactory< } override fun moveToLast() { - + index = dataSource.getCurrentChapter()?.let { + if (it.pageSize() == 0) { + 0 + } else { + it.pageSize() - 1 + } + } ?: 0 } override fun moveToNext(): Boolean { - return if(hasNext()){ + return if (hasNext()) { index = index.plus(1) true - }else + } else false } override fun moveToPrevious(): Boolean { - return if(hasPrev()){ + return if (hasPrev()) { index = index.minus(1) true - }else + } else false }