Browse Source

Feature: highlight search result

cooperku_kdanmobile 5 years ago
parent
commit
4f7596ce35

+ 1 - 1
reader/src/main/java/com/kdanmobile/reader/ReaderViewModel.kt

@@ -453,7 +453,7 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
             return kmpdfDocumentController?.cleanPreviousSearchResults(keyword) ?: false
             return kmpdfDocumentController?.cleanPreviousSearchResults(keyword) ?: false
         }
         }
 
 
-        override fun cleanPreviousSearchResults(page: Int, keyword: String, rectArray: Array<RectF>): Boolean {
+        override fun setSearchResult(page: Int, keyword: String, rectArray: Array<RectF>): Boolean {
             return kmpdfDocumentController?.setSearchResult(keyword, page, rectArray) ?: false
             return kmpdfDocumentController?.setSearchResult(keyword, page, rectArray) ?: false
         }
         }
 
 

+ 1 - 1
reader/src/main/java/com/kdanmobile/reader/screen/handler/SearchHandler.kt

@@ -8,7 +8,7 @@ interface SearchHandler {
 
 
     fun cleanPreviousSearchResults(keyword: String): Boolean
     fun cleanPreviousSearchResults(keyword: String): Boolean
 
 
-    fun cleanPreviousSearchResults(page: Int, keyword: String, rectArray: Array<RectF>): Boolean
+    fun setSearchResult(page: Int, keyword: String, rectArray: Array<RectF>): Boolean
 
 
     fun stopSearchKeyWord(): Boolean
     fun stopSearchKeyWord(): Boolean
 }
 }

+ 7 - 7
reader/src/main/java/com/kdanmobile/reader/screen/model/SearchResultInfo.kt

@@ -3,7 +3,7 @@ package com.kdanmobile.reader.screen.model
 import android.graphics.RectF
 import android.graphics.RectF
 import com.kdanmobile.kmpdfkit.pdfcommon.TextWord
 import com.kdanmobile.kmpdfkit.pdfcommon.TextWord
 
 
-class SearchResultInfo(var page: Int, var search: String, var rf: RectF, lines: Array<TextWord>) {
+class SearchResultInfo(var page: Int, var keyword: String, var rect: RectF, lines: Array<TextWord>) {
     var result: String = ""
     var result: String = ""
 
 
     init {
     init {
@@ -13,17 +13,17 @@ class SearchResultInfo(var page: Int, var search: String, var rf: RectF, lines:
 
 
         val sb = StringBuilder()
         val sb = StringBuilder()
         var src = result.toLowerCase()
         var src = result.toLowerCase()
-        val seh = search.toLowerCase()
-        var index = src.indexOf(seh)
+        val key = keyword.toLowerCase()
+        var index = src.indexOf(key)
         while (index >= 0) {
         while (index >= 0) {
             sb.append(src.subSequence(0, index))
             sb.append(src.subSequence(0, index))
             sb.append("<font color=\"#ff0000\">")
             sb.append("<font color=\"#ff0000\">")
             result = result.substring(index)
             result = result.substring(index)
-            sb.append(result.substring(0, search.length))
+            sb.append(result.substring(0, keyword.length))
             sb.append("</font>")
             sb.append("</font>")
-            result = result.substring(search.length)
-            src = src.substring(index + search.length)
-            index = src.indexOf(seh)
+            result = result.substring(keyword.length)
+            src = src.substring(index + keyword.length)
+            index = src.indexOf(key)
         }
         }
 
 
         sb.append(result)
         sb.append(result)

+ 0 - 17
reader/src/main/java/com/kdanmobile/reader/screen/model/SearchTaskResult.kt

@@ -1,17 +0,0 @@
-package com.kdanmobile.reader.screen.model
-
-import android.graphics.RectF
-
-class SearchTaskResult(val txt: String, val pageNumber: Int, val searchBoxes: Array<RectF>) {
-    companion object {
-        private var singleton: SearchTaskResult? = null
-
-        fun get(): SearchTaskResult? {
-            return singleton
-        }
-
-        fun set(result: SearchTaskResult) {
-            singleton = result
-        }
-    }
-}

+ 1 - 2
reader/src/main/java/com/kdanmobile/reader/screen/view/SearchView.kt

@@ -18,7 +18,6 @@ import com.kdanmobile.reader.screen.adapter.SearchAdapter
 import com.kdanmobile.reader.screen.model.SearchResultInfo
 import com.kdanmobile.reader.screen.model.SearchResultInfo
 import com.kdanmobile.reader.screen.handler.PdfInfoHandler
 import com.kdanmobile.reader.screen.handler.PdfInfoHandler
 import com.kdanmobile.reader.screen.handler.SearchHandler
 import com.kdanmobile.reader.screen.handler.SearchHandler
-import com.kdanmobile.reader.screen.model.SearchTaskResult
 import com.kdanmobile.reader.screen.model.SimpleTextWatcher
 import com.kdanmobile.reader.screen.model.SimpleTextWatcher
 import com.kdanmobile.reader.utils.DensityUtil
 import com.kdanmobile.reader.utils.DensityUtil
 import io.reactivex.Completable
 import io.reactivex.Completable
@@ -105,7 +104,7 @@ class SearchView: RelativeLayout, View.OnClickListener {
                         30 -> {
                         30 -> {
                             val position = msg.arg1
                             val position = msg.arg1
                             val info = view.list[position]
                             val info = view.list[position]
-                            SearchTaskResult.set(SearchTaskResult(info.search, info.page, arrayOf(info.rf)))
+                            view.searchHandler?.setSearchResult(info.page, info.keyword, arrayOf(info.rect))
                             view.pdfInfoHandler?.setCurrentPage(view.list[position].page)
                             view.pdfInfoHandler?.setCurrentPage(view.list[position].page)
                         }
                         }
                     }
                     }