From c4afa99d44c94dd9f95ed74f57e00466cd431d18 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 30 Dec 2019 12:18:46 -0800 Subject: Use MaterialDialog for webviews --- .../pitchedapps/frost/web/FrostChromeClients.kt | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt index 9577aeb0..03bfacd5 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt @@ -19,11 +19,16 @@ package com.pitchedapps.frost.web import android.net.Uri import android.webkit.ConsoleMessage import android.webkit.GeolocationPermissions +import android.webkit.JsPromptResult +import android.webkit.JsResult import android.webkit.ValueCallback import android.webkit.WebChromeClient import android.webkit.WebView import ca.allanwang.kau.permissions.PERMISSION_ACCESS_FINE_LOCATION import ca.allanwang.kau.permissions.kauRequestPermissions +import ca.allanwang.kau.utils.materialDialog +import com.afollestad.materialdialogs.callbacks.onDismiss +import com.afollestad.materialdialogs.input.input import com.pitchedapps.frost.R import com.pitchedapps.frost.contracts.ActivityContract import com.pitchedapps.frost.utils.L @@ -73,6 +78,73 @@ class FrostChromeClient(web: FrostWebView) : WebChromeClient() { return activity != null } + override fun onJsAlert( + view: WebView, + url: String, + message: String, + result: JsResult + ): Boolean { + view.context.materialDialog { + title(text = url) + message(text = message) + positiveButton { result.confirm() } + onDismiss { result.cancel() } + } + return true + } + + override fun onJsConfirm( + view: WebView, + url: String, + message: String, + result: JsResult + ): Boolean { + view.context.materialDialog { + title(text = url) + message(text = message) + positiveButton { result.confirm() } + negativeButton { result.cancel() } + onDismiss { result.cancel() } + } + return true + } + + override fun onJsBeforeUnload( + view: WebView, + url: String, + message: String, + result: JsResult + ): Boolean { + view.context.materialDialog { + title(text = url) + message(text = message) + positiveButton { result.confirm() } + negativeButton { result.cancel() } + onDismiss { result.cancel() } + } + return true + } + + override fun onJsPrompt( + view: WebView, + url: String, + message: String, + defaultValue: String?, + result: JsPromptResult + ): Boolean { + view.context.materialDialog { + title(text = url) + message(text = message) + input(prefill = defaultValue) { _, charSequence -> + result.confirm(charSequence.toString()) + } + // positive button added through input + negativeButton { result.cancel() } + onDismiss { result.cancel() } + } + return true + } + override fun onGeolocationPermissionsShowPrompt( origin: String, callback: GeolocationPermissions.Callback -- cgit v1.2.3