mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
c873b72513
commit
ce1d23a029
@ -76,7 +76,6 @@ import io.legado.app.ui.book.read.config.TipConfigDialog.Companion.TIP_DIVIDER_C
|
||||
import io.legado.app.ui.book.read.page.ContentTextView
|
||||
import io.legado.app.ui.book.read.page.ReadView
|
||||
import io.legado.app.ui.book.read.page.entities.PageDirection
|
||||
import io.legado.app.ui.book.read.page.provider.TextPageFactory
|
||||
import io.legado.app.ui.book.searchContent.SearchContentActivity
|
||||
import io.legado.app.ui.book.searchContent.SearchResult
|
||||
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
|
||||
@ -212,7 +211,8 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
private val timeBatteryReceiver = TimeBatteryReceiver()
|
||||
private var screenTimeOut: Long = 0
|
||||
private var loadStates: Boolean = false
|
||||
override val pageFactory: TextPageFactory get() = binding.readView.pageFactory
|
||||
override val pageFactory get() = binding.readView.pageFactory
|
||||
override val pageDelegate get() = binding.readView.pageDelegate
|
||||
override val headerHeight: Int get() = binding.readView.curPage.headerHeight
|
||||
private val menuLayoutIsVisible get() = bottomDialog > 0 || binding.readMenu.isVisible
|
||||
private val nextPageDebounce by lazy { Debounce { keyPage(PageDirection.NEXT) } }
|
||||
|
@ -3,7 +3,6 @@ package io.legado.app.ui.book.read.page
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.RectF
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
@ -14,6 +13,7 @@ import io.legado.app.constant.PreferKey
|
||||
import io.legado.app.data.entities.Bookmark
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.model.ReadBook
|
||||
import io.legado.app.ui.book.read.page.delegate.PageDelegate
|
||||
import io.legado.app.ui.book.read.page.entities.TextLine
|
||||
import io.legado.app.ui.book.read.page.entities.TextPage
|
||||
import io.legado.app.ui.book.read.page.entities.TextPos
|
||||
@ -45,7 +45,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
}
|
||||
}
|
||||
private var callBack: CallBack
|
||||
private val visibleRect = RectF()
|
||||
private val visibleRect = ChapterProvider.visibleRect
|
||||
val selectStart = TextPos(0, 0, 0)
|
||||
private val selectEnd = TextPos(0, 0, 0)
|
||||
var textPage: TextPage = TextPage()
|
||||
@ -56,7 +56,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
var reverseEndCursor = false
|
||||
|
||||
//滚动参数
|
||||
private val pageFactory: TextPageFactory get() = callBack.pageFactory
|
||||
private val pageFactory get() = callBack.pageFactory
|
||||
private val pageDelegate get() = callBack.pageDelegate
|
||||
private var pageOffset = 0
|
||||
private val pictureMirror = PictureMirror()
|
||||
private val isNoAnim get() = ReadBook.pageAnim() == PageAnim.noAnim
|
||||
@ -81,23 +82,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
invalidate()
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新绘制区域
|
||||
*/
|
||||
fun upVisibleRect() {
|
||||
visibleRect.set(
|
||||
ChapterProvider.paddingLeft.toFloat(),
|
||||
ChapterProvider.paddingTop.toFloat(),
|
||||
ChapterProvider.visibleRight.toFloat(),
|
||||
ChapterProvider.visibleBottom.toFloat()
|
||||
)
|
||||
}
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
super.onSizeChanged(w, h, oldw, oldh)
|
||||
if (!isMainView) return
|
||||
ChapterProvider.upViewSize(w, h)
|
||||
upVisibleRect()
|
||||
textPage.format()
|
||||
}
|
||||
|
||||
@ -159,17 +147,20 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
}
|
||||
if (!pageFactory.hasPrev() && pageOffset > 0) {
|
||||
pageOffset = 0
|
||||
pageDelegate?.abortAnim()
|
||||
} else if (!pageFactory.hasNext()
|
||||
&& pageOffset < 0
|
||||
&& pageOffset + textPage.height < ChapterProvider.visibleHeight
|
||||
) {
|
||||
val offset = (ChapterProvider.visibleHeight - textPage.height).toInt()
|
||||
pageOffset = min(0, offset)
|
||||
pageDelegate?.abortAnim()
|
||||
} else if (pageOffset > 0) {
|
||||
if (pageFactory.moveToPrev(true)) {
|
||||
pageOffset -= textPage.height.toInt()
|
||||
} else {
|
||||
pageOffset = 0
|
||||
pageDelegate?.abortAnim()
|
||||
}
|
||||
} else if (pageOffset < -textPage.height) {
|
||||
val height = textPage.height
|
||||
@ -177,6 +168,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
pageOffset += height.toInt()
|
||||
} else {
|
||||
pageOffset = -height.toInt()
|
||||
pageDelegate?.abortAnim()
|
||||
}
|
||||
}
|
||||
invalidate()
|
||||
@ -699,6 +691,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
|
||||
interface CallBack {
|
||||
val headerHeight: Int
|
||||
val pageFactory: TextPageFactory
|
||||
val pageDelegate: PageDelegate?
|
||||
val isScroll: Boolean
|
||||
var isSelectingSearchResult: Boolean
|
||||
fun upSelectedStart(x: Float, y: Float, top: Float)
|
||||
|
@ -101,7 +101,6 @@ class PageView(context: Context) : FrameLayout(context) {
|
||||
vwTopDivider.gone(llHeader.isGone || !it.showHeaderLine)
|
||||
vwBottomDivider.gone(llFooter.isGone || !it.showFooterLine)
|
||||
}
|
||||
contentTextView.upVisibleRect()
|
||||
upTime()
|
||||
upBattery(battery)
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
||||
}
|
||||
|
||||
override fun computeScroll() {
|
||||
pageDelegate?.scroll()
|
||||
pageDelegate?.computeScroll()
|
||||
}
|
||||
|
||||
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
|
||||
|
@ -96,7 +96,7 @@ abstract class PageDelegate(protected val readView: ReadView) {
|
||||
viewHeight = height
|
||||
}
|
||||
|
||||
fun scroll() {
|
||||
fun computeScroll() {
|
||||
if (scroller.computeScrollOffset()) {
|
||||
readView.setTouchPoint(scroller.currX.toFloat(), scroller.currY.toFloat())
|
||||
} else if (isStarted) {
|
||||
|
@ -9,7 +9,6 @@ import io.legado.app.model.ReadBook
|
||||
import io.legado.app.ui.book.read.page.ReadView
|
||||
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
||||
|
||||
@Suppress("UnnecessaryVariable")
|
||||
class ScrollPageDelegate(readView: ReadView) : PageDelegate(readView) {
|
||||
|
||||
// 滑动追踪的时间
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.legado.app.ui.book.read.page.provider
|
||||
|
||||
import android.graphics.Paint.FontMetrics
|
||||
import android.graphics.RectF
|
||||
import android.graphics.Typeface
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
@ -133,6 +134,9 @@ object ChapterProvider {
|
||||
var doublePage = false
|
||||
private set
|
||||
|
||||
@JvmStatic
|
||||
var visibleRect = RectF()
|
||||
|
||||
private val titleMeasureHelper = TextMeasure(titlePaint)
|
||||
private val contentMeasureHelper = TextMeasure(contentPaint)
|
||||
|
||||
@ -911,6 +915,14 @@ object ChapterProvider {
|
||||
visibleRight = viewWidth - paddingRight
|
||||
visibleBottom = paddingTop + visibleHeight
|
||||
}
|
||||
|
||||
visibleRect.set(
|
||||
paddingLeft.toFloat(),
|
||||
paddingTop.toFloat(),
|
||||
visibleRight.toFloat(),
|
||||
visibleBottom.toFloat()
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user