|  |  |  | @ -12,7 +12,9 @@ import io.legado.app.constant.PreferKey | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.help.ReadBookConfig | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.lib.theme.accentColor | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.service.help.ReadBook | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.ui.book.read.page.entities.* | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.ui.book.read.page.entities.TextChar | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.ui.book.read.page.entities.TextLine | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.ui.book.read.page.entities.TextPage | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.ui.book.read.page.provider.ChapterProvider | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.ui.book.read.page.provider.ImageProvider | 
			
		
	
		
			
				
					|  |  |  |  | import io.legado.app.ui.book.read.page.provider.TextPageFactory | 
			
		
	
	
		
			
				
					|  |  |  | @ -39,7 +41,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
			
				
					|  |  |  |  |     private val visibleRect = RectF() | 
			
		
	
		
			
				
					|  |  |  |  |     private val selectStart = arrayOf(0, 0, 0) | 
			
		
	
		
			
				
					|  |  |  |  |     private val selectEnd = arrayOf(0, 0, 0) | 
			
		
	
		
			
				
					|  |  |  |  |     private var textChapter: TextChapter? = null | 
			
		
	
		
			
				
					|  |  |  |  |     var textPage: TextPage = TextPage() | 
			
		
	
		
			
				
					|  |  |  |  |         private set | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -51,9 +52,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
			
				
					|  |  |  |  |         callBack = activity as CallBack | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     fun setContent(pageData: PageData) { | 
			
		
	
		
			
				
					|  |  |  |  |         this.textChapter = pageData.textChapter | 
			
		
	
		
			
				
					|  |  |  |  |         this.textPage = pageData.textPage | 
			
		
	
		
			
				
					|  |  |  |  |     fun setContent(textPage: TextPage) { | 
			
		
	
		
			
				
					|  |  |  |  |         this.textPage = textPage | 
			
		
	
		
			
				
					|  |  |  |  |         invalidate() | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -140,9 +140,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
			
				
					|  |  |  |  |         isReadAloud: Boolean, | 
			
		
	
		
			
				
					|  |  |  |  |     ) { | 
			
		
	
		
			
				
					|  |  |  |  |         val textPaint = if (isTitle) { | 
			
		
	
		
			
				
					|  |  |  |  |             textChapter?.titlePaint ?: ChapterProvider.titlePaint | 
			
		
	
		
			
				
					|  |  |  |  |             ChapterProvider.titlePaint | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |             textChapter?.contentPaint ?: ChapterProvider.contentPaint | 
			
		
	
		
			
				
					|  |  |  |  |             ChapterProvider.contentPaint | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         textPaint.color = | 
			
		
	
		
			
				
					|  |  |  |  |             if (isReadAloud) context.accentColor else ReadBookConfig.textColor | 
			
		
	
	
		
			
				
					|  |  |  | @ -190,14 +190,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
			
				
					|  |  |  |  |             pageOffset = min(0, offset) | 
			
		
	
		
			
				
					|  |  |  |  |         } else if (pageOffset > 0) { | 
			
		
	
		
			
				
					|  |  |  |  |             pageFactory.moveToPrev(false) | 
			
		
	
		
			
				
					|  |  |  |  |             textPage = pageFactory.curData.textPage | 
			
		
	
		
			
				
					|  |  |  |  |             textPage = pageFactory.curPage | 
			
		
	
		
			
				
					|  |  |  |  |             pageOffset -= textPage.height.toInt() | 
			
		
	
		
			
				
					|  |  |  |  |             upView?.invoke(textPage) | 
			
		
	
		
			
				
					|  |  |  |  |             contentDescription = textPage.text | 
			
		
	
		
			
				
					|  |  |  |  |         } else if (pageOffset < -textPage.height) { | 
			
		
	
		
			
				
					|  |  |  |  |             pageOffset += textPage.height.toInt() | 
			
		
	
		
			
				
					|  |  |  |  |             pageFactory.moveToNext(false) | 
			
		
	
		
			
				
					|  |  |  |  |             textPage = pageFactory.curData.textPage | 
			
		
	
		
			
				
					|  |  |  |  |             textPage = pageFactory.curPage | 
			
		
	
		
			
				
					|  |  |  |  |             upView?.invoke(textPage) | 
			
		
	
		
			
				
					|  |  |  |  |             contentDescription = textPage.text | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
	
		
			
				
					|  |  |  | @ -308,15 +308,19 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             Log.e("y", "$y") | 
			
		
	
		
			
				
					|  |  |  |  |             for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { | 
			
		
	
		
			
				
					|  |  |  |  |                 if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { | 
			
		
	
		
			
				
					|  |  |  |  |                 if (y > textLine.lineTop + relativeOffset | 
			
		
	
		
			
				
					|  |  |  |  |                     && y < textLine.lineBottom + relativeOffset | 
			
		
	
		
			
				
					|  |  |  |  |                 ) { | 
			
		
	
		
			
				
					|  |  |  |  |                     Log.e("line", "$relativePos  $lineIndex") | 
			
		
	
		
			
				
					|  |  |  |  |                     for ((charIndex, textChar) in textLine.textChars.withIndex()) { | 
			
		
	
		
			
				
					|  |  |  |  |                         if (x > textChar.start && x < textChar.end) { | 
			
		
	
		
			
				
					|  |  |  |  |                             Log.e("char", "$relativePos  $lineIndex $charIndex") | 
			
		
	
		
			
				
					|  |  |  |  |                             if (selectEnd[0] != relativePos || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { | 
			
		
	
		
			
				
					|  |  |  |  |                                 if (selectToInt(relativePos, lineIndex, charIndex) < selectToInt( | 
			
		
	
		
			
				
					|  |  |  |  |                                         selectStart | 
			
		
	
		
			
				
					|  |  |  |  |                                     ) | 
			
		
	
		
			
				
					|  |  |  |  |                             if (selectEnd[0] != relativePos | 
			
		
	
		
			
				
					|  |  |  |  |                                 || selectEnd[1] != lineIndex | 
			
		
	
		
			
				
					|  |  |  |  |                                 || selectEnd[2] != charIndex | 
			
		
	
		
			
				
					|  |  |  |  |                             ) { | 
			
		
	
		
			
				
					|  |  |  |  |                                 if (selectToInt(relativePos, lineIndex, charIndex) | 
			
		
	
		
			
				
					|  |  |  |  |                                     < selectToInt(selectStart) | 
			
		
	
		
			
				
					|  |  |  |  |                                 ) { | 
			
		
	
		
			
				
					|  |  |  |  |                                     return | 
			
		
	
		
			
				
					|  |  |  |  |                                 } | 
			
		
	
	
		
			
				
					|  |  |  | @ -476,6 +480,17 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
			
				
					|  |  |  |  |             return stringBuilder.toString() | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     val selectStartPos: Int | 
			
		
	
		
			
				
					|  |  |  |  |         get() { | 
			
		
	
		
			
				
					|  |  |  |  |             for (i in 0 until selectStart[0]) { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             return 0 | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private fun selectToInt(page: Int, line: Int, char: Int): Int { | 
			
		
	
		
			
				
					|  |  |  |  |         return page * 10000000 + line * 100000 + char | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
	
		
			
				
					|  |  |  | @ -488,15 +503,15 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at | 
			
		
	
		
			
				
					|  |  |  |  |         return when (relativePos) { | 
			
		
	
		
			
				
					|  |  |  |  |             0 -> pageOffset.toFloat() | 
			
		
	
		
			
				
					|  |  |  |  |             1 -> pageOffset + textPage.height | 
			
		
	
		
			
				
					|  |  |  |  |             else -> pageOffset + textPage.height + pageFactory.nextData.textPage.height | 
			
		
	
		
			
				
					|  |  |  |  |             else -> pageOffset + textPage.height + pageFactory.nextPage.height | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private fun relativePage(relativePos: Int): TextPage { | 
			
		
	
		
			
				
					|  |  |  |  |         return when (relativePos) { | 
			
		
	
		
			
				
					|  |  |  |  |             0 -> textPage | 
			
		
	
		
			
				
					|  |  |  |  |             1 -> pageFactory.nextData.textPage | 
			
		
	
		
			
				
					|  |  |  |  |             else -> pageFactory.nextPlusData.textPage | 
			
		
	
		
			
				
					|  |  |  |  |             1 -> pageFactory.nextPage | 
			
		
	
		
			
				
					|  |  |  |  |             else -> pageFactory.nextPlusPage | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | 
 |