pull/393/head
Jason Yao 4 years ago
parent 8c377c2ba5
commit 65b7bb3d41
  1. 11
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 12
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt

@ -339,11 +339,9 @@ object ReadBook {
index = content.indexOf(query, index + 1);
count += 1
}
Log.d("h11128", "new index $index")
val contentPosition = index
var pageIndex = 0
var length = pages[pageIndex].text.length
Log.d("h11128", "page size ${pages.size}")
while (length < contentPosition){
pageIndex += 1
if (pageIndex >pages.size){
@ -351,16 +349,12 @@ object ReadBook {
break
}
length += pages[pageIndex].text.length
Log.d("h11128", "to next page , add length change to $length")
}
Log.d("h11128", "at pageindex $pageIndex")
// calculate search result's lineIndex
val currentPage = pages[pageIndex]
var lineIndex = 0
length = length - currentPage.text.length + currentPage.textLines[lineIndex].text.length
Log.d("h11128", "currentLine ${currentPage.textLines[lineIndex].text}")
while (length < contentPosition){
lineIndex += 1
if (lineIndex >currentPage.textLines.size){
@ -368,15 +362,11 @@ object ReadBook {
break
}
length += currentPage.textLines[lineIndex].text.length
Log.d("h11128", "currentLine ${currentPage.textLines[lineIndex].text}")
}
// charIndex
Log.d("h11128", "currentLine ${currentPage.textLines[lineIndex].text}")
Log.d("h11128", "currentLength $length")
val currentLine = currentPage.textLines[lineIndex]
length -= currentLine.text.length
Log.d("h11128", "currentLength $length")
val charIndex = contentPosition - length
var addLine = 0
var charIndex2 = 0
@ -390,7 +380,6 @@ object ReadBook {
addLine = -1
charIndex2 = charIndex + query.length - currentLine.text.length - 1
}
Log.d("h11128", "charIndex2 $charIndex $addLine $charIndex2")
return arrayOf(pageIndex, lineIndex, charIndex, addLine, charIndex2)
}

@ -781,29 +781,18 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
val indexWithinChapter = data.getIntExtra("indexWithinChapter", 0)
val query = data.getStringExtra("query")
viewModel.openChapter(index)
// block until load correct chapter and pages
var pages = ReadBook.curTextChapter?.pages
while (ReadBook.durChapterIndex != index || pages == null ){
delay(100L)
pages = ReadBook.curTextChapter?.pages
}
Log.d("h11128", "Current chapter pages ${pages.size}")
val positions = ReadBook.searchResultPositions(pages, indexWithinChapter, query!!)
Log.d("h11128", positions[0].toString())
Log.d("h11128", positions[1].toString())
Log.d("h11128", positions[2].toString())
Log.d("h11128", positions[3].toString())
while (ReadBook.durPageIndex != positions[0]){
delay(100L)
ReadBook.skipToPage(positions[0])
}
withContext(Main){
Log.d("h11128", "currentpage ${ReadBook.durPageIndex}")
Log.d("h11128", "currentpage ${page_view.pageFactory.currentPage.index}")
Log.d("h11128", "${positions[0]} ${positions[1]} ${positions[2]}")
page_view.curPage.selectStartMoveIndex(0, positions[1], positions[2])
delay(20L)
when (positions[3]){
@ -814,7 +803,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
}
page_view.isTextSelected = true
delay(100L)
Log.d("h11128", "asdasd $selectedText")
}
}
}

Loading…
Cancel
Save