feat: 优化代码

pull/115/head
kunfei 5 years ago
parent 284fe6ce56
commit 9c15e9401c
  1. 2
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 8
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt
  4. 11
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  5. 1
      app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt
  6. 4
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt

@ -312,7 +312,7 @@ object ReadBook {
}
interface CallBack {
fun upContent(relativePosition: Int = 0, resetScrollOffset: Boolean = true)
fun upContent(relativePosition: Int = 0)
fun upView()
fun upPageProgress()
fun contentLoadFinish()

@ -456,9 +456,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
/**
* 更新内容
*/
override fun upContent(relativePosition: Int, resetScrollOffset: Boolean) {
override fun upContent(relativePosition: Int) {
launch {
page_view.upContent(relativePosition, resetScrollOffset)
page_view.upContent(relativePosition)
}
}

@ -17,6 +17,8 @@ import io.legado.app.utils.getPrefBoolean
class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) {
var selectAble = context.getPrefBoolean(PreferKey.textSelectAble)
var upView: ((TextPage) -> Unit)? = null
private val selectedPaint by lazy {
Paint().apply {
color = context.getCompatColor(R.color.btn_bg_press_2)
@ -24,7 +26,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
}
private var callBack: CallBack
var selectAble = context.getPrefBoolean(PreferKey.textSelectAble)
private var selectLineStart = 0
private var selectCharStart = 0
private var selectLineEnd = 0
@ -159,12 +160,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
pageFactory.moveToPrev()
textPage = pageFactory.currentPage ?: TextPage().format()
pageOffset -= textPage.height
callBack.upContent(0, false)
upView?.invoke(textPage)
} else if (pageOffset < -textPage.height) {
pageOffset += textPage.height
pageFactory.moveToNext()
textPage = pageFactory.currentPage ?: TextPage().format()
callBack.upContent(0, false)
upView?.invoke(textPage)
}
invalidate()
}
@ -302,7 +303,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
}
interface CallBack {
fun upContent(relativePosition: Int, resetScrollOffset: Boolean)
fun upSelectedStart(x: Float, y: Float)
fun upSelectedEnd(x: Float, y: Float)
fun onCancelSelect()

@ -25,6 +25,11 @@ class ContentView(context: Context) : FrameLayout(context) {
upStyle()
upTime()
content_text_view.upView = {
tv_bottom_left.text = it.title
pageSize = it.pageSize
setPageIndex(it.index)
}
}
fun upStyle() {
@ -91,17 +96,13 @@ class ContentView(context: Context) : FrameLayout(context) {
tv_top_right.text = context.getString(R.string.battery_show, battery)
}
fun setContent(textPage: TextPage?, resetScrollOffset: Boolean = true) {
fun setContent(textPage: TextPage?) {
if (textPage != null) {
tv_bottom_left.text = textPage.title
pageSize = textPage.pageSize
setPageIndex(textPage.index)
if (resetScrollOffset) {
content_text_view.resetPageOffset()
content_text_view.setContent(textPage)
} else {
content_text_view.invalidate()
}
}
}

@ -16,5 +16,4 @@ interface DataSource {
fun hasNextChapter(): Boolean
fun hasPrevChapter(): Boolean
}

@ -98,9 +98,9 @@ class PageView(context: Context, attrs: AttributeSet) :
upContent()
}
fun upContent(relativePosition: Int = 0, resetScrollOffset: Boolean = true) {
fun upContent(relativePosition: Int = 0) {
if (ReadBookConfig.isScroll) {
curPage.setContent(pageFactory.currentPage, resetScrollOffset)
curPage.setContent(pageFactory.currentPage)
} else {
when (relativePosition) {
-1 -> prevPage.setContent(pageFactory.prevPage)

Loading…
Cancel
Save