pull/32/head
parent
04b471f7c1
commit
20fd00f165
@ -1,18 +1,22 @@ |
|||||||
package io.legado.app.ui.widget.page |
package io.legado.app.ui.widget.page |
||||||
|
|
||||||
import android.widget.TextView |
import io.legado.app.data.entities.BookChapter |
||||||
|
|
||||||
|
|
||||||
class ChapterProvider { |
class ChapterProvider { |
||||||
|
|
||||||
|
|
||||||
fun getTextChapter(textView: TextView, content: String) { |
fun getTextChapter(textView: ContentTextView, bookChapter: BookChapter, content: String): TextChapter { |
||||||
|
val textPages = arrayListOf<TextPage>() |
||||||
textView.text = content |
var surplusText = content |
||||||
val layout = textView.layout |
var pageIndex = 0 |
||||||
val topOfLastLine = textView.height - textView.paddingTop - textView.paddingBottom - textView.lineHeight |
while (surplusText.isNotEmpty()) { |
||||||
val lineNum = layout.getLineForVertical(topOfLastLine) |
textView.text = surplusText |
||||||
val lastCharNum = layout.getLineEnd(lineNum) |
textPages.add(TextPage(pageIndex, surplusText.substring(0, textView.getCharNum()))) |
||||||
|
surplusText = surplusText.substring(textView.getCharNum()) |
||||||
|
pageIndex++ |
||||||
|
} |
||||||
|
return TextChapter(bookChapter.index, textPages) |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in new issue