From 3820fee2202c821c9f2c5ed11c557466f6ca4b65 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Mon, 1 Apr 2024 19:08:07 +0530 Subject: [PATCH] Fixed: Spurious message: "Error: Loading article (Url: https://upload.wikimedia.org/wikipedia/commons/6/65/Lock-green.svg" * The error toast message is no longer displayed if a URL fails to load. Instead, a debug error message is logged. * Restricting the loading of external resources when rendering the pages. --- .../org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt | 3 +-- .../org/kiwix/kiwixmobile/core/main/CoreWebViewClient.kt | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt index d81b74a20..e6bfc6e41 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt @@ -2037,8 +2037,7 @@ abstract class CoreReaderFragment : override fun webViewFailedLoading(url: String) { if (isAdded) { - val error = String.format(getString(R.string.error_article_url_not_found), url) - Toast.makeText(requireActivity(), error, Toast.LENGTH_SHORT).show() + Log.d(TAG_KIWIX, String.format(getString(R.string.error_article_url_not_found), url)) } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreWebViewClient.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreWebViewClient.kt index f05b5262d..cb4ceaf95 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreWebViewClient.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreWebViewClient.kt @@ -149,7 +149,13 @@ open class CoreWebViewClient( return if (url.startsWith(ZimFileReader.CONTENT_PREFIX)) { zimReaderContainer.load(url, request.requestHeaders) } else { - super.shouldInterceptRequest(view, request) + // Return an empty WebResourceResponse for the external resource to prevent + // it from being loaded. Passing null would trigger an attempt to load the resource. + WebResourceResponse( + "text/css", + Charsets.UTF_8.name(), + null + ) } }