pull/34/head
kunfei 5 years ago
parent db112d7453
commit 44a0a4467a
  1. 22
      app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt
  2. 30
      app/src/main/java/io/legado/app/ui/widget/page/PageScrollView.kt
  3. 65
      app/src/main/res/layout/view_book_page_scroll.xml

@ -13,15 +13,9 @@ import io.legado.app.constant.AppConst.TIME_FORMAT
import io.legado.app.help.ImageLoader
import io.legado.app.help.ReadBookConfig
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.view_book_page.view.content_text_view
import kotlinx.android.synthetic.main.view_book_page.view.page_panel
import kotlinx.android.synthetic.main.view_book_page.view.top_bar
import kotlinx.android.synthetic.main.view_book_page.view.tv_bottom_left
import kotlinx.android.synthetic.main.view_book_page.view.tv_bottom_right
import kotlinx.android.synthetic.main.view_book_page.view.tv_top_left
import kotlinx.android.synthetic.main.view_book_page.view.tv_top_right
import kotlinx.android.synthetic.main.view_book_page_scroll.view.*
import kotlinx.android.synthetic.main.view_book_page.view.*
import org.jetbrains.anko.matchParent
import org.jetbrains.anko.sdk27.listeners.onScrollChange
import java.util.*
@ -47,24 +41,18 @@ class ContentView : FrameLayout {
//设置背景防止切换背景时文字重叠
setBackgroundColor(context.getCompatColor(R.color.background))
addView(bgImage, LayoutParams(matchParent, matchParent))
if (isScroll) {
inflate(context, R.layout.view_book_page_scroll, this)
} else {
inflate(context, R.layout.view_book_page, this)
}
top_bar.layoutParams.height = context.getStatusBarHeight()
upStyle()
upTime()
content_text_view.customSelectionActionModeCallback =
ContentSelectActionCallback(content_text_view)
page_scroll_view?.scrollListener = object : PageScrollView.OnScrollListener {
override fun onScroll(scrollY: Int) {
content_text_view.onScrollChange { _, _, scrollY, _, _ ->
content_text_view.layout?.getLineForVertical(scrollY)?.let { line ->
callBack?.scrollToLine(line)
}
}
}
}
fun upStyle() {
ReadBookConfig.getConfig().apply {
@ -137,8 +125,8 @@ class ContentView : FrameLayout {
fun scrollTo(pos: Int?) {
if (pos != null) {
page_scroll_view?.post {
page_scroll_view?.scrollTo(0, content_text_view.layout.getLineTop(pos))
content_text_view.post {
content_text_view.scrollTo(0, content_text_view.layout.getLineTop(pos))
}
}
}

@ -1,30 +0,0 @@
package io.legado.app.ui.widget.page
import android.content.Context
import android.util.AttributeSet
import android.widget.ScrollView
class PageScrollView : ScrollView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)
var scrollListener: OnScrollListener? = null
override fun onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) {
super.onScrollChanged(l, t, oldl, oldt)
scrollListener?.onScroll(t)
}
interface OnScrollListener {
fun onScroll(scrollY: Int)
}
}

@ -1,65 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/page_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:divider="@drawable/ic_divider"
app:showDividers="middle">
<LinearLayout
android:id="@+id/top_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_top_left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_top_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<io.legado.app.ui.widget.page.PageScrollView
android:id="@+id/page_scroll_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="none">
<io.legado.app.ui.widget.page.ContentTextView
android:id="@+id/content_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</io.legado.app.ui.widget.page.PageScrollView>
<LinearLayout
android:id="@+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_bottom_left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true" />
<TextView
android:id="@+id/tv_bottom_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
Loading…
Cancel
Save