@SuppressLint("InflateParams")
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
// Get the arguments.
- val arguments = arguments!!
+ val arguments = requireArguments()
// Get the strings from the arguments.
val initialShortcutName = arguments.getString("shortcut_name")
// Convert the favorite icon byte array to a bitmap.
val favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.size)
- // Get a handle for the shared preferences.
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
-
- // Get the theme and screenshot preferences.
- val allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false)
- val darkTheme = sharedPreferences.getBoolean("dark_theme", false)
-
- // Use an alert dialog builder to create the dialog and set the style according to the theme.
- val dialogBuilder = if (darkTheme) {
- AlertDialog.Builder(activity!!, R.style.PrivacyBrowserAlertDialogDark)
- } else {
- AlertDialog.Builder(activity!!, R.style.PrivacyBrowserAlertDialogLight)
- }
+ // Use an alert dialog builder to create the dialog.
+ val dialogBuilder = AlertDialog.Builder(requireContext(), R.style.PrivacyBrowserAlertDialog)
// Create a drawable version of the favorite icon.
val favoriteIconDrawable: Drawable = BitmapDrawable(resources, favoriteIconBitmap)
dialogBuilder.setIcon(favoriteIconDrawable)
// Set the view. The parent view is null because it will be assigned by the alert dialog.
- dialogBuilder.setView(activity!!.layoutInflater.inflate(R.layout.create_home_screen_shortcut_dialog, null))
+ dialogBuilder.setView(requireActivity().layoutInflater.inflate(R.layout.create_home_screen_shortcut_dialog, null))
// Set a listener on the close button. Using null closes the dialog without doing anything else.
dialogBuilder.setNegativeButton(R.string.cancel, null)
// Create an alert dialog from the alert dialog builder.
val alertDialog = dialogBuilder.create()
+ // Get a handle for the shared preferences.
+ val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
+
+ // Get the screenshot preference.
+ val allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false)
+
// Disable screenshots if not allowed.
if (!allowScreenshots) {
alertDialog.window!!.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
private fun createHomeScreenShortcut(favoriteIconBitmap: Bitmap) {
- // Get a handle for the context.
- val context = context!!
-
// Get the strings from the edit texts.
val shortcutName = shortcutNameEditText.text.toString()
val urlString = urlEditText.text.toString()
shortcutIntent.data = Uri.parse(urlString)
// Create a shortcut info builder. The shortcut name becomes the shortcut ID.
- val shortcutInfoBuilder = ShortcutInfoCompat.Builder(context, shortcutName)
+ val shortcutInfoBuilder = ShortcutInfoCompat.Builder(requireContext(), shortcutName)
// Add the required fields to the shortcut info builder.
shortcutInfoBuilder.setIcon(favoriteIcon)
shortcutInfoBuilder.setShortLabel(shortcutName)
// Add the shortcut to the home screen. `ShortcutManagerCompat` can be switched to `ShortcutManager` once the minimum API >= 26.
- ShortcutManagerCompat.requestPinShortcut(context, shortcutInfoBuilder.build(), null)
+ ShortcutManagerCompat.requestPinShortcut(requireContext(), shortcutInfoBuilder.build(), null)
}
}
\ No newline at end of file