feat: 优化代码

pull/115/head
kunfei 5 years ago
parent d590cc186a
commit b5457fe80c
  1. 11
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt

@ -28,7 +28,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
private var selectCharStart = 0 private var selectCharStart = 0
private var selectLineEnd = 0 private var selectLineEnd = 0
private var selectCharEnd = 0 private var selectCharEnd = 0
private var textPage: TextPage = TextPage().textToLine() private var textPage: TextPage = TextPage()
//滚动参数 //滚动参数
private val pageFactory: TextPageFactory get() = callBack.pageFactory private val pageFactory: TextPageFactory get() = callBack.pageFactory
private val maxScrollOffset = 100f private val maxScrollOffset = 100f
@ -49,11 +49,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh) super.onSizeChanged(w, h, oldw, oldh)
ReadBookConfig.let { ChapterProvider.viewWidth = w
ChapterProvider.viewWidth = w ChapterProvider.viewHeight = h
ChapterProvider.viewHeight = h ChapterProvider.upSize()
ChapterProvider.upSize() textPage.format()
}
} }
override fun onDraw(canvas: Canvas) { override fun onDraw(canvas: Canvas) {

@ -18,8 +18,8 @@ data class TextPage(
) { ) {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
fun textToLine(): TextPage { fun format(): TextPage {
if (textLines.isEmpty()) { if (textLines.isEmpty() && ChapterProvider.visibleWidth > 0) {
val layout = StaticLayout( val layout = StaticLayout(
text, ChapterProvider.contentPaint, ChapterProvider.visibleWidth, text, ChapterProvider.contentPaint, ChapterProvider.visibleWidth,
Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false

Loading…
Cancel
Save