aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-12-30 12:18:46 -0800
committerAllan Wang <me@allanwang.ca>2019-12-30 12:18:46 -0800
commitc4afa99d44c94dd9f95ed74f57e00466cd431d18 (patch)
tree95d426513e3dc466b1ab2568275e078b9cc075b7 /app/src/main/kotlin/com/pitchedapps
parent999e87a8c879d8112e62baf45cbe4e876d35b9cc (diff)
downloadfrost-c4afa99d44c94dd9f95ed74f57e00466cd431d18.tar.gz
frost-c4afa99d44c94dd9f95ed74f57e00466cd431d18.tar.bz2
frost-c4afa99d44c94dd9f95ed74f57e00466cd431d18.zip
Use MaterialDialog for webviews
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt72
1 files changed, 72 insertions, 0 deletions
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