declex icon indicating copy to clipboard operation
declex copied to clipboard

Change default behavior of next item in action $AlertDialog

Open smaugho opened this issue 7 years ago • 0 comments

When an $AlertDialog is invoked, the default action is the positive button, for instance:

   $AlertDialog().message("Are you sure?").possitiveButton("Ok").negativeButton("Cancel");
   doSomethingHere();

The method doSomethingHere() would be executed if the possitive button is pressed, so that's the default action... but with $AlertDialog you construct more complex dialogs, for instance, one to select options:

    $AlertDialog().items(options);
    if ($AlertDialog.ItemSelected) {
        doSomethingHere();
    }

in this situation, it is clear that the default action should be when the item is selected... it would be good to implement a change in the default action, if some condition is satisfied (like in this case, no $AlertDialog).

But in this case, it is important to note, that if this is done, it should be done in a way that it access completely to the Runnable defined by the action ItemSelected, if not, then something like this wouldn't work:

$AlertDialog().items(options);
int $position = 0;
doSomethingWith($position);

One approach is to define builder actions selectors (with priority levels if necessary).. for instance

@Selector(value="PositiveButtonPressed", priority=1);
void positiveButton() {} 

@Selector(value="ItemSelected", priority=2);
void items() {} 

This would be declared in the Action Holder... so when the ActionProcessor parses this, determine which one to take as default depending of the called methods and following the priority.

By default of no selector is specified, then of course the first Selector would be the default one.

smaugho avatar Mar 10 '17 20:03 smaugho