feat: 优化代码

pull/111/head
kunfei 5 years ago
parent dc25ffa3dc
commit 9b128ab5f4
  1. 8
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  2. 14
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  3. 24
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt

@ -16,6 +16,7 @@ import io.legado.app.utils.getPrefBoolean
class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) {
private val maxScrollOffset = 100f
private val selectedPaint by lazy {
Paint().apply {
color = context.getCompatColor(R.color.btn_bg_press_2)
@ -84,6 +85,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
fun onScroll(offset: Float) {
var mOffset = offset
if (offset > maxScrollOffset) {
mOffset = maxScrollOffset
} else if (offset < -maxScrollOffset) {
mOffset = -maxScrollOffset
}
}

@ -135,20 +135,6 @@ class ContentView(context: Context) : FrameLayout(context) {
val selectedText: String get() = content_text_view.selectedText
fun scrollTo(pos: Int?) {
if (pos != null) {
content_text_view.post {
}
}
}
fun scrollToBottom() {
content_text_view.post {
}
}
interface CallBack {
fun scrollToLine(line: Int)
fun scrollToLast()

@ -75,16 +75,10 @@ class PageView(context: Context, attrs: AttributeSet) :
PageDelegate.Direction.PREV -> {
pageFactory?.moveToPrevious()
upContent()
if (isScrollDelegate) {
curPage.scrollToBottom()
}
}
PageDelegate.Direction.NEXT -> {
pageFactory?.moveToNext()
upContent()
if (isScrollDelegate) {
curPage.scrollTo(0)
}
}
else -> Unit
}
@ -112,27 +106,15 @@ class PageView(context: Context, attrs: AttributeSet) :
curPage.setContent(it.currentPage())
nextPage.setContent(it.nextPage())
prevPage.setContent(it.previousPage())
if (isScrollDelegate) {
curPage.scrollTo(ReadBook.textChapter()?.getStartLine(ReadBook.durChapterPos()))
}
}
}
if (isScrollDelegate) {
prevPage.scrollToBottom()
}
}
callBack?.screenOffTimerStart()
}
fun moveToPrevPage(noAnim: Boolean = true) {
if (noAnim) {
if (isScrollDelegate) {
ReadBook.textChapter()?.let {
curPage.scrollTo(it.getStartLine(pageIndex - 1))
}
} else {
fillPage(PageDelegate.Direction.PREV)
}
} else {
pageDelegate?.start(PageDelegate.Direction.PREV)
}
@ -140,13 +122,7 @@ class PageView(context: Context, attrs: AttributeSet) :
fun moveToNextPage(noAnim: Boolean = true) {
if (noAnim) {
if (isScrollDelegate) {
ReadBook.textChapter()?.let {
curPage.scrollTo(it.getStartLine(pageIndex + 1))
}
} else {
fillPage(PageDelegate.Direction.NEXT)
}
} else {
pageDelegate?.start(PageDelegate.Direction.NEXT)
}

Loading…
Cancel
Save