From c4afa99d44c94dd9f95ed74f57e00466cd431d18 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 30 Dec 2019 12:18:46 -0800 Subject: [PATCH] Use MaterialDialog for webviews --- app/build.gradle | 2 + .../frost/web/FrostChromeClients.kt | 72 +++++++++++++++++++ app/src/main/play/en-US/whatsnew | 4 +- app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/styles.xml | 4 +- app/src/main/res/xml/frost_changelog.xml | 2 + docs/Changelog.md | 2 + 7 files changed, 84 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3fab88531..3e042a38f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -282,6 +282,8 @@ dependencies { implementation kau.Dependencies.iconicsMaterial implementation kau.Dependencies.iconicsCommunity + implementation kau.Dependencies.materialDialog("input") + implementation "org.jsoup:jsoup:${Versions.jsoup}" implementation "com.squareup.okhttp3:okhttp:${Versions.okhttp}" 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 9577aeb05..03bfacd5f 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 diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index e8ecee328..a7a34ee34 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -3,4 +3,6 @@ v2.4.2 * Fix back stack history * Fix search suggestions * Redesign navigation layout -* Update theme \ No newline at end of file +* Update theme +* Open formatted urls from context menu +* Allow copying text with emojis \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 4c685908e..1f1f08722 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -2,6 +2,7 @@ @color/facebook_blue #3b5998 + #6183C8 #2e4b86 @color/facebook_blue diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f17d005c6..f4fa9e6c6 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -3,7 +3,7 @@