Commit faa5eb46 authored by wanglei's avatar wanglei

...

parent 66eaf512
......@@ -435,8 +435,7 @@ class WebBrowserActivity : BaseActivity<ActivityWebBrowserBinding>() {
fragmentList.add(myFragment)
currentFragment = myFragment
currentFragment?.onPageFinished = { uriString ->
binding.editWeb.setText(currentFragment?.bookmarkBean?.name ?: "")
// uriString?.let { binding.editWeb.setText(it) }
binding.editWeb.text = currentFragment?.bookmarkBean?.name ?: ""
checkLeftRight()
}
}
......
......@@ -24,6 +24,7 @@ import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import com.applovin.sdk.AppLovinSdkUtils.runOnUiThread
import com.base.browserwhite.MyApplication
import com.base.browserwhite.ads.AdmobMaxHelper
import com.base.browserwhite.ads.AdmobMaxHelper.lastShowInter
......@@ -116,7 +117,23 @@ class WebViewFragment() : BaseFragment<FragmentWebViewBinding>() {
binding.flDownload.setOnClickListener {
callDownloadDialog()
}
binding.webView.setFindListener { activeMatchOrdinal, numberOfMatches, isDoneCounting ->
LogEx.logDebug(
TAG,
"activeMatchOrdinal=$activeMatchOrdinal numberOfMatches=$numberOfMatches isDoneCounting=$isDoneCounting"
)
if (numberOfMatches > 0) {
if (isDoneCounting) {
binding.webView.loadUrl("javascript:window.android.onSearchResult(document.body.innerText);")
}
} else {
if (activity is WebBrowserActivity) {
(activity as WebBrowserActivity?)?.setSearchNum(0, 0)
}
searchResult.clear()
searchPosition = 0
}
}
}
private fun callDownloadDialog() {
......@@ -183,19 +200,7 @@ class WebViewFragment() : BaseFragment<FragmentWebViewBinding>() {
}
requireContext().saveDownloadRecordFile(downloadList)
}
binding.webView.setFindListener { activeMatchOrdinal, numberOfMatches, isDoneCounting ->
if (numberOfMatches > 0) {
if (isDoneCounting) {
binding.webView.loadUrl("javascript:window.android.onSearchResult(document.body.innerText);")
}
} else {
if (activity is WebBrowserActivity) {
(activity as WebBrowserActivity)?.setSearchNum(0, 0)
}
searchResult.clear()
searchPosition = 0
}
}
}
private var keyword = ""
......@@ -243,6 +248,7 @@ class WebViewFragment() : BaseFragment<FragmentWebViewBinding>() {
@JavascriptInterface
fun onSearchResult(text: String?) {
LogEx.logDebug(TAG, "onSearchResult")
text?.let {
val filteredText = Html.fromHtml(it).toString()
val pattern = Pattern.compile(keyword, Pattern.CASE_INSENSITIVE)
......@@ -253,10 +259,12 @@ class WebViewFragment() : BaseFragment<FragmentWebViewBinding>() {
searchResult.add(start)
}
if (activity is WebBrowserActivity) {
(activity as WebBrowserActivity)?.setSearchNum(
searchPosition + 1,
searchResult.size
)
runOnUiThread {
(activity as WebBrowserActivity?)?.setSearchNum(
searchPosition + 1, searchResult.size
)
}
}
highlightSearchResult()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment