]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmarkFolderDialog.kt
Convert a number of files to Kotlin. https://redmine.stoutner.com/issues/641
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / dialogs / CreateBookmarkFolderDialog.kt
index 83670bc8923b66b1ddb5fc0f8244b6efc042287f..d5fd6d82d8390996022a5183d03483fa01efc934 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2016-2020 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2016-2021 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
  *
@@ -16,6 +16,7 @@
  * 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.privacybrowser.dialogs
 
 import android.annotation.SuppressLint
@@ -42,15 +43,18 @@ import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper
 
 import java.io.ByteArrayOutputStream
 
-class CreateBookmarkFolderDialog: DialogFragment() {
+// Declare the class constants.
+private const val FAVORITE_ICON_BYTE_ARRAY = "favorite_icon_byte_array"
+
+class CreateBookmarkFolderDialog : DialogFragment() {
+    // Declare the class variables.
+    private lateinit var createBookmarkFolderListener: CreateBookmarkFolderListener
+
     // The public interface is used to send information back to the parent activity.
     interface CreateBookmarkFolderListener {
         fun onCreateBookmarkFolder(dialogFragment: DialogFragment, favoriteIconBitmap: Bitmap)
     }
 
-    // The create bookmark folder listener is initialized in `onAttach()` and used in `onCreateDialog()`.
-    private lateinit var createBookmarkFolderListener: CreateBookmarkFolderListener
-
     override fun onAttach(context: Context) {
         // Run the default commands.
         super.onAttach(context)
@@ -60,7 +64,7 @@ class CreateBookmarkFolderDialog: DialogFragment() {
     }
 
     companion object {
-        // `@JvmStatic` will no longer be required once all the code has transitioned to Kotlin.  Also, the function can then be moved out of a companion object and just become a package-level function.
+        // `@JvmStatic` will no longer be required once all the code has transitioned to Kotlin.
         @JvmStatic
         fun createBookmarkFolder(favoriteIconBitmap: Bitmap): CreateBookmarkFolderDialog {
             // Create a favorite icon byte array output stream.
@@ -76,7 +80,7 @@ class CreateBookmarkFolderDialog: DialogFragment() {
             val argumentsBundle = Bundle()
 
             // Store the favorite icon in the bundle.
-            argumentsBundle.putByteArray("favorite_icon_byte_array", favoriteIconByteArray)
+            argumentsBundle.putByteArray(FAVORITE_ICON_BYTE_ARRAY, favoriteIconByteArray)
 
             // Create a new instance of the dialog.
             val createBookmarkFolderDialog = CreateBookmarkFolderDialog()
@@ -89,14 +93,14 @@ class CreateBookmarkFolderDialog: DialogFragment() {
         }
     }
 
-    // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the alert dialog.
+    // `@SuppressLint("InflateParams")` removes the warning about using `null` as the parent view group when inflating the alert dialog.
     @SuppressLint("InflateParams")
     override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
         // Get the arguments.
         val arguments = requireArguments()
 
         // Get the favorite icon byte array.
-        val favoriteIconByteArray = arguments.getByteArray("favorite_icon_byte_array")!!
+        val favoriteIconByteArray = arguments.getByteArray(FAVORITE_ICON_BYTE_ARRAY)!!
 
         // Convert the favorite icon byte array to a bitmap.
         val favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.size)
@@ -126,7 +130,7 @@ class CreateBookmarkFolderDialog: DialogFragment() {
         val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
 
         // Get the screenshot preference.
-        val allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false)
+        val allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)
 
         // Disable screenshots if not allowed.
         if (!allowScreenshots) {