pull/34/head
kunfei 5 years ago
parent 48cf1c7e6d
commit ef5fddf0ef
  1. 12
      app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt
  2. 10
      app/src/main/java/io/legado/app/ui/widget/page/PageScrollView.kt
  3. 6
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt

@ -27,6 +27,7 @@ import java.util.*
class ContentView : FrameLayout { class ContentView : FrameLayout {
private var isScroll: Boolean = false private var isScroll: Boolean = false
var callBack: CallBack? = null
private val bgImage: AppCompatImageView = AppCompatImageView(context) private val bgImage: AppCompatImageView = AppCompatImageView(context)
.apply { .apply {
scaleType = ImageView.ScaleType.CENTER_CROP scaleType = ImageView.ScaleType.CENTER_CROP
@ -55,6 +56,13 @@ class ContentView : FrameLayout {
upTime() upTime()
content_text_view.customSelectionActionModeCallback = content_text_view.customSelectionActionModeCallback =
ContentSelectActionCallback(content_text_view) ContentSelectActionCallback(content_text_view)
page_scroll_view?.scrollListener = object : PageScrollView.OnScrollListener {
override fun onScroll(scrollY: Int) {
content_text_view.layout?.getLineForVertical(scrollY)?.let { line ->
callBack?.scrollToLine(line)
}
}
}
} }
fun upStyle() { fun upStyle() {
@ -126,4 +134,8 @@ class ContentView : FrameLayout {
} }
} }
} }
interface CallBack {
fun scrollToLine(line: Int)
}
} }

@ -6,6 +6,7 @@ import android.widget.ScrollView
class PageScrollView : ScrollView { class PageScrollView : ScrollView {
constructor(context: Context) : super(context) constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
@ -16,5 +17,14 @@ class PageScrollView : ScrollView {
defStyleAttr 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)
}
} }

@ -14,6 +14,7 @@ import io.legado.app.utils.getPrefInt
class PageView(context: Context, attrs: AttributeSet) : class PageView(context: Context, attrs: AttributeSet) :
FrameLayout(context, attrs), FrameLayout(context, attrs),
PageDelegate.PageInterface, PageDelegate.PageInterface,
ContentView.CallBack,
DataSource { DataSource {
private var callback: CallBack? = null private var callback: CallBack? = null
@ -36,6 +37,7 @@ class PageView(context: Context, attrs: AttributeSet) :
setWillNotDraw(false) setWillNotDraw(false)
pageFactory = TextPageFactory.create(this) pageFactory = TextPageFactory.create(this)
upPageAnim() upPageAnim()
curPage?.callBack = this
} }
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
@ -207,6 +209,10 @@ class PageView(context: Context, attrs: AttributeSet) :
callback?.moveToPrevChapter() callback?.moveToPrevChapter()
} }
override fun scrollToLine(line: Int) {
}
interface CallBack { interface CallBack {
fun chapterSize(): Int fun chapterSize(): Int
fun durChapterIndex(): Int fun durChapterIndex(): Int

Loading…
Cancel
Save