...
This commit is contained in:
@@ -26,7 +26,7 @@ import java.io.Serializable
|
||||
* Created by Leonardo on 11/21/15.
|
||||
*/
|
||||
class AwesomeWebView {
|
||||
class Builder : Serializable {
|
||||
open class Builder : Serializable {
|
||||
@Transient
|
||||
val context: Context
|
||||
|
||||
@@ -1000,7 +1000,7 @@ class AwesomeWebView {
|
||||
show(url, null)
|
||||
}
|
||||
|
||||
fun show(url: String?, data: String?) {
|
||||
open fun show(url: String?, data: String?) {
|
||||
this.url = url
|
||||
this.data = data
|
||||
this.key = System.identityHashCode(this)
|
||||
|
||||
@@ -15,6 +15,7 @@ import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.Message
|
||||
import android.print.PDFPrint
|
||||
import android.provider.MediaStore
|
||||
@@ -93,7 +94,7 @@ import java.util.Date
|
||||
import kotlin.math.abs
|
||||
|
||||
|
||||
class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
|
||||
open class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
|
||||
Handler.Callback {
|
||||
protected var key: Int = 0
|
||||
|
||||
@@ -281,13 +282,18 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected var handler: Handler = Handler(this)
|
||||
protected val MSG_CLICK_ON_WEBVIEW: Int = 1
|
||||
protected val MSG_CLICK_ON_URL: Int = 2
|
||||
|
||||
@SuppressLint("ResourceType")
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
protected fun initializeOptions() {
|
||||
open protected fun initializeOptions() {
|
||||
val intent = intent ?: return
|
||||
|
||||
val builder = intent.getSerializableExtra("builder") as AwesomeWebView.Builder?
|
||||
@@ -538,6 +544,9 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
|
||||
extraHeaders = builder?.extraHeaders
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected fun bindViews() {
|
||||
binding.toolbarContent.close.setOnClickListener(this)
|
||||
binding.toolbarContent.back.setOnClickListener(this)
|
||||
@@ -545,6 +554,27 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
|
||||
binding.toolbarContent.more.setOnClickListener(this)
|
||||
webView = buildWebView()
|
||||
binding.webLayout.addView(webView)
|
||||
webView?.setOnScrollChangeListener { view, i, i2, i3, i4 ->
|
||||
// LogUtil.e("$view, $i, $i2, $i3, $i4")
|
||||
registCancelSearch()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val chechHandler = Handler(Looper.getMainLooper())
|
||||
|
||||
val cancelSearch = Runnable {
|
||||
finish()
|
||||
}
|
||||
|
||||
fun fast() {
|
||||
chechHandler.removeCallbacks(cancelSearch)
|
||||
chechHandler.postDelayed(cancelSearch, 6000L)
|
||||
}
|
||||
|
||||
fun registCancelSearch() {
|
||||
chechHandler.removeCallbacks(cancelSearch)
|
||||
chechHandler.postDelayed(cancelSearch, 60000L)
|
||||
}
|
||||
|
||||
protected fun layoutViews() {
|
||||
@@ -1284,6 +1314,7 @@ LogUtil.e("url!!.toUri(). >> ${url!!.toUri().authority}")
|
||||
webView!!.loadUrl(url!!, extraHeaders!!)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected val maxWidth: Int
|
||||
@@ -1432,7 +1463,6 @@ LogUtil.e("onBackPressed ${webChromeClient} && ${binding.menus.menuLayout.visibi
|
||||
snackbarView.setBackgroundColor(toolbarColor)
|
||||
if (snackbarView is ViewGroup) updateChildTextView(snackbarView)
|
||||
snackbar.show()
|
||||
|
||||
hideMenu()
|
||||
} else if (viewId == R.id.menuOpenWith) {
|
||||
val browserIntent = Intent(
|
||||
@@ -1441,8 +1471,8 @@ LogUtil.e("onBackPressed ${webChromeClient} && ${binding.menus.menuLayout.visibi
|
||||
)
|
||||
)
|
||||
startActivity(browserIntent)
|
||||
|
||||
hideMenu()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1809,8 +1839,8 @@ LogUtil.e("onBackPressed ${webChromeClient} && ${binding.menus.menuLayout.visibi
|
||||
view: WebView,
|
||||
request: WebResourceRequest
|
||||
): WebResourceResponse? {
|
||||
LogUtil.e("shouldInterceptRequest request >>> ${request.url.toString()}")
|
||||
if (request.url.toString().contains("gif")) {
|
||||
// LogUtil.e("shouldInterceptRequest request >>> ${request.url.toString()}")
|
||||
if (request.url.toString().contains("gif") && request.url.toString().contains("sogirl")) {
|
||||
return WebResourceResponse(
|
||||
"text/plain", "utf-8",
|
||||
ByteArrayInputStream("".toByteArray())
|
||||
@@ -1863,12 +1893,13 @@ LogUtil.e("onBackPressed ${webChromeClient} && ${binding.menus.menuLayout.visibi
|
||||
webView!!.loadUrl(injectJavaScript!!)
|
||||
}
|
||||
}
|
||||
registCancelSearch()
|
||||
}
|
||||
|
||||
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
|
||||
handler.sendEmptyMessage(MSG_CLICK_ON_URL)
|
||||
LogUtil.e("host >>> ${host} , url >>> ${url}")
|
||||
// if (host?.length ?: 0 > 2 && url.contains(host!!)) {
|
||||
// LogUtil.e("host >>> ${host} , url >>> ${url}")
|
||||
if (url.contains("coupang") == false && url.contains("aliex") == false) {
|
||||
if (url.endsWith(".mp4")) {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.setDataAndType(Uri.parse(url), "video/*")
|
||||
@@ -1919,9 +1950,9 @@ LogUtil.e("onBackPressed ${webChromeClient} && ${binding.menus.menuLayout.visibi
|
||||
return super.shouldOverrideUrlLoading(view, url)
|
||||
}
|
||||
}
|
||||
// } else {
|
||||
// return true
|
||||
// }
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLoadResource(view: WebView, url: String) {
|
||||
|
||||
Reference in New Issue
Block a user