|
|
|
@@ -63,6 +63,8 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|
|
|
|
import androidx.core.content.ContextCompat
|
|
|
|
|
import androidx.core.content.FileProvider
|
|
|
|
|
import androidx.core.net.toUri
|
|
|
|
|
import com.bumptech.glide.Glide
|
|
|
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
|
import kr.lunaticbum.awesomewebview.databinding.AwesomeWebViewBinding
|
|
|
|
|
import kr.lunaticbum.awesomewebview.enums.Position
|
|
|
|
@@ -86,11 +88,14 @@ import kr.lunaticbum.utils.service.ClipboardManagerUtil
|
|
|
|
|
import kr.lunaticbum.utils.ui.DisplayUtil
|
|
|
|
|
import kr.lunaticbum.utils.ui.ViewUtil
|
|
|
|
|
import java.io.ByteArrayInputStream
|
|
|
|
|
import java.io.ByteArrayOutputStream
|
|
|
|
|
import java.io.File
|
|
|
|
|
import java.io.IOException
|
|
|
|
|
import java.io.InputStream
|
|
|
|
|
import java.net.URL
|
|
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
|
import java.util.Date
|
|
|
|
|
import java.util.Locale
|
|
|
|
|
import kotlin.math.abs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -564,7 +569,11 @@ open class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
|
|
|
|
|
val chechHandler = Handler(Looper.getMainLooper())
|
|
|
|
|
|
|
|
|
|
val cancelSearch = Runnable {
|
|
|
|
|
finish()
|
|
|
|
|
if(!hasYoutubePlayer) {
|
|
|
|
|
finish()
|
|
|
|
|
} else {
|
|
|
|
|
registCancelSearch()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun fast() {
|
|
|
|
@@ -1305,9 +1314,6 @@ open class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
|
|
|
|
|
if (data != null) {
|
|
|
|
|
webView!!.loadData(data!!, mimeType, encoding)
|
|
|
|
|
} else if (url != null) {
|
|
|
|
|
// host = url!!.toUri().host?.replace("www.","")?.replace("m.","")
|
|
|
|
|
LogUtil.e("url!!.toUri(). >> ${url!!.toUri().authority}")
|
|
|
|
|
LogUtil.e("url!!.toUri(). >> ${url!!.toUri().encodedFragment}")
|
|
|
|
|
if (extraHeaders == null) {
|
|
|
|
|
webView!!.loadUrl(url!!)
|
|
|
|
|
} else {
|
|
|
|
@@ -1390,8 +1396,9 @@ LogUtil.e("url!!.toUri(). >> ${url!!.toUri().authority}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("MissingSuperCall")
|
|
|
|
|
override fun onBackPressed() {
|
|
|
|
|
LogUtil.e("onBackPressed ${webChromeClient} && ${binding.menus.menuLayout.visibility}")
|
|
|
|
|
LogUtil.e("onBackPressed ${webChromeClient} && ${binding.menus.menuLayout.visibility}")
|
|
|
|
|
if (webChromeClient is MyWebChromeClient && (webChromeClient as MyWebChromeClient).onBackPressed()) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@@ -1833,27 +1840,75 @@ LogUtil.e("onBackPressed ${webChromeClient} && ${binding.menus.menuLayout.visibi
|
|
|
|
|
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
|
|
|
|
|
return File.createTempFile(new_name, if (isVideo) ".mp4" else ".jpg", sd_directory)
|
|
|
|
|
}
|
|
|
|
|
var hasYoutubePlayer = false
|
|
|
|
|
open fun webviewOnPageFinished(){}
|
|
|
|
|
inner class MyWebViewClient : WebViewClient() {
|
|
|
|
|
override fun shouldInterceptRequest(
|
|
|
|
|
view: WebView,
|
|
|
|
|
request: WebResourceRequest
|
|
|
|
|
): WebResourceResponse? {
|
|
|
|
|
// LogUtil.e("shouldInterceptRequest request >>> ${request.url.toString()}")
|
|
|
|
|
if (request.url.toString().contains("gif") && request.url.toString().contains("sogirl")) {
|
|
|
|
|
var skipResource =
|
|
|
|
|
(host != null) && ((request.url?.host?.contains(host!!) ?: true) == false)
|
|
|
|
|
if (skipResource && request.url.toString().contains("gif")) {
|
|
|
|
|
LogUtil.e("shouldInterceptRequest request block gif resource >>> ${request.url.toString()}")
|
|
|
|
|
return WebResourceResponse(
|
|
|
|
|
"text/plain", "utf-8",
|
|
|
|
|
ByteArrayInputStream("".toByteArray())
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
return super.shouldInterceptRequest(view, request)
|
|
|
|
|
val url = request.url.toString()
|
|
|
|
|
if(!hasYoutubePlayer) {
|
|
|
|
|
hasYoutubePlayer = url.toLowerCase(Locale.ROOT)
|
|
|
|
|
.contains("https://www.youtube.com/s/player".toLowerCase(Locale.ROOT))
|
|
|
|
|
}
|
|
|
|
|
if (url.toLowerCase(Locale.ROOT)
|
|
|
|
|
.contains("ads".toLowerCase(Locale.ROOT))) {
|
|
|
|
|
LogUtil.e("shouldInterceptRequest request url contains ads >>> ${request.url.toString()}")
|
|
|
|
|
}
|
|
|
|
|
var adblockKeyWords = arrayOf("adcr.naver.com","daumcdn.net/biz/ui/ad/adcm","imgad","ad.daum.net","cr.adsappier.com","ar-adview","adtrafficquality","criteo","adlib.nhnace.com","google.com/ads","googleads.","/pagead","/adpost/","ads/search")
|
|
|
|
|
val adblock = adblockKeyWords.filter { url.toLowerCase(Locale.ROOT).contains(it.toLowerCase(Locale.ROOT)) }.size > 0
|
|
|
|
|
return if(adblock) {
|
|
|
|
|
try {
|
|
|
|
|
LogUtil.e("shouldInterceptRequest request block adblockKeyWords resource >>> ${request.url.toString()}")
|
|
|
|
|
WebResourceResponse("text/plain", "utf-8", ByteArrayInputStream("".toByteArray()))
|
|
|
|
|
} catch (e : Exception) {
|
|
|
|
|
super.shouldInterceptRequest(view, url)
|
|
|
|
|
}
|
|
|
|
|
}else if(url.toLowerCase(Locale.ROOT).contains(".jpg") || url.toLowerCase(Locale.ROOT).contains(".jpeg")){
|
|
|
|
|
try {
|
|
|
|
|
val bitmap = Glide.with(this@AwesomeWebViewActivity).asBitmap().timeout(30000).diskCacheStrategy(DiskCacheStrategy.ALL).load(url).submit().get()
|
|
|
|
|
WebResourceResponse("image/jpg", "UTF-8",getBitmapInputStream(bitmap,Bitmap.CompressFormat.JPEG))
|
|
|
|
|
} catch (e : Exception) {
|
|
|
|
|
super.shouldInterceptRequest(view, url)
|
|
|
|
|
}
|
|
|
|
|
}else if(url.toLowerCase(Locale.ROOT).contains(".png")){
|
|
|
|
|
try {
|
|
|
|
|
val bitmap = Glide.with(this@AwesomeWebViewActivity).asBitmap().timeout(30000).diskCacheStrategy(DiskCacheStrategy.ALL).load(url).submit().get()
|
|
|
|
|
WebResourceResponse("image/png", "UTF-8",getBitmapInputStream(bitmap,Bitmap.CompressFormat.PNG))
|
|
|
|
|
} catch (e : Exception) {
|
|
|
|
|
super.shouldInterceptRequest(view, url)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else if(url.toLowerCase(Locale.ROOT).contains(".webp")){
|
|
|
|
|
try {
|
|
|
|
|
val bitmap = Glide.with(this@AwesomeWebViewActivity).asBitmap().timeout(30000).diskCacheStrategy(DiskCacheStrategy.ALL).load(url).submit().get()
|
|
|
|
|
WebResourceResponse("image/webp", "UTF-8",getBitmapInputStream(bitmap,Bitmap.CompressFormat.WEBP))
|
|
|
|
|
} catch (e : Exception) {
|
|
|
|
|
super.shouldInterceptRequest(view, url)
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
super.shouldInterceptRequest(view, url)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private fun getBitmapInputStream(bitmap: Bitmap, compressFormat: Bitmap.CompressFormat): InputStream {
|
|
|
|
|
val byteArrayOutputStream = ByteArrayOutputStream()
|
|
|
|
|
bitmap.compress(compressFormat, 80, byteArrayOutputStream)
|
|
|
|
|
val bitmapData: ByteArray = byteArrayOutputStream.toByteArray()
|
|
|
|
|
return ByteArrayInputStream(bitmapData)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// override fun shouldInterceptRequest(view: WebView, url: String): WebResourceResponse? {
|
|
|
|
|
// LogUtil.e("shouldInterceptRequest String >>> $url")
|
|
|
|
|
// if (url.contains("gif")) {
|
|
|
|
|
// return null
|
|
|
|
|
// }
|
|
|
|
|
// return super.shouldInterceptRequest(view, url)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
@@ -1862,6 +1917,19 @@ LogUtil.e("onBackPressed ${webChromeClient} && ${binding.menus.menuLayout.visibi
|
|
|
|
|
if (!url.contains("docs.google.com") && url.endsWith(".pdf")) {
|
|
|
|
|
webView!!.loadUrl("http://docs.google.com/gview?embedded=true&url=$url")
|
|
|
|
|
}
|
|
|
|
|
url.toUri().host?.let {
|
|
|
|
|
val splits = it.replace("http://","").replace("https://","").split(".")
|
|
|
|
|
when(splits.size) {
|
|
|
|
|
1-> host = splits[0]
|
|
|
|
|
2-> host = splits[0]
|
|
|
|
|
3-> host = splits[1]
|
|
|
|
|
4-> host = splits[2]
|
|
|
|
|
else -> {
|
|
|
|
|
host = null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
hasYoutubePlayer = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onPageFinished(view: WebView, url: String) {
|
|
|
|
@@ -1899,7 +1967,12 @@ LogUtil.e("onBackPressed ${webChromeClient} && ${binding.menus.menuLayout.visibi
|
|
|
|
|
|
|
|
|
|
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
|
|
|
|
|
handler.sendEmptyMessage(MSG_CLICK_ON_URL)
|
|
|
|
|
// LogUtil.e("host >>> ${host} , url >>> ${url}")
|
|
|
|
|
|
|
|
|
|
var skipResource = host!= null && ((url.contains(host!!) ?: true) == false) && (host!!.contains("google") == false)
|
|
|
|
|
if (skipResource) {
|
|
|
|
|
LogUtil.e("shouldOverrideUrlLoading block url $url , host >>>> $host ")
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
if (url.contains("coupang") == false && url.contains("aliex") == false) {
|
|
|
|
|
if (url.endsWith(".mp4")) {
|
|
|
|
|
val intent = Intent(Intent.ACTION_VIEW)
|
|
|
|
|