X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FCreateBookmarkDialog.kt;h=a10e574a5a003ff012849fb6a1ce5e77373e0929;hb=a9b4d8c78a305c2602ced2058702254ea4e3b79b;hp=5bc2da25c4a01896b861a64184333826fb84481a;hpb=9df712df3780161d77d10c6f3a2444bf8f218c99;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.kt b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.kt index 5bc2da25..a10e574a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkDialog.kt @@ -20,7 +20,6 @@ package com.stoutner.privacybrowser.dialogs import android.annotation.SuppressLint -import android.app.AlertDialog import android.app.Dialog import android.content.Context import android.content.DialogInterface @@ -34,6 +33,7 @@ import android.view.View import android.view.WindowManager import android.widget.EditText +import androidx.appcompat.app.AlertDialog import androidx.fragment.app.DialogFragment import androidx.preference.PreferenceManager @@ -94,7 +94,7 @@ class CreateBookmarkDialog: DialogFragment() { @SuppressLint("InflateParams") override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { // Get the arguments. - val arguments = arguments!! + val arguments = requireArguments() // Get the contents of the arguments. val urlString = arguments.getString("url_string") @@ -104,19 +104,8 @@ class CreateBookmarkDialog: DialogFragment() { // 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 screenshot and theme 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(context, R.style.PrivacyBrowserAlertDialogDark) - } else { - AlertDialog.Builder(context, R.style.PrivacyBrowserAlertDialogLight) - } + // Use an alert dialog builder to create the dialog. + val dialogBuilder = AlertDialog.Builder(requireContext(), R.style.PrivacyBrowserAlertDialog) // Set the title. dialogBuilder.setTitle(R.string.create_bookmark) @@ -128,7 +117,7 @@ class CreateBookmarkDialog: DialogFragment() { 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_bookmark_dialog, null)) + dialogBuilder.setView(requireActivity().layoutInflater.inflate(R.layout.create_bookmark_dialog, null)) // Set a listener on the cancel button. Using `null` as the listener closes the dialog without doing anything else. dialogBuilder.setNegativeButton(R.string.cancel, null) @@ -142,6 +131,13 @@ class CreateBookmarkDialog: DialogFragment() { // Create an alert dialog from the 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) @@ -151,8 +147,8 @@ class CreateBookmarkDialog: DialogFragment() { alertDialog.show() // Get a handle for the edit texts. - val createBookmarkNameEditText: EditText = alertDialog.findViewById(R.id.create_bookmark_name_edittext) - val createBookmarkUrlEditText: EditText = alertDialog.findViewById(R.id.create_bookmark_url_edittext) + val createBookmarkNameEditText = alertDialog.findViewById(R.id.create_bookmark_name_edittext)!! + val createBookmarkUrlEditText = alertDialog.findViewById(R.id.create_bookmark_url_edittext)!! // Set the initial texts for the edit texts. createBookmarkNameEditText.setText(titleString)