- // Get a `Bitmap` of the favorite icon from `MainWebViewActivity` and display it in `edit_bookmark_web_page_favorite_icon`.
- ImageView newFavoriteIconImageView = (ImageView) alertDialog.findViewById(R.id.edit_bookmark_web_page_favorite_icon);
- assert newFavoriteIconImageView != null; // Remove the warning below that `newFavoriteIcon` might be null.
- newFavoriteIconImageView.setImageBitmap(MainWebViewActivity.favoriteIcon);
+ // Set the new favorite icon bitmap.
+ newFavoriteIconImageView.setImageBitmap(favoriteIconBitmap);
+
+ // Store the current bookmark name and URL.
+ String currentName = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
+ String currentUrl = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL));
+
+ // Populate the edit texts.
+ nameEditText.setText(currentName);
+ urlEditText.setText(currentUrl);
+
+ // Initially disable the edit button.
+ editButton.setEnabled(false);
+
+ // Update the edit button if the icon selection changes.
+ iconRadioGroup.setOnCheckedChangeListener((RadioGroup group, int checkedId) -> {
+ // Update the edit button.
+ updateEditButton(alertDialog, currentName, currentUrl);
+ });
+
+ // Update the edit button if the bookmark name changes.
+ nameEditText.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ // Do nothing.
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ // Do nothing.
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ // Update the edit button.
+ updateEditButton(alertDialog, currentName, currentUrl);
+ }
+ });
+
+ // Update the edit button if the URL changes.
+ urlEditText.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ // Do nothing.
+ }