From 630966d4699fd2486673378fd9a4d313a6a1d37e Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Fri, 7 Jun 2024 16:45:10 +0530 Subject: [PATCH] Fixed: Long clicking on Download button in epub ZIM files shows the Open in new tab dialog which leads to a blank page. * We didn't account for the scenario where a user long-clicks on an image that contains an anchor tag with a URL. For now, we only check when a link is loading(when user simply clicks on the image button), and if the link is unsupported by Kiwix, we show the save/open dialog. Now, we are also checking for this scenario on long clicks. --- .../org/kiwix/kiwixmobile/core/main/CoreWebViewClient.kt | 2 +- .../java/org/kiwix/kiwixmobile/core/main/KiwixWebView.kt | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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 25b8ed045f..3e7d238df8 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 @@ -77,7 +77,7 @@ open class CoreWebViewClient( } @Suppress("NestedBlockDepth") - private fun handleUnsupportedFiles(url: String): Boolean { + fun handleUnsupportedFiles(url: String): Boolean { val extension = MimeTypeMap.getFileExtensionFromUrl(url) if (DOCUMENT_TYPES.containsKey(extension)) { callback.showSaveOrOpenUnsupportedFilesDialog(url, DOCUMENT_TYPES[extension]) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/KiwixWebView.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/KiwixWebView.kt index e3ac51b6e9..4948980347 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/KiwixWebView.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/KiwixWebView.kt @@ -54,7 +54,7 @@ open class KiwixWebView @SuppressLint("SetJavaScriptEnabled") constructor( attrs: AttributeSet, nonVideoView: ViewGroup, videoView: ViewGroup, - webViewClient: CoreWebViewClient, + private val webViewClient: CoreWebViewClient, val sharedPreferenceUtil: SharedPreferenceUtil ) : VideoEnabledWebView(context, attrs) { @@ -108,7 +108,11 @@ open class KiwixWebView @SuppressLint("SetJavaScriptEnabled") constructor( override fun performLongClick(): Boolean { val result = hitTestResult if (result.type == HitTestResult.SRC_ANCHOR_TYPE) { - result.extra?.let(callback::webViewLongClick) + result.extra?.let { + if (!webViewClient.handleUnsupportedFiles(it)) { + callback.webViewLongClick(it) + } + } return true } return super.performLongClick()