- // Load the text for `edit_bookmark_url_edittext`.
- EditText bookmarkUrlEditText = (EditText) alertDialog.findViewById(R.id.edit_bookmark_url_edittext);
- bookmarkUrlEditText.setText(bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)));
-
- // Allow the "enter" key on the keyboard to save the bookmark from `edit_bookmark_url_edittext`.
- bookmarkUrlEditText.setOnKeyListener(new View.OnKeyListener() {
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- // If the event is a key-down on the `enter` button, select the PositiveButton `Save`.
- if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
- // Trigger `editBookmarkListener` and return the DialogFragment to the parent activity.
- editBookmarkListener.onSaveEditBookmark(EditBookmarkDialog.this);
- // Manually dismiss the `AlertDialog`.
- alertDialog.dismiss();
- // Consume the event.
- return true;
- } else { // If any other key was pressed, do not consume the event.
- return false;
- }
+ // 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.
+ }
+
+ @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();
+ }
+ });
+
+ // Allow the `enter` key on the keyboard to save the bookmark from the bookmark name `EditText`.
+ nameEditText.setOnKeyListener((View v, int keyCode, KeyEvent event) -> {
+ // Save the bookmark if the event is a key-down on the "enter" button.
+ if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER) && editButton.isEnabled()) { // The enter key was pressed and the edit button is enabled.
+ // Trigger the `Listener` and return the `DialogFragment` to the parent activity.
+ editBookmarkListener.onSaveBookmark(EditBookmarkDialog.this, selectedBookmarkDatabaseId);
+
+ // Manually dismiss `alertDialog`.
+ alertDialog.dismiss();
+
+ // Consume the event.
+ return true;
+ } else { // If any other key was pressed, or if the edit button is currently disabled, do not consume the event.
+ return false;
+ }
+ });
+
+ // Allow the "enter" key on the keyboard to save the bookmark from the URL `EditText`.
+ urlEditText.setOnKeyListener((View v, int keyCode, KeyEvent event) -> {
+ // Save the bookmark if the event is a key-down on the "enter" button.
+ if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER) && editButton.isEnabled()) { // The enter key was pressed and the edit button is enabled.
+ // Trigger the `Listener` and return the DialogFragment to the parent activity.
+ editBookmarkListener.onSaveBookmark(EditBookmarkDialog.this, selectedBookmarkDatabaseId);
+
+ // Manually dismiss the `AlertDialog`.
+ alertDialog.dismiss();
+
+ // Consume the event.
+ return true;
+ } else { // If any other key was pressed, or if the edit button is currently disabled, do not consume the event.
+ return false;