]> gitweb.stoutner.com Git - PrivacyCell.git/blob - 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
1 /*
2  * Copyright © 2021 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell>.
5  *
6  * Privacy Cell is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Cell is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package com.stoutner.privacycell.dialogs
21
22 import android.app.Dialog
23 import android.content.res.Configuration
24 import android.os.Bundle
25 import android.webkit.WebView
26
27 import androidx.appcompat.app.AlertDialog
28 import androidx.fragment.app.DialogFragment
29 import androidx.webkit.WebSettingsCompat
30 import androidx.webkit.WebViewFeature
31
32 import com.stoutner.privacycell.R
33
34 class PermissionsDialog : DialogFragment() {
35     override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
36         // Use a builder to create the alert dialog.
37         val dialogBuilder = AlertDialog.Builder(requireContext(), R.style.Theme_PrivacyCellAlertDialog)
38
39         // Set the icon.
40         dialogBuilder.setIcon(R.drawable.permissions)
41
42         // Set the title.
43         dialogBuilder.setTitle(R.string.permissions)
44
45         // Set the view.
46         dialogBuilder.setView(R.layout.permissions_dialog)
47
48         // Set a listener on the close button.  Using `null` as the listener closes the dialog without doing anything else.
49         dialogBuilder.setNegativeButton(R.string.close, null)
50
51         // Create an alert dialog from the builder.
52         val alertDialog = dialogBuilder.create()
53
54         // The alert dialog needs to be shown before the contents can be modified.
55         alertDialog.show()
56
57         // Get a handle for the WebView.
58         val webView = alertDialog.findViewById<WebView>(R.id.webview)!!
59
60         // Get the current theme status.
61         val currentThemeStatus = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
62
63         // Check to see if the app is in night mode.
64         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES && WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {  // The app is in night mode.
65             // Apply the dark WebView theme.
66             WebSettingsCompat.setForceDark(webView.settings, WebSettingsCompat.FORCE_DARK_ON)
67         }
68
69         // Create a WebView asset loader.  TODO.
70         // val webViewAssetLoader = WebViewAssetLoader.Builder().addPathHandler("/assets/", WebViewAssetLoader.AssetsPathHandler(requireContext())).build()
71
72         // Load the WebView data.
73         webView.loadUrl("file:///android_asset/en/permissions.html")
74
75         // Return the alert dialog.
76         return alertDialog
77     }
78 }