feat: 优化代码

pull/115/head
kunfei 5 years ago
parent 9f46589320
commit af31324bb7
  1. 4
      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. 3
      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. 7
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  6. 4
      app/src/main/res/layout/dialog_read_aloud.xml
  7. 1
      app/src/main/res/values/strings.xml

@ -133,7 +133,7 @@ object ReadBook {
curPageChanged()
}
fun curPageChanged() {
private fun curPageChanged() {
callBack?.upPageProgress()
if (BaseReadAloudService.isRun) {
readAloud(!BaseReadAloudService.pause)
@ -312,7 +312,7 @@ object ReadBook {
}
interface CallBack {
fun upContent(position: Int = 0)
fun upContent(relativePosition: Int = 0, resetScrollOffset: Boolean = true)
fun upView()
fun upPageProgress()
fun contentLoadFinish()

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

@ -160,10 +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)
} else if (pageOffset < -textPage.height) {
pageOffset += textPage.height
pageFactory.moveToNext()
textPage = pageFactory.currentPage ?: TextPage().format()
callBack.upContent(0, false)
}
invalidate()
}
@ -301,6 +303,7 @@ 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()

@ -91,12 +91,15 @@ class ContentView(context: Context) : FrameLayout(context) {
tv_top_right.text = context.getString(R.string.battery_show, battery)
}
fun setContent(textPage: TextPage?) {
fun setContent(textPage: TextPage?, resetScrollOffset: Boolean = true) {
if (textPage != null) {
content_text_view.setContent(textPage)
tv_bottom_left.text = textPage.title
pageSize = textPage.pageSize
setPageIndex(textPage.index)
if (resetScrollOffset) {
content_text_view.resetPageOffset()
content_text_view.setContent(textPage)
}
}
}
@ -111,10 +114,6 @@ class ContentView(context: Context) : FrameLayout(context) {
content_text_view.onScroll(offset)
}
fun resetPageOffset() {
content_text_view.resetPageOffset()
}
fun upSelectAble(selectAble: Boolean) {
content_text_view.selectAble = selectAble
}

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

@ -154,8 +154,8 @@
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:tooltipText="@string/other_setting"
android:contentDescription="@string/other_setting"
android:tooltipText="@string/other_aloud_setting"
android:contentDescription="@string/other_aloud_setting"
android:src="@drawable/ic_settings"
android:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />

@ -626,4 +626,5 @@
<string name="more_menu">更多菜单</string>
<string name="reduce"></string>
<string name="plus"></string>
<string name="other_aloud_setting">其它朗读设置</string>
</resources>

Loading…
Cancel
Save