From ef5fddf0efaca98401004945eeff394bfea19da4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 21 Sep 2019 20:05:13 +0800 Subject: [PATCH] up --- .../java/io/legado/app/ui/widget/page/ContentView.kt | 12 ++++++++++++ .../io/legado/app/ui/widget/page/PageScrollView.kt | 10 ++++++++++ .../java/io/legado/app/ui/widget/page/PageView.kt | 6 ++++++ 3 files changed, 28 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt index 9383adb15..441402562 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt @@ -27,6 +27,7 @@ import java.util.* class ContentView : FrameLayout { private var isScroll: Boolean = false + var callBack: CallBack? = null private val bgImage: AppCompatImageView = AppCompatImageView(context) .apply { scaleType = ImageView.ScaleType.CENTER_CROP @@ -55,6 +56,13 @@ class ContentView : FrameLayout { upTime() content_text_view.customSelectionActionModeCallback = 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() { @@ -126,4 +134,8 @@ class ContentView : FrameLayout { } } } + + interface CallBack { + fun scrollToLine(line: Int) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageScrollView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageScrollView.kt index 4ba6abb9b..dc85416ed 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageScrollView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageScrollView.kt @@ -6,6 +6,7 @@ import android.widget.ScrollView class PageScrollView : ScrollView { + constructor(context: Context) : super(context) constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) @@ -16,5 +17,14 @@ class PageScrollView : ScrollView { 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) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index 7bf865314..dd80a278c 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -14,6 +14,7 @@ import io.legado.app.utils.getPrefInt class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), PageDelegate.PageInterface, + ContentView.CallBack, DataSource { private var callback: CallBack? = null @@ -36,6 +37,7 @@ class PageView(context: Context, attrs: AttributeSet) : setWillNotDraw(false) pageFactory = TextPageFactory.create(this) upPageAnim() + curPage?.callBack = this } override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { @@ -207,6 +209,10 @@ class PageView(context: Context, attrs: AttributeSet) : callback?.moveToPrevChapter() } + override fun scrollToLine(line: Int) { + + } + interface CallBack { fun chapterSize(): Int fun durChapterIndex(): Int