AlertDialog binding

Sometimes we want to show an AlertDialog, but the title or the message of that dialog depends on a Field.

In this case we can use a FieldAlertDialogBuilder. This class extends AlertDialog.Builder from the AndroidX library, but provides the methods setTitle and setMessage that accept a Field of Charsequence and will respectively change the title or the message of the dialog as soon as the Field changes.

For example:

FieldAlertDialogBuilder() .setTitle( .setMessage( { name-> "Set $name as watched?" }) .setPositiveButton(...) .setNeutralButton(...) .show()
new FieldAlertDialogBuilder() .setTitle(movie.getName()) .setMessage(movie.getName().transform(name-> "Set " + name + " as watched?" )) .setPositiveButton(...) .setNeutralButton(...) .show();