]> gitweb.stoutner.com Git - PrivacyCell.git/blobdiff - app/src/main/java/com/stoutner/privacycell/dialogs/PermissionsDialog.kt
Populate the permissions menu entry.
[PrivacyCell.git] / app / src / main / java / com / stoutner / privacycell / dialogs / PermissionsDialog.kt
diff --git a/app/src/main/java/com/stoutner/privacycell/dialogs/PermissionsDialog.kt b/app/src/main/java/com/stoutner/privacycell/dialogs/PermissionsDialog.kt
new file mode 100644 (file)
index 0000000..8cf799e
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright © 2021 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell>.
+ *
+ * Privacy Cell is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Cell is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+package com.stoutner.privacycell.dialogs
+
+import android.app.Dialog
+import android.content.res.Configuration
+import android.os.Bundle
+import android.webkit.WebView
+
+import androidx.appcompat.app.AlertDialog
+import androidx.fragment.app.DialogFragment
+import androidx.webkit.WebSettingsCompat
+import androidx.webkit.WebViewFeature
+
+import com.stoutner.privacycell.R
+
+class PermissionsDialog : DialogFragment() {
+    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+        // Use a builder to create the alert dialog.
+        val dialogBuilder = AlertDialog.Builder(requireContext(), R.style.Theme_PrivacyCellAlertDialog)
+
+        // Set the icon.
+        dialogBuilder.setIcon(R.drawable.permissions)
+
+        // Set the title.
+        dialogBuilder.setTitle(R.string.permissions)
+
+        // Set the view.
+        dialogBuilder.setView(R.layout.permissions_dialog)
+
+        // Set a listener on the close button.  Using `null` as the listener closes the dialog without doing anything else.
+        dialogBuilder.setNegativeButton(R.string.close, null)
+
+        // Create an alert dialog from the builder.
+        val alertDialog = dialogBuilder.create()
+
+        // The alert dialog needs to be shown before the contents can be modified.
+        alertDialog.show()
+
+        // Get a handle for the WebView.
+        val webView = alertDialog.findViewById<WebView>(R.id.webview)!!
+
+        // Get the current theme status.
+        val currentThemeStatus = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
+
+        // Check to see if the app is in night mode.
+        if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES && WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {  // The app is in night mode.
+            // Apply the dark WebView theme.
+            WebSettingsCompat.setForceDark(webView.settings, WebSettingsCompat.FORCE_DARK_ON)
+        }
+
+        // Create a WebView asset loader.  TODO.
+        // val webViewAssetLoader = WebViewAssetLoader.Builder().addPathHandler("/assets/", WebViewAssetLoader.AssetsPathHandler(requireContext())).build()
+
+        // Load the WebView data.
+        webView.loadUrl("file:///android_asset/en/permissions.html")
+
+        // Return the alert dialog.
+        return alertDialog
+    }
+}
\ No newline at end of file