+ val webpageFavoriteIconLinearLayout = alertDialog.findViewById<LinearLayout>(R.id.webpage_favorite_icon_linearlayout)!!
+ val webpageFavoriteIconRadioButton = alertDialog.findViewById<RadioButton>(R.id.webpage_favorite_icon_radiobutton)!!
+ val webpageFavoriteIconImageView = alertDialog.findViewById<ImageView>(R.id.webpage_favorite_icon_imageview)!!
+ customIconLinearLayout = alertDialog.findViewById(R.id.custom_icon_linearlayout)!!
+ val customIconRadioButton = alertDialog.findViewById<RadioButton>(R.id.custom_icon_radiobutton)!!
+ customIconImageView = alertDialog.findViewById(R.id.custom_icon_imageview)!!
+ val browseButton = alertDialog.findViewById<Button>(R.id.browse_button)!!
+ bookmarkNameEditText = alertDialog.findViewById(R.id.bookmark_name_edittext)!!
+ bookmarkUrlEditText = alertDialog.findViewById(R.id.bookmark_url_edittext)!!
+ createButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE)
+
+ // Populate the views.
+ webpageFavoriteIconImageView.setImageBitmap(favoriteIconBitmap)
+ customIconImageView.setImageDrawable(AppCompatResources.getDrawable(requireContext(), R.drawable.world))
+ bookmarkNameEditText.setText(title)
+ bookmarkUrlEditText.setText(urlString)
+
+ // Set the radio button listeners. These perform a click on the linear layout, which contains the necessary logic.
+ webpageFavoriteIconRadioButton.setOnClickListener { webpageFavoriteIconLinearLayout.performClick() }
+ customIconRadioButton.setOnClickListener { customIconLinearLayout.performClick() }
+
+ // Set the webpage favorite icon linear layout click listener.
+ webpageFavoriteIconLinearLayout.setOnClickListener {
+ // Check the webpage favorite icon radio button.
+ webpageFavoriteIconRadioButton.isChecked = true
+
+ // Uncheck the custom icon radio button.
+ customIconRadioButton.isChecked = false
+ }
+
+ // Set the custom icon linear layout click listener.
+ customIconLinearLayout.setOnClickListener {
+ // Check the custom icon radio button.
+ customIconRadioButton.isChecked = true
+
+ // Uncheck the webpage favorite icon radio button.
+ webpageFavoriteIconRadioButton.isChecked = false
+ }
+
+ browseButton.setOnClickListener {
+ // Open the file picker.
+ browseActivityResultLauncher.launch("image/*")
+ }
+
+ // Update the UI when the bookmark name changes.
+ bookmarkNameEditText.addTextChangedListener(object : TextWatcher {
+ override fun beforeTextChanged(charSequence: CharSequence?, start: Int, count: Int, after: Int) {
+ // Do nothing.
+ }
+
+ override fun onTextChanged(charSequence: CharSequence?, start: Int, before: Int, count: Int) {
+ // Do nothing.
+ }
+
+ override fun afterTextChanged(editable: Editable?) {
+ // Update the UI.
+ updateUi()
+ }
+ })
+
+ // Update the UI when the bookmark name changes.
+ bookmarkUrlEditText.addTextChangedListener(object : TextWatcher {
+ override fun beforeTextChanged(charSequence: CharSequence?, start: Int, count: Int, after: Int) {
+ // Do nothing.
+ }
+
+ override fun onTextChanged(charSequence: CharSequence?, start: Int, befire: Int, count: Int) {
+ // Do nothing.
+ }