X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;ds=inline;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Fdialogs%2FWebViewDialog.kt;h=8fd2edb15bd7f302120620e95f87a21cf18d8a57;hb=2f280a085efa15139e1a2df023f983bf296981f6;hp=5961c2e51c0500773f7dbe6770b3487b4ff0658b;hpb=70fa89f618b62a9d17064699ec130341069aa77d;p=PrivacyCell.git
diff --git a/app/src/main/java/com/stoutner/privacycell/dialogs/WebViewDialog.kt b/app/src/main/java/com/stoutner/privacycell/dialogs/WebViewDialog.kt
index 5961c2e..8fd2edb 100644
--- a/app/src/main/java/com/stoutner/privacycell/dialogs/WebViewDialog.kt
+++ b/app/src/main/java/com/stoutner/privacycell/dialogs/WebViewDialog.kt
@@ -14,19 +14,24 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with Privacy Browser. If not, see .
+ * along with Privacy Cell. If not, see .
*/
package com.stoutner.privacycell.dialogs
import android.app.Dialog
+import android.content.Intent
import android.content.res.Configuration
import android.os.Bundle
+import android.webkit.WebResourceRequest
+import android.webkit.WebResourceResponse
import android.webkit.WebView
+import android.webkit.WebViewClient
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import androidx.webkit.WebSettingsCompat
+import androidx.webkit.WebViewAssetLoader
import androidx.webkit.WebViewFeature
import com.stoutner.privacycell.R
@@ -41,6 +46,8 @@ class WebViewDialog : DialogFragment() {
const val PERMISSIONS = 0
const val PRIVACY_POLICY = 1
const val CHANGELOG = 2
+ const val LICENSES = 3
+ const val CONTRIBUTORS = 4
}
// Define the class views.
@@ -96,6 +103,22 @@ class WebViewDialog : DialogFragment() {
// Set the title.
dialogBuilder.setTitle(R.string.changelog)
}
+
+ LICENSES -> {
+ // Set the icon.
+ dialogBuilder.setIcon(R.drawable.licenses)
+
+ // Set the title.
+ dialogBuilder.setTitle(R.string.licenses)
+ }
+
+ CONTRIBUTORS -> {
+ // Set the icon.
+ dialogBuilder.setIcon(R.drawable.contributors)
+
+ // Set the tile.
+ dialogBuilder.setTitle(R.string.contributors)
+ }
}
// Set the view.
@@ -122,14 +145,40 @@ class WebViewDialog : DialogFragment() {
WebSettingsCompat.setForceDark(webView.settings, WebSettingsCompat.FORCE_DARK_ON)
}
- // Create a WebView asset loader. TODO.
- // val webViewAssetLoader = WebViewAssetLoader.Builder().addPathHandler("/assets/", WebViewAssetLoader.AssetsPathHandler(requireContext())).build()
+ // Create a WebView asset loader.
+ val webViewAssetLoader = WebViewAssetLoader.Builder().addPathHandler("/assets/", WebViewAssetLoader.AssetsPathHandler(requireContext())).build()
+
+ // Set a WebView client.
+ webView.webViewClient = object : WebViewClient() {
+ // Send external links to a web browser.
+ override fun shouldOverrideUrlLoading(view: WebView, webResourceRequest: WebResourceRequest): Boolean {
+ // Create an intent to view the URL.
+ val urlIntent = Intent(Intent.ACTION_VIEW)
+
+ // Add the URL to the intent.
+ urlIntent.data = webResourceRequest.url
+
+ // Make it so.
+ startActivity(urlIntent)
+
+ // Consume the click.
+ return true
+ }
+
+ // Process asset requests with the asset loader.
+ override fun shouldInterceptRequest(webView: WebView, webResourceRequest: WebResourceRequest): WebResourceResponse? {
+ // This allows using the `appassets.androidplatform.net` URL, which handles the loading of SVG files, which otherwise is prevented by the CORS policy.
+ return webViewAssetLoader.shouldInterceptRequest(webResourceRequest.url)
+ }
+ }
// Load the WebView data according to the dialog type.
when (dialogType) {
- PERMISSIONS -> webView.loadUrl("file:///android_asset/en/permissions.html")
- PRIVACY_POLICY -> webView.loadUrl("file:///android_asset/en/privacy_policy.html")
- CHANGELOG -> webView.loadUrl("file:///android_asset/en/changelog.html")
+ PERMISSIONS -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/permissions.html")
+ PRIVACY_POLICY -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/privacy_policy.html")
+ CHANGELOG -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/changelog.html")
+ LICENSES -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/licenses.html")
+ CONTRIBUTORS -> webView.loadUrl("https://appassets.androidplatform.net/assets/" + getString(R.string.asset_directory) + "/contributors.html")
}
// Scroll the WebView if the saved instance state is not null.