From 8079f7a5892144906c4430dbf1b11801d12a1dd8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 09:16:53 +0800 Subject: [PATCH 01/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookActivity.kt | 9 +- .../legado/app/ui/book/read/TextActionMenu.kt | 6 +- .../app/ui/book/read/page/ChapterProvider.kt | 8 +- .../read/page/content/BaseContentTextView.kt | 113 ++++++++++++++++++ .../page/{ => content}/ContentTextView.kt | 111 +---------------- app/src/main/res/layout/view_book_page.xml | 2 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 8 files changed, 136 insertions(+), 119 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt rename app/src/main/java/io/legado/app/ui/book/read/page/{ => content}/ContentTextView.kt (69%) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 16b198626..7b68d844d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -8,7 +8,6 @@ import android.os.Bundle import android.os.Handler import android.view.* import android.view.ViewGroup.LayoutParams.WRAP_CONTENT -import androidx.appcompat.view.menu.MenuItemImpl import androidx.core.view.get import androidx.core.view.isVisible import androidx.core.view.size @@ -35,9 +34,9 @@ import io.legado.app.ui.book.read.config.* import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR import io.legado.app.ui.book.read.page.ChapterProvider -import io.legado.app.ui.book.read.page.ContentTextView import io.legado.app.ui.book.read.page.PageView import io.legado.app.ui.book.read.page.TextPageFactory +import io.legado.app.ui.book.read.page.content.BaseContentTextView import io.legado.app.ui.book.read.page.delegate.PageDelegate import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.changesource.ChangeSourceDialog @@ -59,7 +58,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo View.OnTouchListener, PageView.CallBack, TextActionMenu.CallBack, - ContentTextView.CallBack, + BaseContentTextView.CallBack, ReadMenu.CallBack, ReadAloudDialog.CallBack, ChangeSourceDialog.CallBack, @@ -403,8 +402,8 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 文本选择菜单操作 */ - override fun onMenuItemSelected(item: MenuItemImpl): Boolean { - when (item.itemId) { + override fun onMenuItemSelected(itemId: Int): Boolean { + when (itemId) { R.id.menu_replace -> { ReplaceEditDialog.show(supportFragmentManager, pattern = selectedText) return true diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index fe56a18be..9d0959177 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -27,7 +27,7 @@ import kotlinx.android.synthetic.main.popup_action_menu.view.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.toast - +@SuppressLint("RestrictedApi") class TextActionMenu(private val context: Context, private val callBack: CallBack) : PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) { @@ -70,7 +70,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { getItem(holder.layoutPosition)?.let { - if (!callBack.onMenuItemSelected(it)) { + if (!callBack.onMenuItemSelected(it.itemId)) { onMenuItemSelected(it) } } @@ -150,7 +150,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac interface CallBack { val selectedText: String - fun onMenuItemSelected(item: MenuItemImpl): Boolean + fun onMenuItemSelected(itemId: Int): Boolean fun onMenuActionFinally() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 74136ba5c..7618ddc51 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -23,10 +23,12 @@ import io.legado.app.utils.removePref object ChapterProvider { var viewWidth = 0 var viewHeight = 0 - var visibleWidth = 0 - var visibleHeight = 0 var paddingLeft = 0 var paddingTop = 0 + var visibleWidth = 0 + var visibleHeight = 0 + var visibleRight = 0 + var visibleBottom = 0 private var lineSpacingExtra = 0f private var paragraphSpacing = 0 var typeface: Typeface = Typeface.SANS_SERIF @@ -342,6 +344,8 @@ object ChapterProvider { paddingTop = ReadBookConfig.paddingTop.dp visibleWidth = viewWidth - paddingLeft - ReadBookConfig.paddingRight.dp visibleHeight = viewHeight - paddingTop - ReadBookConfig.paddingBottom.dp + visibleRight = paddingLeft + visibleWidth + visibleBottom = paddingTop + visibleHeight } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt new file mode 100644 index 000000000..0f0693db3 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt @@ -0,0 +1,113 @@ +package io.legado.app.ui.book.read.page.content + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Paint +import android.util.AttributeSet +import android.view.View +import io.legado.app.R +import io.legado.app.constant.PreferKey +import io.legado.app.help.ReadBookConfig +import io.legado.app.lib.theme.accentColor +import io.legado.app.ui.book.read.page.ChapterProvider +import io.legado.app.ui.book.read.page.TextPageFactory +import io.legado.app.ui.book.read.page.entities.TextChar +import io.legado.app.ui.book.read.page.entities.TextPage +import io.legado.app.utils.activity +import io.legado.app.utils.getCompatColor +import io.legado.app.utils.getPrefBoolean + +abstract class BaseContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) { + + var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) + var upView: ((TextPage) -> Unit)? = null + protected val selectedPaint by lazy { + Paint().apply { + color = context.getCompatColor(R.color.btn_bg_press_2) + style = Paint.Style.FILL + } + } + protected var callBack: CallBack + protected var selectLineStart = 0 + protected var selectCharStart = 0 + protected var selectLineEnd = 0 + protected var selectCharEnd = 0 + protected var textPage: TextPage = TextPage() + //滚动参数 + protected val pageFactory: TextPageFactory get() = callBack.pageFactory + protected val maxScrollOffset = 100f + protected var pageOffset = 0f + protected var linePos = 0 + + init { + callBack = activity as CallBack + contentDescription = textPage.text + } + + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + ChapterProvider.viewWidth = w + ChapterProvider.viewHeight = h + ChapterProvider.upSize() + textPage.format() + } + + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + canvas.clipRect( + ChapterProvider.paddingLeft, + ChapterProvider.paddingTop, + ChapterProvider.visibleRight, + ChapterProvider.visibleBottom + ) + if (ReadBookConfig.isScroll) { + drawScrollPage(canvas) + } else { + drawHorizontalPage(canvas) + } + } + + abstract fun drawScrollPage(canvas: Canvas) + + abstract fun drawHorizontalPage(canvas: Canvas) + + protected fun drawChars( + canvas: Canvas, + textChars: List, + lineTop: Float, + lineBase: Float, + lineBottom: Float, + isTitle: Boolean, + isReadAloud: Boolean + ) { + val textPaint = if (isTitle) ChapterProvider.titlePaint else ChapterProvider.contentPaint + textPaint.color = + if (isReadAloud) context.accentColor else ReadBookConfig.durConfig.textColor() + textChars.forEach { + canvas.drawText(it.charData, it.start, lineBase, textPaint) + if (it.selected) { + canvas.drawRect(it.start, lineTop, it.end, lineBottom, selectedPaint) + } + } + } + + + protected fun upSelectedStart(x: Float, y: Float) { + callBack.upSelectedStart(x, y + callBack.headerHeight) + } + + protected fun upSelectedEnd(x: Float, y: Float) { + callBack.upSelectedEnd(x, y + callBack.headerHeight) + } + + + interface CallBack { + fun upSelectedStart(x: Float, y: Float) + fun upSelectedEnd(x: Float, y: Float) + fun onCancelSelect() + val headerHeight: Int + val pageFactory: TextPageFactory + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt similarity index 69% rename from app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt rename to app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt index 7d2262824..be3057a48 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt @@ -1,46 +1,14 @@ -package io.legado.app.ui.book.read.page +package io.legado.app.ui.book.read.page.content import android.content.Context import android.graphics.Canvas -import android.graphics.Paint import android.util.AttributeSet -import android.view.View -import io.legado.app.R -import io.legado.app.constant.PreferKey -import io.legado.app.help.ReadBookConfig -import io.legado.app.lib.theme.accentColor -import io.legado.app.ui.book.read.page.entities.TextChar +import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.entities.TextPage -import io.legado.app.utils.activity -import io.legado.app.utils.getCompatColor -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) - style = Paint.Style.FILL - } - } - private var callBack: CallBack - private var selectLineStart = 0 - private var selectCharStart = 0 - private var selectLineEnd = 0 - private var selectCharEnd = 0 - private var textPage: TextPage = TextPage() - //滚动参数 - private val pageFactory: TextPageFactory get() = callBack.pageFactory - private val maxScrollOffset = 100f - private var pageOffset = 0f - private var linePos = 0 - - init { - callBack = activity as CallBack - contentDescription = textPage.text - } +class ContentTextView(context: Context, attrs: AttributeSet?) : + BaseContentTextView(context, attrs) { fun setContent(textPage: TextPage) { this.textPage = textPage @@ -48,24 +16,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at invalidate() } - override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { - super.onSizeChanged(w, h, oldw, oldh) - ChapterProvider.viewWidth = w - ChapterProvider.viewHeight = h - ChapterProvider.upSize() - textPage.format() - } - - override fun onDraw(canvas: Canvas) { - super.onDraw(canvas) - if (ReadBookConfig.isScroll) { - drawScrollPage(canvas) - } else { - drawHorizontalPage(canvas) - } - } - - private fun drawHorizontalPage(canvas: Canvas) { + override fun drawHorizontalPage(canvas: Canvas) { textPage.textLines.forEach { textLine -> drawChars( canvas, @@ -79,7 +30,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } - private fun drawScrollPage(canvas: Canvas) { + override fun drawScrollPage(canvas: Canvas) { val mPageOffset = pageOffset textPage.textLines.forEach { textLine -> val lineTop = textLine.lineTop + mPageOffset @@ -110,41 +61,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at textLine.isReadAloud ) } - pageFactory.prevPage?.textLines?.forEach { textLine -> - val yPy = mPageOffset + ChapterProvider.paddingTop - val lineTop = -textLine.lineTop + yPy - val lineBase = -textLine.lineBase + yPy - val lineBottom = -textLine.lineBottom + yPy - drawChars( - canvas, - textLine.textChars, - lineTop, - lineBase, - lineBottom, - textLine.isTitle, - textLine.isReadAloud - ) - } - } - - private fun drawChars( - canvas: Canvas, - textChars: List, - lineTop: Float, - lineBase: Float, - lineBottom: Float, - isTitle: Boolean, - isReadAloud: Boolean - ) { - val textPaint = if (isTitle) ChapterProvider.titlePaint else ChapterProvider.contentPaint - textPaint.color = - if (isReadAloud) context.accentColor else ReadBookConfig.durConfig.textColor() - textChars.forEach { - canvas.drawText(it.charData, it.start, lineBase, textPaint) - if (it.selected) { - canvas.drawRect(it.start, lineTop, it.end, lineBottom, selectedPaint) - } - } } fun onScroll(mOffset: Float) { @@ -271,14 +187,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at invalidate() } - private fun upSelectedStart(x: Float, y: Float) { - callBack.upSelectedStart(x, y + callBack.headerHeight) - } - - private fun upSelectedEnd(x: Float, y: Float) { - callBack.upSelectedEnd(x, y + callBack.headerHeight) - } - fun cancelSelect() { textPage.textLines.forEach { textLine -> textLine.textChars.forEach { @@ -317,11 +225,4 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at return stringBuilder.toString() } - interface CallBack { - fun upSelectedStart(x: Float, y: Float) - fun upSelectedEnd(x: Float, y: Float) - fun onCancelSelect() - val headerHeight: Int - val pageFactory: TextPageFactory - } } diff --git a/app/src/main/res/layout/view_book_page.xml b/app/src/main/res/layout/view_book_page.xml index 81c9e09d4..325e8a75c 100644 --- a/app/src/main/res/layout/view_book_page.xml +++ b/app/src/main/res/layout/view_book_page.xml @@ -32,7 +32,7 @@ android:background="@color/divider" android:visibility="invisible" /> - Date: Tue, 25 Feb 2020 09:34:44 +0800 Subject: [PATCH 02/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/content/BaseContentTextView.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt index 0f0693db3..036678e5c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt @@ -21,7 +21,7 @@ abstract class BaseContentTextView(context: Context, attrs: AttributeSet?) : Vie var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) var upView: ((TextPage) -> Unit)? = null - protected val selectedPaint by lazy { + private val selectedPaint by lazy { Paint().apply { color = context.getCompatColor(R.color.btn_bg_press_2) style = Paint.Style.FILL @@ -69,9 +69,9 @@ abstract class BaseContentTextView(context: Context, attrs: AttributeSet?) : Vie } } - abstract fun drawScrollPage(canvas: Canvas) + protected abstract fun drawScrollPage(canvas: Canvas) - abstract fun drawHorizontalPage(canvas: Canvas) + protected abstract fun drawHorizontalPage(canvas: Canvas) protected fun drawChars( canvas: Canvas, From d400a67f534145652fa660e49e3220fbf31dff0f Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 09:44:15 +0800 Subject: [PATCH 03/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/read/page/ContentView.kt | 4 ++++ .../io/legado/app/ui/book/read/page/delegate/PageDelegate.kt | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index 512f778a7..2f77ac986 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -105,6 +105,10 @@ class ContentView(context: Context) : FrameLayout(context) { } } + fun resetPageOffset() { + content_text_view.resetPageOffset() + } + @SuppressLint("SetTextI18n") fun setPageIndex(pageIndex: Int?) { pageIndex?.let { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 234ce8097..7c453d9c7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -70,6 +70,10 @@ abstract class PageDelegate(protected val pageView: PageView) : var firstLineIndex: Int = 0 var firstCharIndex: Int = 0 + init { + curPage.resetPageOffset() + } + open fun setStartPoint(x: Float, y: Float, invalidate: Boolean = true) { startX = x startY = y From 1cb1c3b2ea8b0416c4d007ce61d7aacb6089de31 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 09:45:08 +0800 Subject: [PATCH 04/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/content/BaseContentTextView.kt | 1 - .../io/legado/app/ui/book/read/page/content/ContentTextView.kt | 1 - 2 files changed, 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt index 036678e5c..95fd796ea 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt @@ -37,7 +37,6 @@ abstract class BaseContentTextView(context: Context, attrs: AttributeSet?) : Vie protected val pageFactory: TextPageFactory get() = callBack.pageFactory protected val maxScrollOffset = 100f protected var pageOffset = 0f - protected var linePos = 0 init { callBack = activity as CallBack diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt index be3057a48..e1013bb65 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt @@ -89,7 +89,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : fun resetPageOffset() { pageOffset = 0f - linePos = 0 } fun selectText(x: Float, y: Float, select: (lineIndex: Int, charIndex: Int) -> Unit) { From f753bc33e75274a87972e3ff005371c1f95fffc0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 09:49:19 +0800 Subject: [PATCH 05/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/page/content/ContentTextView.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt index e1013bb65..20e6728b2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt @@ -3,7 +3,6 @@ package io.legado.app.ui.book.read.page.content import android.content.Context import android.graphics.Canvas import android.util.AttributeSet -import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.entities.TextPage @@ -47,7 +46,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : ) } pageFactory.nextPage?.textLines?.forEach { textLine -> - val yPy = mPageOffset + textPage.height - ChapterProvider.paddingTop + val yPy = mPageOffset + textPage.height val lineTop = textLine.lineTop + yPy val lineBase = textLine.lineBase + yPy val lineBottom = textLine.lineBottom + yPy From 854d11b0b07833e4626ee7d1034d49239ec2bcdf Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 10:12:37 +0800 Subject: [PATCH 06/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentView.kt | 14 +++---- .../app/ui/book/read/page/DataSource.kt | 6 +-- .../legado/app/ui/book/read/page/PageView.kt | 9 +++-- .../app/ui/book/read/page/TextPageFactory.kt | 40 +++++++++++++------ .../book/read/page/content/ContentTextView.kt | 7 ++-- 5 files changed, 47 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index 2f77ac986..574020c45 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -95,14 +95,12 @@ class ContentView(context: Context) : FrameLayout(context) { tv_top_right.text = context.getString(R.string.battery_show, battery) } - fun setContent(textPage: TextPage?) { - if (textPage != null) { - tv_bottom_left.text = textPage.title - pageSize = textPage.pageSize - setPageIndex(textPage.index) - content_text_view.resetPageOffset() - content_text_view.setContent(textPage) - } + fun setContent(textPage: TextPage) { + tv_bottom_left.text = textPage.title + pageSize = textPage.pageSize + setPageIndex(textPage.index) + content_text_view.resetPageOffset() + content_text_view.setContent(textPage) } fun resetPageOffset() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt b/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt index 106e2e4db..1d188f598 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt @@ -7,11 +7,11 @@ interface DataSource { val pageIndex: Int get() = ReadBook.durChapterPos() - fun getCurrentChapter(): TextChapter? + val currentChapter: TextChapter? - fun getNextChapter(): TextChapter? + val nextChapter: TextChapter? - fun getPreviousChapter(): TextChapter? + val prevChapter: TextChapter? fun hasNextChapter(): Boolean diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 3009af02e..d5a46d734 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -164,15 +164,18 @@ class PageView(context: Context, attrs: AttributeSet) : nextPage.upBattery(battery) } - override fun getCurrentChapter(): TextChapter? { + override val currentChapter: TextChapter? + get() { return if (callBack.isInitFinish) ReadBook.textChapter(0) else null } - override fun getNextChapter(): TextChapter? { + override val nextChapter: TextChapter? + get() { return if (callBack.isInitFinish) ReadBook.textChapter(1) else null } - override fun getPreviousChapter(): TextChapter? { + override val prevChapter: TextChapter? + get() { return if (callBack.isInitFinish) ReadBook.textChapter(-1) else null } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt b/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt index 307423955..f10f99c5a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt @@ -10,7 +10,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource } override fun hasNext(): Boolean = with(dataSource) { - return hasNextChapter() || getCurrentChapter()?.isLastIndex(pageIndex) != true + return hasNextChapter() || currentChapter?.isLastIndex(pageIndex) != true } override fun moveToFirst() { @@ -18,7 +18,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource } override fun moveToLast() = with(dataSource) { - getCurrentChapter()?.let { + currentChapter?.let { if (it.pageSize() == 0) { ReadBook.setPageIndex(0) } else { @@ -29,7 +29,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource override fun moveToNext(): Boolean = with(dataSource) { return if (hasNext()) { - if (getCurrentChapter()?.isLastIndex(pageIndex) == true) { + if (currentChapter?.isLastIndex(pageIndex) == true) { ReadBook.moveToNextChapter(false) } else { ReadBook.setPageIndex(pageIndex.plus(1)) @@ -51,27 +51,43 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource false } - override val currentPage: TextPage? + override val currentPage: TextPage get() = with(dataSource) { - return getCurrentChapter()?.page(pageIndex) + currentChapter?.let { + return@with it.page(pageIndex) + ?: TextPage(title = it.title).format() + } + return TextPage().format() } - override val nextPage: TextPage? + override val nextPage: TextPage get() = with(dataSource) { - getCurrentChapter()?.let { + currentChapter?.let { if (pageIndex < it.pageSize() - 1) { - return getCurrentChapter()?.page(pageIndex + 1)?.removePageAloudSpan() + return@with it.page(pageIndex + 1)?.removePageAloudSpan() + ?: TextPage(title = it.title).format() } } - return getNextChapter()?.page(0)?.removePageAloudSpan() + nextChapter?.let { + return@with it.page(0)?.removePageAloudSpan() + ?: TextPage(title = it.title).format() + } + return TextPage().format() } - override val prevPage: TextPage? + override val prevPage: TextPage get() = with(dataSource) { if (pageIndex > 0) { - return getCurrentChapter()?.page(pageIndex - 1)?.removePageAloudSpan() + currentChapter?.let { + return@with it.page(pageIndex - 1)?.removePageAloudSpan() + ?: TextPage(title = it.title).format() + } + } + prevChapter?.let { + return@with it.lastPage()?.removePageAloudSpan() + ?: TextPage(title = it.title).format() } - return getPreviousChapter()?.lastPage()?.removePageAloudSpan() + return TextPage().format() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt index 20e6728b2..7bb9c4d6e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt @@ -45,7 +45,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : textLine.isReadAloud ) } - pageFactory.nextPage?.textLines?.forEach { textLine -> + pageFactory.nextPage.textLines.forEach { textLine -> val yPy = mPageOffset + textPage.height val lineTop = textLine.lineTop + yPy val lineBase = textLine.lineBase + yPy @@ -60,6 +60,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : textLine.isReadAloud ) } + } fun onScroll(mOffset: Float) { @@ -74,13 +75,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : pageOffset += offset if (pageOffset > 0) { pageFactory.moveToPrev() - textPage = pageFactory.currentPage ?: TextPage().format() + textPage = pageFactory.currentPage pageOffset -= textPage.height upView?.invoke(textPage) } else if (pageOffset < -textPage.height) { pageOffset += textPage.height pageFactory.moveToNext() - textPage = pageFactory.currentPage ?: TextPage().format() + textPage = pageFactory.currentPage upView?.invoke(textPage) } invalidate() From aafa690692629a699c5841b899137440718c3098 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 10:39:52 +0800 Subject: [PATCH 07/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/PageFactory.kt | 8 ++++--- .../app/ui/book/read/page/TextPageFactory.kt | 18 +++++++++++++++ .../book/read/page/content/ContentTextView.kt | 22 +++++++++++++++++-- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt index db504b6f4..85cdecbd5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt @@ -10,11 +10,13 @@ abstract class PageFactory(protected val dataSource: DataSource) { abstract fun moveToPrev(): Boolean - abstract val nextPage: DATA? + abstract val nextPage: DATA - abstract val prevPage: DATA? + abstract val prevPage: DATA - abstract val currentPage: DATA? + abstract val currentPage: DATA + + abstract val nextPagePlus: DATA abstract fun hasNext(): Boolean diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt b/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt index f10f99c5a..fe18f1b26 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt @@ -90,5 +90,23 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource return TextPage().format() } + override val nextPagePlus: TextPage + get() = with(dataSource) { + currentChapter?.let { + if (pageIndex < it.pageSize() - 2) { + return@with it.page(pageIndex + 2)?.removePageAloudSpan() + ?: TextPage(title = it.title).format() + } + nextChapter?.let { nc -> + if (pageIndex < it.pageSize() - 1) { + return@with nc.page(0)?.removePageAloudSpan() + ?: TextPage(title = nc.title).format() + } + return@with nc.page(1)?.removePageAloudSpan() + ?: TextPage(title = nc.title).format() + } + } + return TextPage().format() + } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt index 7bb9c4d6e..4060012af 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.book.read.page.content import android.content.Context import android.graphics.Canvas import android.util.AttributeSet +import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.entities.TextPage @@ -45,7 +46,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : textLine.isReadAloud ) } - pageFactory.nextPage.textLines.forEach { textLine -> + val nextPage = pageFactory.nextPage + nextPage.textLines.forEach { textLine -> val yPy = mPageOffset + textPage.height val lineTop = textLine.lineTop + yPy val lineBase = textLine.lineBase + yPy @@ -60,7 +62,23 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : textLine.isReadAloud ) } - + if (mPageOffset + textPage.height + nextPage.height < ChapterProvider.visibleHeight) { + pageFactory.nextPagePlus.textLines.forEach { textLine -> + val yPy = mPageOffset + textPage.height + nextPage.height + val lineTop = textLine.lineTop + yPy + val lineBase = textLine.lineBase + yPy + val lineBottom = textLine.lineBottom + yPy + drawChars( + canvas, + textLine.textChars, + lineTop, + lineBase, + lineBottom, + textLine.isTitle, + textLine.isReadAloud + ) + } + } } fun onScroll(mOffset: Float) { From ee1f04f42cfbe4bdadda06eedd1ee1560c6a716b Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 12:05:50 +0800 Subject: [PATCH 08/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/page/ContentView.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index 574020c45..9f2631ea6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -15,7 +15,6 @@ import java.util.* class ContentView(context: Context) : FrameLayout(context) { - private var pageSize: Int = 0 init { //设置背景防止切换背景时文字重叠 @@ -26,8 +25,7 @@ class ContentView(context: Context) : FrameLayout(context) { upTime() content_text_view.upView = { tv_bottom_left.text = it.title - pageSize = it.pageSize - setPageIndex(it.index) + setPageIndex(it.index, it.pageSize) } } @@ -97,8 +95,7 @@ class ContentView(context: Context) : FrameLayout(context) { fun setContent(textPage: TextPage) { tv_bottom_left.text = textPage.title - pageSize = textPage.pageSize - setPageIndex(textPage.index) + setPageIndex(textPage.index, textPage.pageSize) content_text_view.resetPageOffset() content_text_view.setContent(textPage) } @@ -108,7 +105,7 @@ class ContentView(context: Context) : FrameLayout(context) { } @SuppressLint("SetTextI18n") - fun setPageIndex(pageIndex: Int?) { + fun setPageIndex(pageIndex: Int?, pageSize: Int) { pageIndex?.let { tv_bottom_right.text = "${pageIndex.plus(1)}/${pageSize}" } From f800991eeb107fe58a22019897294013f08f09f0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 12:16:33 +0800 Subject: [PATCH 09/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookActivity.kt | 4 +- .../page/{content => }/ContentTextView.kt | 124 ++++++++++++++---- .../read/page/content/BaseContentTextView.kt | 112 ---------------- app/src/main/res/layout/view_book_page.xml | 2 +- 4 files changed, 102 insertions(+), 140 deletions(-) rename app/src/main/java/io/legado/app/ui/book/read/page/{content => }/ContentTextView.kt (68%) delete mode 100644 app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 7b68d844d..cf88a03dd 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -34,9 +34,9 @@ import io.legado.app.ui.book.read.config.* import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR import io.legado.app.ui.book.read.page.ChapterProvider +import io.legado.app.ui.book.read.page.ContentTextView import io.legado.app.ui.book.read.page.PageView import io.legado.app.ui.book.read.page.TextPageFactory -import io.legado.app.ui.book.read.page.content.BaseContentTextView import io.legado.app.ui.book.read.page.delegate.PageDelegate import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.changesource.ChangeSourceDialog @@ -58,7 +58,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo View.OnTouchListener, PageView.CallBack, TextActionMenu.CallBack, - BaseContentTextView.CallBack, + ContentTextView.CallBack, ReadMenu.CallBack, ReadAloudDialog.CallBack, ChangeSourceDialog.CallBack, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt similarity index 68% rename from app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt rename to app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 4060012af..5f482f8f6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -1,14 +1,45 @@ -package io.legado.app.ui.book.read.page.content +package io.legado.app.ui.book.read.page import android.content.Context import android.graphics.Canvas +import android.graphics.Paint import android.util.AttributeSet -import io.legado.app.ui.book.read.page.ChapterProvider +import android.view.View +import io.legado.app.R +import io.legado.app.constant.PreferKey +import io.legado.app.help.ReadBookConfig +import io.legado.app.lib.theme.accentColor +import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.ui.book.read.page.entities.TextPage +import io.legado.app.utils.activity +import io.legado.app.utils.getCompatColor +import io.legado.app.utils.getPrefBoolean -class ContentTextView(context: Context, attrs: AttributeSet?) : - BaseContentTextView(context, attrs) { +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) + style = Paint.Style.FILL + } + } + private var callBack: CallBack + private var selectLineStart = 0 + private var selectCharStart = 0 + private var selectLineEnd = 0 + private var selectCharEnd = 0 + private var textPage: TextPage = TextPage() + //滚动参数 + private val pageFactory: TextPageFactory get() = callBack.pageFactory + private val maxScrollOffset = 100f + private var pageOffset = 0f + + init { + callBack = activity as CallBack + contentDescription = textPage.text + } fun setContent(textPage: TextPage) { this.textPage = textPage @@ -16,21 +47,26 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : invalidate() } - override fun drawHorizontalPage(canvas: Canvas) { - textPage.textLines.forEach { textLine -> - drawChars( - canvas, - textLine.textChars, - textLine.lineTop, - textLine.lineBase, - textLine.lineBottom, - textLine.isTitle, - textLine.isReadAloud - ) - } + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + ChapterProvider.viewWidth = w + ChapterProvider.viewHeight = h + ChapterProvider.upSize() + textPage.format() } - override fun drawScrollPage(canvas: Canvas) { + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + canvas.clipRect( + ChapterProvider.paddingLeft, + ChapterProvider.paddingTop, + ChapterProvider.visibleRight, + ChapterProvider.visibleBottom + ) + drawPage(canvas) + } + + private fun drawPage(canvas: Canvas) { val mPageOffset = pageOffset textPage.textLines.forEach { textLine -> val lineTop = textLine.lineTop + mPageOffset @@ -46,6 +82,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : textLine.isReadAloud ) } + if (!ReadBookConfig.isScroll) { + return + } val nextPage = pageFactory.nextPage nextPage.textLines.forEach { textLine -> val yPy = mPageOffset + textPage.height @@ -81,6 +120,26 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : } } + private fun drawChars( + canvas: Canvas, + textChars: List, + lineTop: Float, + lineBase: Float, + lineBottom: Float, + isTitle: Boolean, + isReadAloud: Boolean + ) { + val textPaint = if (isTitle) ChapterProvider.titlePaint else ChapterProvider.contentPaint + textPaint.color = + if (isReadAloud) context.accentColor else ReadBookConfig.durConfig.textColor() + textChars.forEach { + canvas.drawText(it.charData, it.start, lineBase, textPaint) + if (it.selected) { + canvas.drawRect(it.start, lineTop, it.end, lineBottom, selectedPaint) + } + } + } + fun onScroll(mOffset: Float) { if (mOffset == 0f) return var offset = mOffset @@ -111,7 +170,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : fun selectText(x: Float, y: Float, select: (lineIndex: Int, charIndex: Int) -> Unit) { for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop && y < textLine.lineBottom) { + if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { textChar.selected = true @@ -120,8 +179,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : selectCharStart = charIndex selectLineEnd = lineIndex selectCharEnd = charIndex - upSelectedStart(textChar.start, textLine.lineBottom) - upSelectedEnd(textChar.end, textLine.lineBottom) + upSelectedStart(textChar.start, textLine.lineBottom + pageOffset) + upSelectedEnd(textChar.end, textLine.lineBottom + pageOffset) select(lineIndex, charIndex) } } @@ -132,7 +191,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : fun selectStartMove(x: Float, y: Float) { for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop && y < textLine.lineBottom) { + if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { if (selectLineStart != lineIndex || selectCharStart != charIndex) { @@ -154,19 +213,19 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : selectCharStart = charIndex val textLine = textPage.textLines[lineIndex] val textChar = textLine.textChars[charIndex] - upSelectedStart(textChar.start, textLine.lineBottom) + upSelectedStart(textChar.start, textLine.lineBottom + pageOffset) upSelectChars(textPage) } fun selectEndMove(x: Float, y: Float) { for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop && y < textLine.lineBottom) { + if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { selectLineEnd = lineIndex selectCharEnd = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom) + upSelectedEnd(textChar.end, textLine.lineBottom + pageOffset) upSelectChars(textPage) } break @@ -182,7 +241,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : selectCharEnd = charIndex val textLine = textPage.textLines[lineIndex] val textChar = textLine.textChars[charIndex] - upSelectedEnd(textChar.end, textLine.lineBottom) + upSelectedEnd(textChar.end, textLine.lineBottom + pageOffset) upSelectChars(textPage) } @@ -204,6 +263,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : invalidate() } + private fun upSelectedStart(x: Float, y: Float) { + callBack.upSelectedStart(x, y + callBack.headerHeight) + } + + private fun upSelectedEnd(x: Float, y: Float) { + callBack.upSelectedEnd(x, y + callBack.headerHeight) + } + fun cancelSelect() { textPage.textLines.forEach { textLine -> textLine.textChars.forEach { @@ -242,4 +309,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : return stringBuilder.toString() } + interface CallBack { + fun upSelectedStart(x: Float, y: Float) + fun upSelectedEnd(x: Float, y: Float) + fun onCancelSelect() + val headerHeight: Int + val pageFactory: TextPageFactory + } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt deleted file mode 100644 index 95fd796ea..000000000 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt +++ /dev/null @@ -1,112 +0,0 @@ -package io.legado.app.ui.book.read.page.content - -import android.content.Context -import android.graphics.Canvas -import android.graphics.Paint -import android.util.AttributeSet -import android.view.View -import io.legado.app.R -import io.legado.app.constant.PreferKey -import io.legado.app.help.ReadBookConfig -import io.legado.app.lib.theme.accentColor -import io.legado.app.ui.book.read.page.ChapterProvider -import io.legado.app.ui.book.read.page.TextPageFactory -import io.legado.app.ui.book.read.page.entities.TextChar -import io.legado.app.ui.book.read.page.entities.TextPage -import io.legado.app.utils.activity -import io.legado.app.utils.getCompatColor -import io.legado.app.utils.getPrefBoolean - -abstract class BaseContentTextView(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) - style = Paint.Style.FILL - } - } - protected var callBack: CallBack - protected var selectLineStart = 0 - protected var selectCharStart = 0 - protected var selectLineEnd = 0 - protected var selectCharEnd = 0 - protected var textPage: TextPage = TextPage() - //滚动参数 - protected val pageFactory: TextPageFactory get() = callBack.pageFactory - protected val maxScrollOffset = 100f - protected var pageOffset = 0f - - init { - callBack = activity as CallBack - contentDescription = textPage.text - } - - - override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { - super.onSizeChanged(w, h, oldw, oldh) - ChapterProvider.viewWidth = w - ChapterProvider.viewHeight = h - ChapterProvider.upSize() - textPage.format() - } - - - override fun onDraw(canvas: Canvas) { - super.onDraw(canvas) - canvas.clipRect( - ChapterProvider.paddingLeft, - ChapterProvider.paddingTop, - ChapterProvider.visibleRight, - ChapterProvider.visibleBottom - ) - if (ReadBookConfig.isScroll) { - drawScrollPage(canvas) - } else { - drawHorizontalPage(canvas) - } - } - - protected abstract fun drawScrollPage(canvas: Canvas) - - protected abstract fun drawHorizontalPage(canvas: Canvas) - - protected fun drawChars( - canvas: Canvas, - textChars: List, - lineTop: Float, - lineBase: Float, - lineBottom: Float, - isTitle: Boolean, - isReadAloud: Boolean - ) { - val textPaint = if (isTitle) ChapterProvider.titlePaint else ChapterProvider.contentPaint - textPaint.color = - if (isReadAloud) context.accentColor else ReadBookConfig.durConfig.textColor() - textChars.forEach { - canvas.drawText(it.charData, it.start, lineBase, textPaint) - if (it.selected) { - canvas.drawRect(it.start, lineTop, it.end, lineBottom, selectedPaint) - } - } - } - - - protected fun upSelectedStart(x: Float, y: Float) { - callBack.upSelectedStart(x, y + callBack.headerHeight) - } - - protected fun upSelectedEnd(x: Float, y: Float) { - callBack.upSelectedEnd(x, y + callBack.headerHeight) - } - - - interface CallBack { - fun upSelectedStart(x: Float, y: Float) - fun upSelectedEnd(x: Float, y: Float) - fun onCancelSelect() - val headerHeight: Int - val pageFactory: TextPageFactory - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/view_book_page.xml b/app/src/main/res/layout/view_book_page.xml index 325e8a75c..81c9e09d4 100644 --- a/app/src/main/res/layout/view_book_page.xml +++ b/app/src/main/res/layout/view_book_page.xml @@ -32,7 +32,7 @@ android:background="@color/divider" android:visibility="invisible" /> - Date: Tue, 25 Feb 2020 12:22:37 +0800 Subject: [PATCH 10/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/page/ContentTextView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 5f482f8f6..8c88fe856 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -197,7 +197,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (selectLineStart != lineIndex || selectCharStart != charIndex) { selectLineStart = lineIndex selectCharStart = charIndex - upSelectedStart(textChar.start, textLine.lineBottom) + upSelectedStart(textChar.start, textLine.lineBottom + pageOffset) upSelectChars(textPage) } break From 37d5643b8daa6d650905895d34ae662fe9b713eb Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 12:32:13 +0800 Subject: [PATCH 11/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 8c88fe856..4cd54223b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.book.read.page import android.content.Context import android.graphics.Canvas import android.graphics.Paint +import android.graphics.RectF import android.util.AttributeSet import android.view.View import io.legado.app.R @@ -26,6 +27,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } private var callBack: CallBack + private val visibleRect = RectF() private var selectLineStart = 0 private var selectCharStart = 0 private var selectLineEnd = 0 @@ -52,17 +54,18 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ChapterProvider.viewWidth = w ChapterProvider.viewHeight = h ChapterProvider.upSize() + visibleRect.set( + ChapterProvider.paddingLeft.toFloat(), + ChapterProvider.paddingTop.toFloat(), + ChapterProvider.visibleRight.toFloat(), + ChapterProvider.visibleBottom.toFloat() + ) textPage.format() } override fun onDraw(canvas: Canvas) { super.onDraw(canvas) - canvas.clipRect( - ChapterProvider.paddingLeft, - ChapterProvider.paddingTop, - ChapterProvider.visibleRight, - ChapterProvider.visibleBottom - ) + canvas.clipRect(visibleRect) drawPage(canvas) } @@ -169,6 +172,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } fun selectText(x: Float, y: Float, select: (lineIndex: Int, charIndex: Int) -> Unit) { + if (!visibleRect.contains(x, y)) return for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { @@ -190,6 +194,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } fun selectStartMove(x: Float, y: Float) { + if (!visibleRect.contains(x, y)) return for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { @@ -218,6 +223,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } fun selectEndMove(x: Float, y: Float) { + if (!visibleRect.contains(x, y)) return for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { From 4337c773ff51958429b414395f6492431fd536da Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 13:43:40 +0800 Subject: [PATCH 12/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 263 +++++++++++++++--- .../app/ui/book/read/page/ContentView.kt | 13 +- .../book/read/page/delegate/PageDelegate.kt | 39 ++- 3 files changed, 256 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 4cd54223b..cc366e886 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -28,8 +28,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } private var callBack: CallBack private val visibleRect = RectF() + private var selectPageStart = 0 private var selectLineStart = 0 private var selectCharStart = 0 + private var selectPageEnd = 0 private var selectLineEnd = 0 private var selectCharEnd = 0 private var textPage: TextPage = TextPage() @@ -69,12 +71,15 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at drawPage(canvas) } + /** + * 绘制页面 + */ private fun drawPage(canvas: Canvas) { - val mPageOffset = pageOffset + var relativeOffset = relativeOffset(0) textPage.textLines.forEach { textLine -> - val lineTop = textLine.lineTop + mPageOffset - val lineBase = textLine.lineBase + mPageOffset - val lineBottom = textLine.lineBottom + mPageOffset + val lineTop = textLine.lineTop + relativeOffset + val lineBase = textLine.lineBase + relativeOffset + val lineBottom = textLine.lineBottom + relativeOffset drawChars( canvas, textLine.textChars, @@ -85,15 +90,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at textLine.isReadAloud ) } - if (!ReadBookConfig.isScroll) { - return - } - val nextPage = pageFactory.nextPage + if (!ReadBookConfig.isScroll) return + //滚动翻页 + val nextPage = relativePage(1) + relativeOffset = relativeOffset(1) nextPage.textLines.forEach { textLine -> - val yPy = mPageOffset + textPage.height - val lineTop = textLine.lineTop + yPy - val lineBase = textLine.lineBase + yPy - val lineBottom = textLine.lineBottom + yPy + val lineTop = textLine.lineTop + relativeOffset + val lineBase = textLine.lineBase + relativeOffset + val lineBottom = textLine.lineBottom + relativeOffset drawChars( canvas, textLine.textChars, @@ -104,12 +108,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at textLine.isReadAloud ) } - if (mPageOffset + textPage.height + nextPage.height < ChapterProvider.visibleHeight) { - pageFactory.nextPagePlus.textLines.forEach { textLine -> - val yPy = mPageOffset + textPage.height + nextPage.height - val lineTop = textLine.lineTop + yPy - val lineBase = textLine.lineBase + yPy - val lineBottom = textLine.lineBottom + yPy + relativeOffset = relativeOffset(2) + if (relativeOffset < ChapterProvider.visibleHeight) { + relativePage(2).textLines.forEach { textLine -> + val lineTop = textLine.lineTop + relativeOffset + val lineBase = textLine.lineBase + relativeOffset + val lineBottom = textLine.lineBottom + relativeOffset drawChars( canvas, textLine.textChars, @@ -123,6 +127,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + /** + * 绘制文字 + */ private fun drawChars( canvas: Canvas, textChars: List, @@ -143,6 +150,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + /** + * 滚动事件 + */ fun onScroll(mOffset: Float) { if (mOffset == 0f) return var offset = mOffset @@ -171,83 +181,232 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at pageOffset = 0f } - fun selectText(x: Float, y: Float, select: (lineIndex: Int, charIndex: Int) -> Unit) { + /** + * 选择初始文字 + */ + fun selectText( + x: Float, + y: Float, + select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit + ) { if (!visibleRect.contains(x, y)) return + var relativeOffset = relativeOffset(0) for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + textChar.selected = true + invalidate() + selectPageStart = 0 + selectLineStart = lineIndex + selectCharStart = charIndex + selectPageEnd = 0 + selectLineEnd = lineIndex + selectCharEnd = charIndex + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + select(0, lineIndex, charIndex) + return + } + } + return + } + } + if (!ReadBookConfig.isScroll) return + //滚动翻页 + relativeOffset = relativeOffset(1) + if (relativeOffset >= ChapterProvider.visibleHeight) return + val nextPage = relativePage(1) + for ((lineIndex, textLine) in nextPage.textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + textChar.selected = true + invalidate() + selectPageStart = 1 + selectLineStart = lineIndex + selectCharStart = charIndex + selectPageEnd = 1 + selectLineEnd = lineIndex + selectCharEnd = charIndex + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + select(1, lineIndex, charIndex) + return + } + } + return + } + } + relativeOffset = relativeOffset(2) + if (relativeOffset >= ChapterProvider.visibleHeight) return + for ((lineIndex, textLine) in relativePage(2).textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { textChar.selected = true invalidate() + selectPageStart = 2 selectLineStart = lineIndex selectCharStart = charIndex + selectPageEnd = 2 selectLineEnd = lineIndex selectCharEnd = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + pageOffset) - upSelectedEnd(textChar.end, textLine.lineBottom + pageOffset) - select(lineIndex, charIndex) + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + select(2, lineIndex, charIndex) + return } } - break + return } } } + /** + * 开始选择符移动 + */ fun selectStartMove(x: Float, y: Float) { if (!visibleRect.contains(x, y)) return + var relativeOffset = relativeOffset(0) for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { if (selectLineStart != lineIndex || selectCharStart != charIndex) { + selectPageStart = 0 selectLineStart = lineIndex selectCharStart = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + pageOffset) + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) upSelectChars(textPage) } - break + return } } - break + return + } + } + if (!ReadBookConfig.isScroll) return + //滚动翻页 + relativeOffset = relativeOffset(1) + if (relativeOffset >= ChapterProvider.visibleHeight) return + for ((lineIndex, textLine) in relativePage(1).textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + if (selectLineStart != lineIndex || selectCharStart != charIndex) { + selectPageStart = 1 + selectLineStart = lineIndex + selectCharStart = charIndex + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectChars(textPage) + } + return + } + } + return + } + } + relativeOffset = relativeOffset(2) + if (relativeOffset >= ChapterProvider.visibleHeight) return + for ((lineIndex, textLine) in relativePage(2).textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + if (selectLineStart != lineIndex || selectCharStart != charIndex) { + selectPageStart = 1 + selectLineStart = lineIndex + selectCharStart = charIndex + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectChars(textPage) + } + return + } + } + return } } } - fun selectStartMoveIndex(lineIndex: Int, charIndex: Int) { - selectLineStart = lineIndex - selectCharStart = charIndex - val textLine = textPage.textLines[lineIndex] - val textChar = textLine.textChars[charIndex] - upSelectedStart(textChar.start, textLine.lineBottom + pageOffset) - upSelectChars(textPage) - } - + /** + * 结束选择符移动 + */ fun selectEndMove(x: Float, y: Float) { if (!visibleRect.contains(x, y)) return + var relativeOffset = relativeOffset(0) for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { + selectLineEnd = lineIndex + selectCharEnd = charIndex + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + upSelectChars(textPage) + } + return + } + } + return + } + } + if (!ReadBookConfig.isScroll) return + //滚动翻页 + relativeOffset = relativeOffset(1) + if (relativeOffset >= ChapterProvider.visibleHeight) return + for ((lineIndex, textLine) in relativePage(1).textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { + selectLineEnd = lineIndex + selectCharEnd = charIndex + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + upSelectChars(textPage) + } + return + } + } + return + } + } + relativeOffset = relativeOffset(2) + if (relativeOffset >= ChapterProvider.visibleHeight) return + for ((lineIndex, textLine) in relativePage(2).textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { selectLineEnd = lineIndex selectCharEnd = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom + pageOffset) + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) upSelectChars(textPage) } - break + return } } - break + return } } } - fun selectEndMoveIndex(lineIndex: Int, charIndex: Int) { + fun selectStartMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { + selectPageStart = relativePage + selectLineStart = lineIndex + selectCharStart = charIndex + val textLine = relativePage(relativePage).textLines[lineIndex] + val textChar = textLine.textChars[charIndex] + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(relativePage)) + upSelectChars(textPage) + } + + fun selectEndMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { + selectPageEnd = relativePage selectLineEnd = lineIndex selectCharEnd = charIndex - val textLine = textPage.textLines[lineIndex] + val textLine = relativePage(relativePage).textLines[lineIndex] val textChar = textLine.textChars[charIndex] - upSelectedEnd(textChar.end, textLine.lineBottom + pageOffset) + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(relativePage)) upSelectChars(textPage) } @@ -315,6 +474,22 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at return stringBuilder.toString() } + private fun relativeOffset(relativePos: Int): Float { + return when (relativePos) { + 0 -> pageOffset + 1 -> pageOffset + textPage.height + else -> pageOffset + textPage.height + pageFactory.nextPage.height + } + } + + private fun relativePage(relativePos: Int): TextPage { + return when (relativePos) { + 0 -> textPage + 1 -> pageFactory.nextPage + else -> pageFactory.nextPagePlus + } + } + interface CallBack { fun upSelectedStart(x: Float, y: Float) fun upSelectedEnd(x: Float, y: Float) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index 9f2631ea6..c39ca8f14 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -119,7 +119,10 @@ class ContentView(context: Context) : FrameLayout(context) { content_text_view.selectAble = selectAble } - fun selectText(e: MotionEvent, select: (lineIndex: Int, charIndex: Int) -> Unit) { + fun selectText( + e: MotionEvent, + select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit + ) { val y = e.y - headerHeight return content_text_view.selectText(e.x, y, select) } @@ -128,16 +131,16 @@ class ContentView(context: Context) : FrameLayout(context) { content_text_view.selectStartMove(x, y - headerHeight) } - fun selectStartMoveIndex(lineIndex: Int, charIndex: Int) { - content_text_view.selectStartMoveIndex(lineIndex, charIndex) + fun selectStartMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { + content_text_view.selectStartMoveIndex(relativePage, lineIndex, charIndex) } fun selectEndMove(x: Float, y: Float) { content_text_view.selectEndMove(x, y - headerHeight) } - fun selectEndMoveIndex(lineIndex: Int, charIndex: Int) { - content_text_view.selectEndMoveIndex(lineIndex, charIndex) + fun selectEndMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { + content_text_view.selectEndMoveIndex(relativePage, lineIndex, charIndex) } fun cancelSelect() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 7c453d9c7..e7b76fc6e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -67,6 +67,7 @@ abstract class PageDelegate(protected val pageView: PageView) : var isTextSelected = false var selectedOnDown = false + var firstRelativePage = 0 var firstLineIndex: Int = 0 var firstCharIndex: Int = 0 @@ -286,23 +287,41 @@ abstract class PageDelegate(protected val pageView: PageView) : * 长按选择 */ override fun onLongPress(e: MotionEvent) { - curPage.selectText(e) { lineIndex, charIndex -> + curPage.selectText(e) { relativePage, lineIndex, charIndex -> isTextSelected = true + firstRelativePage = relativePage firstLineIndex = lineIndex firstCharIndex = charIndex } } protected fun selectText(event: MotionEvent) { - curPage.selectText(event) { lineIndex, charIndex -> - if (lineIndex > firstLineIndex - || (lineIndex == firstLineIndex && charIndex > firstCharIndex) - ) { - curPage.selectStartMoveIndex(firstLineIndex, firstCharIndex) - curPage.selectEndMoveIndex(lineIndex, charIndex) - } else { - curPage.selectEndMoveIndex(firstLineIndex, firstCharIndex) - curPage.selectStartMoveIndex(lineIndex, charIndex) + curPage.selectText(event) { relativePage, lineIndex, charIndex -> + when { + relativePage > firstRelativePage -> { + curPage.selectStartMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectEndMoveIndex(relativePage, lineIndex, charIndex) + } + relativePage < firstRelativePage -> { + curPage.selectEndMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectStartMoveIndex(relativePage, lineIndex, charIndex) + } + lineIndex > firstLineIndex -> { + curPage.selectStartMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectEndMoveIndex(relativePage, lineIndex, charIndex) + } + lineIndex < firstLineIndex -> { + curPage.selectEndMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectStartMoveIndex(relativePage, lineIndex, charIndex) + } + charIndex > firstCharIndex -> { + curPage.selectStartMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectEndMoveIndex(relativePage, lineIndex, charIndex) + } + else -> { + curPage.selectEndMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectStartMoveIndex(relativePage, lineIndex, charIndex) + } } } } From edb0335919553669330b182a103ebe1ab7864369 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 14:25:37 +0800 Subject: [PATCH 13/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 61 ++++++++++++------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index cc366e886..9c23ff89a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -278,7 +278,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectLineStart = lineIndex selectCharStart = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) - upSelectChars(textPage) + upSelectChars() } return } @@ -299,7 +299,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectLineStart = lineIndex selectCharStart = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) - upSelectChars(textPage) + upSelectChars() } return } @@ -318,7 +318,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectLineStart = lineIndex selectCharStart = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) - upSelectChars(textPage) + upSelectChars() } return } @@ -342,7 +342,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectLineEnd = lineIndex selectCharEnd = charIndex upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars(textPage) + upSelectChars() } return } @@ -362,7 +362,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectLineEnd = lineIndex selectCharEnd = charIndex upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars(textPage) + upSelectChars() } return } @@ -380,7 +380,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectLineEnd = lineIndex selectCharEnd = charIndex upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars(textPage) + upSelectChars() } return } @@ -390,6 +390,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + /** + * 选择开始文字 + */ fun selectStartMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { selectPageStart = relativePage selectLineStart = lineIndex @@ -397,9 +400,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at val textLine = relativePage(relativePage).textLines[lineIndex] val textChar = textLine.textChars[charIndex] upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(relativePage)) - upSelectChars(textPage) + upSelectChars() } + /** + * 选择结束文字 + */ fun selectEndMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { selectPageEnd = relativePage selectLineEnd = lineIndex @@ -407,22 +413,35 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at val textLine = relativePage(relativePage).textLines[lineIndex] val textChar = textLine.textChars[charIndex] upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(relativePage)) - upSelectChars(textPage) + upSelectChars() } - private fun upSelectChars(textPage: TextPage) { - for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - for ((charIndex, textChar) in textLine.textChars.withIndex()) { - textChar.selected = - if (lineIndex == selectLineStart && lineIndex == selectLineEnd) { - charIndex in selectCharStart..selectCharEnd - } else if (lineIndex == selectLineStart) { - charIndex >= selectCharStart - } else if (lineIndex == selectLineEnd) { - charIndex <= selectCharEnd - } else { - lineIndex in (selectLineStart + 1) until selectLineEnd - } + private fun upSelectChars() { + val last = if (ReadBookConfig.isScroll) 2 else 0 + for (relativePos in 0..last) { + for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + textChar.selected = + if (relativePos == selectPageStart + && relativePos == selectPageEnd + && lineIndex == selectLineStart + && lineIndex == selectLineEnd + ) { + charIndex in selectCharStart..selectCharEnd + } else if (relativePos == selectPageStart && lineIndex == selectLineStart) { + charIndex >= selectCharStart + } else if (relativePos == selectPageEnd && lineIndex == selectLineEnd) { + charIndex <= selectCharEnd + } else if (relativePos == selectPageStart && relativePos == selectPageEnd) { + lineIndex in (selectLineStart + 1) until selectLineEnd + } else if (relativePos == selectPageStart) { + lineIndex > selectLineStart + } else if (relativePos == selectPageEnd) { + lineIndex < selectLineEnd + } else { + relativePos in selectPageStart + 1 until selectPageEnd + } + } } } invalidate() From 4546a2ad97aa0c65faa5eddc17f8a2c8c1acd0bc Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 14:26:53 +0800 Subject: [PATCH 14/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/page/ContentTextView.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 9c23ff89a..6b4c329e1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -456,9 +456,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } fun cancelSelect() { - textPage.textLines.forEach { textLine -> - textLine.textChars.forEach { - it.selected = false + val last = if (ReadBookConfig.isScroll) 2 else 0 + for (relativePos in 0..last) { + relativePage(relativePos).textLines.forEach { textLine -> + textLine.textChars.forEach { + it.selected = false + } } } invalidate() From 1e8bdb489fe4dd11600595f081a0d72b3e16b441 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 15:01:09 +0800 Subject: [PATCH 15/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 71 +++++++++++++------ 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 6b4c329e1..282e5578b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -471,26 +471,57 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at val selectedText: String get() { val stringBuilder = StringBuilder() - for (lineIndex in selectLineStart..selectLineEnd) { - if (lineIndex == selectLineStart && lineIndex == selectLineEnd) { - stringBuilder.append( - textPage.textLines[lineIndex].text.substring( - selectCharStart, - selectCharEnd + 1 - ) - ) - } else if (lineIndex == selectLineStart) { - stringBuilder.append( - textPage.textLines[lineIndex].text.substring( - selectCharStart - ) - ) - } else if (lineIndex == selectLineEnd) { - stringBuilder.append( - textPage.textLines[lineIndex].text.substring(0, selectCharEnd + 1) - ) - } else { - stringBuilder.append(textPage.textLines[lineIndex].text) + for (relativePos in selectPageStart..selectPageEnd) { + val textPage = relativePage(relativePos) + if (relativePos == selectPageStart && relativePos == selectPageEnd) { + for (lineIndex in selectLineStart..selectLineEnd) { + if (lineIndex == selectLineStart && lineIndex == selectLineEnd) { + stringBuilder.append( + textPage.textLines[lineIndex].text.substring( + selectCharStart, + selectCharEnd + 1 + ) + ) + } else if (lineIndex == selectLineStart) { + stringBuilder.append( + textPage.textLines[lineIndex].text.substring( + selectCharStart + ) + ) + } else if (lineIndex == selectLineEnd) { + stringBuilder.append( + textPage.textLines[lineIndex].text.substring(0, selectCharEnd + 1) + ) + } else { + stringBuilder.append(textPage.textLines[lineIndex].text) + } + } + } else if (relativePos == selectPageStart) { + for (lineIndex in selectLineStart until relativePage(relativePos).textLines.size) { + if (lineIndex == selectLineStart) { + stringBuilder.append( + textPage.textLines[lineIndex].text.substring( + selectCharStart + ) + ) + } else { + stringBuilder.append(textPage.textLines[lineIndex].text) + } + } + } else if (relativePos == selectPageEnd) { + for (lineIndex in 0..selectLineEnd) { + if (lineIndex == selectLineEnd) { + stringBuilder.append( + textPage.textLines[lineIndex].text.substring(0, selectCharEnd + 1) + ) + } else { + stringBuilder.append(textPage.textLines[lineIndex].text) + } + } + } else if (relativePos in selectPageStart + 1 until selectPageEnd) { + for (lineIndex in selectLineStart..selectLineEnd) { + stringBuilder.append(textPage.textLines[lineIndex].text) + } } } return stringBuilder.toString() From 36178b6103e9c34fd02355054b81eb11051c48a2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 15:11:15 +0800 Subject: [PATCH 16/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 1cb677260..b9379ed02 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -2,6 +2,9 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/02/25** +* 优化文本选择和滚动,感觉很完美了 + **2020/02/24** * 滚动暂时可以滚了,先这样吧,头大 * 紧急修复朗读报错的bug From ac815fecf4589767a2e37e6cf97c84334e0869df Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 15:26:23 +0800 Subject: [PATCH 17/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/BookSourceDao.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 0981a94ea..fd5e2a6c9 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -14,10 +14,16 @@ interface BookSourceDao { @Query("select * from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey order by customOrder asc") fun liveDataSearch(searchKey: String = ""): LiveData> - @Query("select * from book_sources where enabled = 1 and enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' order by customOrder asc") + @Query("select * from book_sources where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' order by customOrder asc") fun liveExplore(): LiveData> - @Query("select * from book_sources where enabled = 1 and enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc") + @Query( + """ + select * from book_sources + where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and (bookSourceGroup like :key or bookSourceName like :key) + order by customOrder asc + """ + ) fun liveExplore(key: String): LiveData> @Query("select bookSourceGroup from book_sources where bookSourceGroup is not null and bookSourceGroup <> ''") @@ -26,7 +32,12 @@ interface BookSourceDao { @Query("select bookSourceGroup from book_sources where enabled = 1 and bookSourceGroup is not null and bookSourceGroup <> ''") fun liveGroupEnabled(): LiveData> - @Query("select bookSourceGroup from book_sources where enabled = 1 and enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and bookSourceGroup is not null and bookSourceGroup <> ''") + @Query( + """ + select bookSourceGroup from book_sources + where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and bookSourceGroup is not null and bookSourceGroup <> '' + """ + ) fun liveGroupExplore(): LiveData> @Query("select distinct enabled from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey") From 9dfe4870e7f500a060c9011607be8c8fa5c1ecf8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 15:38:09 +0800 Subject: [PATCH 18/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/dao/BookSourceDao.kt | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index fd5e2a6c9..e80f590f5 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -14,30 +14,25 @@ interface BookSourceDao { @Query("select * from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey order by customOrder asc") fun liveDataSearch(searchKey: String = ""): LiveData> - @Query("select * from book_sources where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' order by customOrder asc") + @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc") fun liveExplore(): LiveData> @Query( """ select * from book_sources - where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and (bookSourceGroup like :key or bookSourceName like :key) + where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc """ ) fun liveExplore(key: String): LiveData> - @Query("select bookSourceGroup from book_sources where bookSourceGroup is not null and bookSourceGroup <> ''") + @Query("select bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") fun liveGroup(): LiveData> - @Query("select bookSourceGroup from book_sources where enabled = 1 and bookSourceGroup is not null and bookSourceGroup <> ''") + @Query("select bookSourceGroup from book_sources where enabled = 1 and trim(bookSourceGroup) <> ''") fun liveGroupEnabled(): LiveData> - @Query( - """ - select bookSourceGroup from book_sources - where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and bookSourceGroup is not null and bookSourceGroup <> '' - """ - ) + @Query("select bookSourceGroup from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and trim(bookSourceGroup) <> ''") fun liveGroupExplore(): LiveData> @Query("select distinct enabled from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey") From 8132afde6c408b61a6e34271fc61e74e96e9fea7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 15:45:36 +0800 Subject: [PATCH 19/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/delegate/HorizontalPageDelegate.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index 263e2029d..586b3d88e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -22,7 +22,8 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie private fun onScroll(event: MotionEvent) { //判断是否移动了 if (!isMoved) { - isMoved = abs(startX - event.x) > slop || abs(startY - event.y) > slop + isMoved = abs(startX - event.x) > slop + || abs(startX - event.x) > abs(startY - event.y) if (isMoved) { if (event.x - startX > 0) { //如果上一页不存在 From 01f886b7d1f2cbe1ed9b46838bb03fddb18c8899 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 16:58:05 +0800 Subject: [PATCH 20/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 208 +++++++++--------- 1 file changed, 109 insertions(+), 99 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 282e5578b..29c2a3ddb 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -28,12 +28,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } private var callBack: CallBack private val visibleRect = RectF() - private var selectPageStart = 0 - private var selectLineStart = 0 - private var selectCharStart = 0 - private var selectPageEnd = 0 - private var selectLineEnd = 0 - private var selectCharEnd = 0 + private var selectStart = arrayOf(0, 0, 0) + private var selectEnd = arrayOf(0, 0, 0) private var textPage: TextPage = TextPage() //滚动参数 private val pageFactory: TextPageFactory get() = callBack.pageFactory @@ -197,12 +193,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (x > textChar.start && x < textChar.end) { textChar.selected = true invalidate() - selectPageStart = 0 - selectLineStart = lineIndex - selectCharStart = charIndex - selectPageEnd = 0 - selectLineEnd = lineIndex - selectCharEnd = charIndex + selectStart[0] = 0 + selectStart[1] = lineIndex + selectStart[2] = charIndex + selectEnd[0] = 0 + selectEnd[1] = lineIndex + selectEnd[2] = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) select(0, lineIndex, charIndex) @@ -223,12 +219,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (x > textChar.start && x < textChar.end) { textChar.selected = true invalidate() - selectPageStart = 1 - selectLineStart = lineIndex - selectCharStart = charIndex - selectPageEnd = 1 - selectLineEnd = lineIndex - selectCharEnd = charIndex + selectStart[0] = 1 + selectStart[1] = lineIndex + selectStart[2] = charIndex + selectEnd[0] = 1 + selectEnd[1] = lineIndex + selectEnd[2] = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) select(1, lineIndex, charIndex) @@ -246,12 +242,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (x > textChar.start && x < textChar.end) { textChar.selected = true invalidate() - selectPageStart = 2 - selectLineStart = lineIndex - selectCharStart = charIndex - selectPageEnd = 2 - selectLineEnd = lineIndex - selectCharEnd = charIndex + selectStart[0] = 2 + selectStart[1] = lineIndex + selectStart[2] = charIndex + selectEnd[0] = 2 + selectEnd[1] = lineIndex + selectEnd[2] = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) select(2, lineIndex, charIndex) @@ -273,12 +269,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectLineStart != lineIndex || selectCharStart != charIndex) { - selectPageStart = 0 - selectLineStart = lineIndex - selectCharStart = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) - upSelectChars() + if (selectStart[1] != lineIndex || selectStart[2] != charIndex) { + selectStart[0] = 0 + selectStart[1] = lineIndex + selectStart[2] = charIndex + upSelect() } return } @@ -294,12 +289,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectLineStart != lineIndex || selectCharStart != charIndex) { - selectPageStart = 1 - selectLineStart = lineIndex - selectCharStart = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) - upSelectChars() + if (selectStart[1] != lineIndex || selectStart[2] != charIndex) { + selectStart[0] = 1 + selectStart[1] = lineIndex + selectStart[2] = charIndex + upSelect() } return } @@ -313,12 +307,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectLineStart != lineIndex || selectCharStart != charIndex) { - selectPageStart = 1 - selectLineStart = lineIndex - selectCharStart = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) - upSelectChars() + if (selectStart[1] != lineIndex || selectStart[2] != charIndex) { + selectStart[0] = 2 + selectStart[1] = lineIndex + selectStart[2] = charIndex + upSelect() } return } @@ -338,11 +331,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { - selectLineEnd = lineIndex - selectCharEnd = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars() + if (selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + selectEnd[0] = 0 + selectEnd[1] = lineIndex + selectEnd[2] = charIndex + upSelect() } return } @@ -358,11 +351,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { - selectLineEnd = lineIndex - selectCharEnd = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars() + if (selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + selectEnd[0] = 1 + selectEnd[1] = lineIndex + selectEnd[2] = charIndex + upSelect() } return } @@ -376,11 +369,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { - selectLineEnd = lineIndex - selectCharEnd = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars() + if (selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + selectEnd[0] = 2 + selectEnd[1] = lineIndex + selectEnd[2] = charIndex + upSelect() } return } @@ -394,9 +387,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * 选择开始文字 */ fun selectStartMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { - selectPageStart = relativePage - selectLineStart = lineIndex - selectCharStart = charIndex + selectStart[0] = relativePage + selectStart[1] = lineIndex + selectStart[2] = charIndex val textLine = relativePage(relativePage).textLines[lineIndex] val textChar = textLine.textChars[charIndex] upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(relativePage)) @@ -407,39 +400,56 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * 选择结束文字 */ fun selectEndMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { - selectPageEnd = relativePage - selectLineEnd = lineIndex - selectCharEnd = charIndex + selectEnd[0] = relativePage + selectEnd[1] = lineIndex + selectEnd[2] = charIndex val textLine = relativePage(relativePage).textLines[lineIndex] val textChar = textLine.textChars[charIndex] upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(relativePage)) upSelectChars() } + private fun upSelect() { + val start = selectStart[0] * 1000000 + selectStart[1] * 100000 + selectStart[2] + val end = selectEnd[0] * 1000000 + selectEnd[1] * 100000 + selectEnd[2] + if (start > end) { + val value = selectStart + selectStart = selectEnd + selectEnd = value + } + var textLine = relativePage(selectStart[0]).textLines[selectStart[1]] + var textChar = textLine.textChars[selectStart[2]] + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(selectStart[0])) + textLine = relativePage(selectEnd[0]).textLines[selectEnd[0]] + textChar = textLine.textChars[selectEnd[2]] + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(selectEnd[0])) + upSelectChars() + } + private fun upSelectChars() { val last = if (ReadBookConfig.isScroll) 2 else 0 for (relativePos in 0..last) { for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { textChar.selected = - if (relativePos == selectPageStart - && relativePos == selectPageEnd - && lineIndex == selectLineStart - && lineIndex == selectLineEnd + if (relativePos == selectStart[0] + && relativePos == selectEnd[0] + && lineIndex == selectStart[1] + && lineIndex == selectEnd[1] ) { - charIndex in selectCharStart..selectCharEnd - } else if (relativePos == selectPageStart && lineIndex == selectLineStart) { - charIndex >= selectCharStart - } else if (relativePos == selectPageEnd && lineIndex == selectLineEnd) { - charIndex <= selectCharEnd - } else if (relativePos == selectPageStart && relativePos == selectPageEnd) { - lineIndex in (selectLineStart + 1) until selectLineEnd - } else if (relativePos == selectPageStart) { - lineIndex > selectLineStart - } else if (relativePos == selectPageEnd) { - lineIndex < selectLineEnd + charIndex in selectStart[2]..selectEnd[2] + } else if (relativePos == selectStart[0] && lineIndex == selectStart[1]) { + charIndex >= selectStart[2] + } else if (relativePos == selectEnd[0] && lineIndex == selectEnd[1]) { + charIndex <= selectEnd[2] + } else if (relativePos == selectStart[0] && relativePos == selectEnd[0]) { + lineIndex in (selectStart[1] + 1) until selectEnd[1] + } else if (relativePos == selectStart[0]) { + lineIndex > selectStart[1] + } else if (relativePos == selectEnd[0]) { + lineIndex < selectEnd[1] } else { - relativePos in selectPageStart + 1 until selectPageEnd + relativePos in selectStart[0] + 1 until selectEnd[0] } } } @@ -471,55 +481,55 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at val selectedText: String get() { val stringBuilder = StringBuilder() - for (relativePos in selectPageStart..selectPageEnd) { + for (relativePos in selectStart[0]..selectEnd[0]) { val textPage = relativePage(relativePos) - if (relativePos == selectPageStart && relativePos == selectPageEnd) { - for (lineIndex in selectLineStart..selectLineEnd) { - if (lineIndex == selectLineStart && lineIndex == selectLineEnd) { + if (relativePos == selectStart[0] && relativePos == selectEnd[0]) { + for (lineIndex in selectStart[1]..selectEnd[1]) { + if (lineIndex == selectStart[1] && lineIndex == selectEnd[1]) { stringBuilder.append( textPage.textLines[lineIndex].text.substring( - selectCharStart, - selectCharEnd + 1 + selectStart[2], + selectEnd[2] + 1 ) ) - } else if (lineIndex == selectLineStart) { + } else if (lineIndex == selectStart[1]) { stringBuilder.append( textPage.textLines[lineIndex].text.substring( - selectCharStart + selectStart[2] ) ) - } else if (lineIndex == selectLineEnd) { + } else if (lineIndex == selectEnd[1]) { stringBuilder.append( - textPage.textLines[lineIndex].text.substring(0, selectCharEnd + 1) + textPage.textLines[lineIndex].text.substring(0, selectEnd[2] + 1) ) } else { stringBuilder.append(textPage.textLines[lineIndex].text) } } - } else if (relativePos == selectPageStart) { - for (lineIndex in selectLineStart until relativePage(relativePos).textLines.size) { - if (lineIndex == selectLineStart) { + } else if (relativePos == selectStart[0]) { + for (lineIndex in selectStart[1] until relativePage(relativePos).textLines.size) { + if (lineIndex == selectStart[1]) { stringBuilder.append( textPage.textLines[lineIndex].text.substring( - selectCharStart + selectStart[2] ) ) } else { stringBuilder.append(textPage.textLines[lineIndex].text) } } - } else if (relativePos == selectPageEnd) { - for (lineIndex in 0..selectLineEnd) { - if (lineIndex == selectLineEnd) { + } else if (relativePos == selectEnd[0]) { + for (lineIndex in 0..selectEnd[1]) { + if (lineIndex == selectEnd[1]) { stringBuilder.append( - textPage.textLines[lineIndex].text.substring(0, selectCharEnd + 1) + textPage.textLines[lineIndex].text.substring(0, selectEnd[2] + 1) ) } else { stringBuilder.append(textPage.textLines[lineIndex].text) } } - } else if (relativePos in selectPageStart + 1 until selectPageEnd) { - for (lineIndex in selectLineStart..selectLineEnd) { + } else if (relativePos in selectStart[0] + 1 until selectEnd[0]) { + for (lineIndex in selectStart[1]..selectEnd[1]) { stringBuilder.append(textPage.textLines[lineIndex].text) } } From 1e533559fe84cfc818a8ebd82ca996d89836e649 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 17:00:28 +0800 Subject: [PATCH 21/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/page/ContentTextView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 29c2a3ddb..33dcb8a8d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -420,7 +420,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at var textLine = relativePage(selectStart[0]).textLines[selectStart[1]] var textChar = textLine.textChars[selectStart[2]] upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(selectStart[0])) - textLine = relativePage(selectEnd[0]).textLines[selectEnd[0]] + textLine = relativePage(selectEnd[0]).textLines[selectEnd[1]] textChar = textLine.textChars[selectEnd[2]] upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(selectEnd[0])) upSelectChars() From 70450a1fa7acb9dc5ac3bb771632173af5f60857 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 17:28:14 +0800 Subject: [PATCH 22/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 71 +++++++++++-------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 33dcb8a8d..270acbff3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -28,8 +28,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } private var callBack: CallBack private val visibleRect = RectF() - private var selectStart = arrayOf(0, 0, 0) - private var selectEnd = arrayOf(0, 0, 0) + private val selectStart = arrayOf(0, 0, 0) + private val selectEnd = arrayOf(0, 0, 0) private var textPage: TextPage = TextPage() //滚动参数 private val pageFactory: TextPageFactory get() = callBack.pageFactory @@ -269,11 +269,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectStart[0] != 0 || selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectToInt(0, lineIndex, charIndex) > selectToInt(selectEnd)) { + return + } selectStart[0] = 0 selectStart[1] = lineIndex selectStart[2] = charIndex - upSelect() + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) } return } @@ -289,11 +292,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectStart[0] != 1 || selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectToInt(1, lineIndex, charIndex) > selectToInt(selectEnd)) { + return + } selectStart[0] = 1 selectStart[1] = lineIndex selectStart[2] = charIndex - upSelect() + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) } return } @@ -307,11 +313,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectStart[0] != 2 || selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectToInt(2, lineIndex, charIndex) > selectToInt(selectEnd)) { + return + } selectStart[0] = 2 selectStart[1] = lineIndex selectStart[2] = charIndex - upSelect() + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) } return } @@ -331,11 +340,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectEnd[0] != 0 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectToInt(0, lineIndex, charIndex) < selectToInt(selectStart)) { + return + } selectEnd[0] = 0 selectEnd[1] = lineIndex selectEnd[2] = charIndex - upSelect() + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) } return } @@ -351,11 +363,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectEnd[0] != 1 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectToInt(1, lineIndex, charIndex) < selectToInt(selectStart)) { + return + } selectEnd[0] = 1 selectEnd[1] = lineIndex selectEnd[2] = charIndex - upSelect() + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) } return } @@ -369,11 +384,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectEnd[0] != 2 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectToInt(2, lineIndex, charIndex) < selectToInt(selectStart)) { + return + } selectEnd[0] = 2 selectEnd[1] = lineIndex selectEnd[2] = charIndex - upSelect() + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) } return } @@ -409,23 +427,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at upSelectChars() } - private fun upSelect() { - val start = selectStart[0] * 1000000 + selectStart[1] * 100000 + selectStart[2] - val end = selectEnd[0] * 1000000 + selectEnd[1] * 100000 + selectEnd[2] - if (start > end) { - val value = selectStart - selectStart = selectEnd - selectEnd = value - } - var textLine = relativePage(selectStart[0]).textLines[selectStart[1]] - var textChar = textLine.textChars[selectStart[2]] - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(selectStart[0])) - textLine = relativePage(selectEnd[0]).textLines[selectEnd[1]] - textChar = textLine.textChars[selectEnd[2]] - upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(selectEnd[0])) - upSelectChars() - } - private fun upSelectChars() { val last = if (ReadBookConfig.isScroll) 2 else 0 for (relativePos in 0..last) { @@ -537,6 +538,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at return stringBuilder.toString() } + private fun selectToInt(page: Int, line: Int, char: Int): Int { + return page * 1000000 + line * 100000 + char + } + + private fun selectToInt(select: Array): Int { + return select[0] * 1000000 + select[1] * 100000 + select[2] + } + private fun relativeOffset(relativePos: Int): Float { return when (relativePos) { 0 -> pageOffset From 187d904ac7ccbeb3334faea465b8456bbd3fef21 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 17:36:23 +0800 Subject: [PATCH 23/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/page/ContentTextView.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 270acbff3..c31fedde6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -277,6 +277,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectStart[1] = lineIndex selectStart[2] = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectChars() } return } @@ -300,6 +301,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectStart[1] = lineIndex selectStart[2] = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectChars() } return } @@ -321,6 +323,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectStart[1] = lineIndex selectStart[2] = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectChars() } return } @@ -348,6 +351,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectEnd[1] = lineIndex selectEnd[2] = charIndex upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + upSelectChars() } return } @@ -371,6 +375,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectEnd[1] = lineIndex selectEnd[2] = charIndex upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + upSelectChars() } return } @@ -392,6 +397,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectEnd[1] = lineIndex selectEnd[2] = charIndex upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + upSelectChars() } return } From 37b212dcb00b20a6cc1e0165ace6f393235b42e2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 19:15:52 +0800 Subject: [PATCH 24/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/config/PaddingConfigDialog.kt | 10 +++++++++- app/src/main/res/layout/dialog_read_padding.xml | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt index c72e1a417..1155e1d7d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt @@ -10,6 +10,7 @@ import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.help.ReadBookConfig import io.legado.app.ui.book.read.Help +import io.legado.app.utils.dp import io.legado.app.utils.postEvent import io.legado.app.utils.visible import kotlinx.android.synthetic.main.dialog_read_padding.* @@ -51,13 +52,20 @@ class PaddingConfigDialog : DialogFragment() { } private fun initData() = with(ReadBookConfig) { + if (hideStatusBar) { + tv_header_padding.visible() + dsb_header_padding_top.visible() + dsb_header_padding_bottom.visible() + dsb_header_padding_left.visible() + dsb_header_padding_right.visible() + tv_body_padding.setPadding(0, 10.dp, 0, 10.dp) + } //正文 dsb_padding_top.progress = paddingTop dsb_padding_bottom.progress = paddingBottom dsb_padding_left.progress = paddingLeft dsb_padding_right.progress = paddingRight //页眉 - tv_header_padding.visible(hideStatusBar) dsb_header_padding_top.progress = headerPaddingTop dsb_header_padding_bottom.progress = headerPaddingBottom dsb_header_padding_left.progress = headerPaddingLeft diff --git a/app/src/main/res/layout/dialog_read_padding.xml b/app/src/main/res/layout/dialog_read_padding.xml index 37e3b8cc4..1b600959e 100644 --- a/app/src/main/res/layout/dialog_read_padding.xml +++ b/app/src/main/res/layout/dialog_read_padding.xml @@ -13,12 +13,14 @@ android:layout_height="wrap_content" android:paddingBottom="10dp" android:textSize="18sp" + android:visibility="gone" android:text="@string/header" /> @@ -26,6 +28,7 @@ android:id="@+id/dsb_header_padding_bottom" android:layout_width="match_parent" android:layout_height="wrap_content" + android:visibility="gone" app:title="@string/padding_bottom" app:max="100" /> @@ -33,6 +36,7 @@ android:id="@+id/dsb_header_padding_left" android:layout_width="match_parent" android:layout_height="wrap_content" + android:visibility="gone" app:title="@string/padding_left" app:max="100" /> @@ -40,13 +44,14 @@ android:id="@+id/dsb_header_padding_right" android:layout_width="match_parent" android:layout_height="wrap_content" + android:visibility="gone" app:title="@string/padding_right" app:max="100" /> From 4055c5b5b51038f6690ef2584ad51e6c68e899c0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 19:27:23 +0800 Subject: [PATCH 25/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/data/dao/BookSourceDao.kt | 10 ++-------- .../main/java/io/legado/app/data/dao/RssSourceDao.kt | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index e80f590f5..94fe063f4 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -17,13 +17,7 @@ interface BookSourceDao { @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc") fun liveExplore(): LiveData> - @Query( - """ - select * from book_sources - where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) - order by customOrder asc - """ - ) + @Query(" select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc ") fun liveExplore(key: String): LiveData> @Query("select bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") @@ -47,7 +41,7 @@ interface BookSourceDao { @Query("select * from book_sources where enabled = 1 and bookSourceGroup like '%' || :group || '%'") fun getEnabledByGroup(group: String): List - @get:Query("select * from book_sources where bookUrlPattern is not null || bookUrlPattern <> ''") + @get:Query("select * from book_sources where trim(bookUrlPattern) <> ''") val hasBookUrlPattern: List @get:Query("select * from book_sources where bookSourceGroup is null or bookSourceGroup = ''") diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index c1c1e85d9..5436ee26c 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -28,7 +28,7 @@ interface RssSourceDao { @Query("SELECT * FROM rssSources where enabled = 1 order by customOrder") fun liveEnabled(): LiveData> - @Query("select sourceGroup from rssSources where sourceGroup is not null and sourceGroup <> ''") + @Query("select sourceGroup from rssSources where trim(sourceGroup) <> ''") fun liveGroup(): LiveData> @get:Query("select min(customOrder) from rssSources") From 438647f43e5652f8868df9125dcaff1682551ba1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 19:34:33 +0800 Subject: [PATCH 26/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 94fe063f4..9ce5c65be 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -17,7 +17,7 @@ interface BookSourceDao { @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc") fun liveExplore(): LiveData> - @Query(" select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc ") + @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc") fun liveExplore(key: String): LiveData> @Query("select bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") From ad6a56239e43fbf3361dadeb559bfe058f954b1f Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 20:13:27 +0800 Subject: [PATCH 27/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/delegate/PageDelegate.kt | 2 +- .../ui/book/read/page/delegate/SimulationPageDelegate.kt | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index e7b76fc6e..c710367c7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -136,7 +136,7 @@ abstract class PageDelegate(protected val pageView: PageView) : bitmap = null } - fun setViewSize(width: Int, height: Int) { + open fun setViewSize(width: Int, height: Int) { viewWidth = width viewHeight = height pageView.invalidate() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index 789fb61e1..cdffc0457 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -115,6 +115,11 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi mFrontShadowDrawableHBT.gradientType = GradientDrawable.LINEAR_GRADIENT } + override fun setViewSize(width: Int, height: Int) { + super.setViewSize(width, height) + mMaxLength = hypot(viewWidth.toDouble(), viewWidth.toDouble()).toFloat() + } + override fun setStartPoint(x: Float, y: Float, invalidate: Boolean) { super.setStartPoint(x, y, invalidate) calcCornerXY(x, y) @@ -171,7 +176,6 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi override fun onAnimStart() { var dx: Float val dy: Float - // dx 水平方向滑动的距离,负值会使滚动向左滚动 // dy 垂直方向滑动的距离,负值会使滚动向上滚动 if (isCancel) { dx = if (mCornerX > 0 && mDirection == Direction.NEXT) { From ce5cf8a3f251972928f60ba2407ea6bf9ca441b0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 20:25:10 +0800 Subject: [PATCH 28/28] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../read/page/delegate/SimulationPageDelegate.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index cdffc0457..ca4048c8d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -484,8 +484,10 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi private fun calcPoints() { mTouchX = touchX mTouchY = touchY + mMiddleX = (mTouchX + mCornerX) / 2 mMiddleY = (mTouchY + mCornerY) / 2 + mBezierControl1.x = mMiddleX - (mCornerY - mMiddleY) * (mCornerY - mMiddleY) / (mCornerX - mMiddleX) mBezierControl1.y = mCornerY.toFloat() @@ -496,6 +498,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi } else { mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / (mCornerY - mMiddleY) } + mBezierStart1.x = mBezierControl1.x - (mCornerX - mBezierControl1.x) / 2 mBezierStart1.y = mCornerY.toFloat() //固定左边上下两个点 @@ -504,24 +507,27 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi if (mBezierStart1.x < 0) mBezierStart1.x = viewWidth - mBezierStart1.x - val f1: Float = abs(mCornerX - mTouchX) - val f2: Float = viewWidth * f1 / mBezierStart1.x + val f1 = abs(mCornerX - mTouchX) + val f2 = viewWidth * f1 / mBezierStart1.x mTouchX = abs(mCornerX - f2) - val f3: Float = abs(mCornerX - mTouchX) * abs(mCornerY - mTouchY) / f1 + val f3 = abs(mCornerX - mTouchX) * abs(mCornerY - mTouchY) / f1 mTouchY = abs(mCornerY - f3) mMiddleX = (mTouchX + mCornerX) / 2 mMiddleY = (mTouchY + mCornerY) / 2 + mBezierControl1.x = mMiddleX - (mCornerY - mMiddleY) * (mCornerY - mMiddleY) / (mCornerX - mMiddleX) mBezierControl1.y = mCornerY.toFloat() + mBezierControl2.x = mCornerX.toFloat() mBezierControl2.y = if ((mCornerY - mMiddleY).toInt() == 0) { mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / 0.1f } else { mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / (mCornerY - mMiddleY) } - mBezierStart1.x = (mBezierControl1.x - (mCornerX - mBezierControl1.x) / 2) + + mBezierStart1.x = mBezierControl1.x - (mCornerX - mBezierControl1.x) / 2 } } mBezierStart2.x = mCornerX.toFloat()