From 183914a254c6b5c2c77340ee35b1d0268ad749fa Mon Sep 17 00:00:00 2001 From: darkryh Date: Mon, 16 Sep 2024 14:01:23 -0500 Subject: [PATCH] Migrated code from logic in BaseWebView and added functions onBeforeOverridingUrl and onBeforeInterceptRequest --- .../models/BlockerClient.kt | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/NoMoreAdsOnMyWebViewPlayer/src/main/java/com/ead/lib/nomoreadsonmywebviewplayer/models/BlockerClient.kt b/NoMoreAdsOnMyWebViewPlayer/src/main/java/com/ead/lib/nomoreadsonmywebviewplayer/models/BlockerClient.kt index 4f49f7c..b765036 100644 --- a/NoMoreAdsOnMyWebViewPlayer/src/main/java/com/ead/lib/nomoreadsonmywebviewplayer/models/BlockerClient.kt +++ b/NoMoreAdsOnMyWebViewPlayer/src/main/java/com/ead/lib/nomoreadsonmywebviewplayer/models/BlockerClient.kt @@ -24,6 +24,12 @@ open class BlockerClient( */ val url = request?.url.toString() + /** + * Getting onInterceptingOverridingUrl to have the possibility to + * in case the they need to customize + */ + val onBeforeOverridingUrl = onBeforeOverridingUrl(view, request) + if (onBeforeOverridingUrl != null) return onBeforeOverridingUrl /** @@ -66,7 +72,7 @@ open class BlockerClient( * return a normal resource * if not just an empty resource */ - return onByPassOverridingUrl(view, request) ?: !isPermitted + return !isPermitted } /** @@ -86,6 +92,15 @@ open class BlockerClient( val url = request?.url.toString() + /** + * Getting onInterceptingInterceptRequest to have the possibility to + * in case the they need to customize + */ + val onBeforeInterceptRequest = onBeforeInterceptRequest(view, request) + + if (onBeforeInterceptRequest != null) return onBeforeInterceptRequest + + /** * Initializing is permitted @@ -127,17 +142,18 @@ open class BlockerClient( * return a normal resource * if not just an empty resource */ + return if (isPermitted) super.onPassingInterceptRequest(view, request) - else onByPassInterceptRequest(view, request) ?: emptyResource + else emptyResource } /** * Used to validate, to replace shouldOverrideUrlLoading */ - protected open fun onByPassOverridingUrl(view: WebView?, request: WebResourceRequest?) : Boolean? = null + protected open fun onBeforeOverridingUrl(view: WebView?, request: WebResourceRequest?) : Boolean? = null /** * Used to validate, to replace shouldInterceptRequest */ - protected open fun onByPassInterceptRequest(view: WebView?, request: WebResourceRequest?) : WebResourceResponse? = null + protected open fun onBeforeInterceptRequest(view: WebView?, request: WebResourceRequest?) : WebResourceResponse? = null } \ No newline at end of file