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.
This commit is contained in:
MohitMaliFtechiz 2024-06-07 16:45:10 +05:30 committed by Kelson
parent 694e76bbb0
commit 630966d469
2 changed files with 7 additions and 3 deletions

View File

@ -77,7 +77,7 @@ open class CoreWebViewClient(
} }
@Suppress("NestedBlockDepth") @Suppress("NestedBlockDepth")
private fun handleUnsupportedFiles(url: String): Boolean { fun handleUnsupportedFiles(url: String): Boolean {
val extension = MimeTypeMap.getFileExtensionFromUrl(url) val extension = MimeTypeMap.getFileExtensionFromUrl(url)
if (DOCUMENT_TYPES.containsKey(extension)) { if (DOCUMENT_TYPES.containsKey(extension)) {
callback.showSaveOrOpenUnsupportedFilesDialog(url, DOCUMENT_TYPES[extension]) callback.showSaveOrOpenUnsupportedFilesDialog(url, DOCUMENT_TYPES[extension])

View File

@ -54,7 +54,7 @@ open class KiwixWebView @SuppressLint("SetJavaScriptEnabled") constructor(
attrs: AttributeSet, attrs: AttributeSet,
nonVideoView: ViewGroup, nonVideoView: ViewGroup,
videoView: ViewGroup, videoView: ViewGroup,
webViewClient: CoreWebViewClient, private val webViewClient: CoreWebViewClient,
val sharedPreferenceUtil: SharedPreferenceUtil val sharedPreferenceUtil: SharedPreferenceUtil
) : VideoEnabledWebView(context, attrs) { ) : VideoEnabledWebView(context, attrs) {
@ -108,7 +108,11 @@ open class KiwixWebView @SuppressLint("SetJavaScriptEnabled") constructor(
override fun performLongClick(): Boolean { override fun performLongClick(): Boolean {
val result = hitTestResult val result = hitTestResult
if (result.type == HitTestResult.SRC_ANCHOR_TYPE) { 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 true
} }
return super.performLongClick() return super.performLongClick()