+ // Does the folder name already exist?
+ boolean folderNameAlreadyExists = (!newFolderName.equals(currentFolderName) && (folderExistsCursor.getCount() > 0));
+
+ // Has the folder been renamed?
+ boolean folderRenamed = (!newFolderName.equals(currentFolderName) && !folderNameAlreadyExists);
+
+ // Has the favorite icon changed?
+ boolean iconChanged = (!currentIconRadioButton.isChecked() && !folderNameAlreadyExists);
+
+ // Enable the create button if something has been edited and the new folder name is valid.
+ editButton.setEnabled(folderNameNotEmpty && (folderRenamed || iconChanged));
+ }
+ });
+
+ // Update the status of the edit button when the icon is changed.
+ iconRadioGroup.setOnCheckedChangeListener((RadioGroup group, int checkedId) -> {
+ // Get the new folder name.
+ String newFolderName = folderNameEditText.getText().toString();
+
+ // Get a cursor for the new folder name if it exists.
+ Cursor folderExistsCursor = bookmarksDatabaseHelper.getFolderCursor(newFolderName);
+
+ // Is the new folder name empty?
+ boolean folderNameEmpty = newFolderName.isEmpty();
+
+ // Does the folder name already exist?
+ boolean folderNameAlreadyExists = (!newFolderName.equals(currentFolderName) && (folderExistsCursor.getCount() > 0));
+
+ // Has the folder been renamed?
+ boolean folderRenamed = (!newFolderName.equals(currentFolderName) && !folderNameAlreadyExists);
+
+ // Has the favorite icon changed?
+ boolean iconChanged = (!currentIconRadioButton.isChecked() && !folderNameAlreadyExists);
+
+ // Enable the create button if something has been edited and the new folder name is valid.
+ editButton.setEnabled(!folderNameEmpty && (folderRenamed || iconChanged));
+ });