pull/32/head
kunfei 5 years ago
parent 04b471f7c1
commit 20fd00f165
  1. 8
      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. 20
      app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt

@ -42,7 +42,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
setSupportActionBar(toolbar)
initAnimation()
initView()
viewModel.chapterMaxIndex.observe(this, Observer { })
viewModel.chapterMaxIndex.observe(this, Observer { bookLoadFinish() })
viewModel.initData(intent)
savedInstanceState?.let {
changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog
@ -222,6 +222,12 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
}
private fun bookLoadFinish() {
viewModel.book?.let {
viewModel.loadContent(it, it.durChapterIndex)
}
}
override fun changeTo(book: Book) {
}

@ -48,7 +48,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}
fun getContent(book: Book, index: Int) {
fun loadContent(book: Book, index: Int) {
App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter ->
BookHelp.getContent(book, chapter)?.let {

@ -1,18 +1,22 @@
package io.legado.app.ui.widget.page
import android.widget.TextView
import io.legado.app.data.entities.BookChapter
class ChapterProvider {
fun getTextChapter(textView: TextView, content: String) {
textView.text = content
val layout = textView.layout
val topOfLastLine = textView.height - textView.paddingTop - textView.paddingBottom - textView.lineHeight
val lineNum = layout.getLineForVertical(topOfLastLine)
val lastCharNum = layout.getLineEnd(lineNum)
fun getTextChapter(textView: ContentTextView, bookChapter: BookChapter, content: String): TextChapter {
val textPages = arrayListOf<TextPage>()
var surplusText = content
var pageIndex = 0
while (surplusText.isNotEmpty()) {
textView.text = surplusText
textPages.add(TextPage(pageIndex, surplusText.substring(0, textView.getCharNum())))
surplusText = surplusText.substring(textView.getCharNum())
pageIndex++
}
return TextChapter(bookChapter.index, textPages)
}

Loading…
Cancel
Save