pull/32/head
kunfei 5 years ago
parent e610f9fd34
commit ed7e94aee7
  1. 2
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 2
      app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt
  3. 25
      app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt

@ -237,7 +237,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
} }
fun bookLoadFinish() { private fun bookLoadFinish() {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
viewModel.loadContent(it, viewModel.durChapterIndex) viewModel.loadContent(it, viewModel.durChapterIndex)
viewModel.loadContent(it, viewModel.durChapterIndex + 1) viewModel.loadContent(it, viewModel.durChapterIndex + 1)

@ -39,10 +39,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
if (!bookUrl.isNullOrEmpty()) { if (!bookUrl.isNullOrEmpty()) {
execute { execute {
App.db.bookDao().getBook(bookUrl)?.let { book -> App.db.bookDao().getBook(bookUrl)?.let { book ->
bookData.postValue(book)
durChapterIndex = book.durChapterIndex durChapterIndex = book.durChapterIndex
durPageIndex = book.durChapterPos durPageIndex = book.durChapterPos
isLocalBook = book.origin == BookType.local isLocalBook = book.origin == BookType.local
bookData.postValue(book)
bookSource = App.db.bookSourceDao().getBookSource(book.origin) bookSource = App.db.bookSourceDao().getBookSource(book.origin)
bookSource?.let { bookSource?.let {
webBook = WebBook(it) webBook = WebBook(it)

@ -1,14 +1,15 @@
package io.legado.app.ui.widget.page package io.legado.app.ui.widget.page
class TextPageFactory private constructor(dataSource: DataSource) : PageFactory<TextPage>(dataSource) { class TextPageFactory private constructor(dataSource: DataSource) :
PageFactory<TextPage>(dataSource) {
companion object{ companion object {
fun create(dataSource: DataSource): TextPageFactory{ fun create(dataSource: DataSource): TextPageFactory {
return TextPageFactory(dataSource) return TextPageFactory(dataSource)
} }
} }
private var index: Int = 0 var index: Int = 0
override fun hasPrev(): Boolean { override fun hasPrev(): Boolean {
return true return true
@ -27,22 +28,28 @@ class TextPageFactory private constructor(dataSource: DataSource) : PageFactory<
} }
override fun moveToLast() { override fun moveToLast() {
index = dataSource.getCurrentChapter()?.let {
if (it.pageSize() == 0) {
0
} else {
it.pageSize() - 1
}
} ?: 0
} }
override fun moveToNext(): Boolean { override fun moveToNext(): Boolean {
return if(hasNext()){ return if (hasNext()) {
index = index.plus(1) index = index.plus(1)
true true
}else } else
false false
} }
override fun moveToPrevious(): Boolean { override fun moveToPrevious(): Boolean {
return if(hasPrev()){ return if (hasPrev()) {
index = index.minus(1) index = index.minus(1)
true true
}else } else
false false
} }

Loading…
Cancel
Save