pull/32/head
kunfei 5 years ago
parent 45fe6caea5
commit 21adbcdca2
  1. 2
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 17
      app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt
  3. 4
      app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt
  4. 6
      app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt

@ -238,7 +238,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun loadContentFinish(bookChapter: BookChapter, content: String) {
launch {
val textChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
content_text_view.text = textChapter.pages[0].text
content_text_view.text = textChapter.pages[0].stringBuilder
}
}

@ -1,5 +1,8 @@
package io.legado.app.ui.widget.page
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.RelativeSizeSpan
import io.legado.app.data.entities.BookChapter
@ -11,8 +14,18 @@ object ChapterProvider {
var surplusText = content
var pageIndex = 0
while (surplusText.isNotEmpty()) {
textView.text = surplusText
textPages.add(TextPage(pageIndex, surplusText.substring(0, textView.getCharNum())))
val spannableStringBuilder = SpannableStringBuilder(surplusText)
if (pageIndex == 0) {
val span = RelativeSizeSpan(1.5f)
spannableStringBuilder.setSpan(span, 0, surplusText.indexOf("\n"), Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
}
textView.text = spannableStringBuilder
textPages.add(
TextPage(
pageIndex,
spannableStringBuilder.delete(textView.getCharNum(), spannableStringBuilder.length)
)
)
surplusText = surplusText.substring(textView.getCharNum())
pageIndex++
}

@ -1,3 +1,5 @@
package io.legado.app.ui.widget.page
data class TextPage(val index: Int, val text: String)
import android.text.SpannableStringBuilder
data class TextPage(val index: Int, val stringBuilder: SpannableStringBuilder)

@ -1,5 +1,7 @@
package io.legado.app.ui.widget.page
import android.text.SpannableStringBuilder
class TextPageFactory private constructor(dataSource: DataSource) : PageFactory<TextPage>(dataSource) {
companion object{
@ -15,11 +17,11 @@ class TextPageFactory private constructor(dataSource: DataSource) : PageFactory<
}
override fun nextPage(): TextPage {
return TextPage(index.plus(1), "index:$index")
return TextPage(index.plus(1), SpannableStringBuilder("index:$index"))
}
override fun previousPage(): TextPage {
return TextPage(index.minus(1), "index:$index")
return TextPage(index.minus(1), SpannableStringBuilder("index:$index"))
}

Loading…
Cancel
Save