pull/32/head
kunfei 5 years ago
parent 515b537c9d
commit 88c66a83b7
  1. 23
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt
  3. 2
      app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt
  4. 2
      app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt

@ -237,16 +237,23 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun loadContentFinish(bookChapter: BookChapter, content: String) {
launch {
if (viewModel.durChapterIndex == bookChapter.index) {
tv_chapter_name.text = bookChapter.title
tv_chapter_name.visible()
if (!viewModel.isLocalBook) {
tv_chapter_url.text = bookChapter.url
tv_chapter_url.visible()
when (bookChapter.index) {
viewModel.durChapterIndex -> {
tv_chapter_name.text = bookChapter.title
tv_chapter_name.visible()
if (!viewModel.isLocalBook) {
tv_chapter_url.text = bookChapter.url
tv_chapter_url.visible()
}
viewModel.curTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
}
viewModel.durChapterIndex - 1 -> {
viewModel.prevTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
}
viewModel.durChapterIndex + 1 -> {
viewModel.nextTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
}
}
val textChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
content_text_view.text = textChapter.pages[0].stringBuilder
}
}

@ -13,6 +13,7 @@ import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
import io.legado.app.help.BookHelp
import io.legado.app.model.WebBook
import io.legado.app.ui.widget.page.TextChapter
import kotlinx.coroutines.Dispatchers.IO
class ReadBookViewModel(application: Application) : BaseViewModel(application) {
@ -24,6 +25,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
var callBack: CallBack? = null
var durChapterIndex = 0
var isLocalBook = true
var prevTextChapter: TextChapter? = null
var curTextChapter: TextChapter? = null
var nextTextChapter: TextChapter? = null
fun initData(intent: Intent) {
val bookUrl = intent.getStringExtra("bookUrl")

@ -29,7 +29,7 @@ object ChapterProvider {
surplusText = surplusText.substring(textView.getCharNum())
pageIndex++
}
return TextChapter(bookChapter.index, textPages)
return TextChapter(bookChapter.index, bookChapter.title, textPages)
}

@ -1,3 +1,3 @@
package io.legado.app.ui.widget.page
data class TextChapter(val position: Int, val pages: List<TextPage>)
data class TextChapter(val position: Int, val title: String, val pages: List<TextPage>)

Loading…
Cancel
Save