+ // Convert the URL to a URI.
+ Uri currentUri = Uri.parse(url);
+
+ // Display the host in the add domain edit text.
+ addDomainEditText.setText(currentUri.getHost());
+
+ // Allow the enter key on the keyboard to create the domain from the add domain edit text.
+ addDomainEditText.setOnKeyListener((View view, int keyCode, KeyEvent event) -> {
+ // If the event is a key-down on the enter key, select the `PositiveButton` `Add`.
+ if ((keyCode == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN)) {
+ // Trigger `addDomainListener` and return the dialog fragment to the parent activity.
+ addDomainListener.onAddDomain(this);
+
+ // Manually dismiss the alert dialog.
+ alertDialog.dismiss();
+
+ // Consume the event.
+ return true;
+ } else { // If any other key was pressed, do not consume the event.
+ return false;
+ }
+ });
+
+ // Return the alert dialog.