Skip to content

Commit

Permalink
fix(android): fix dialog without selectedIndex reusage
Browse files Browse the repository at this point in the history
Prevents a dialog to be shown with the wrong type of buttons if reused.
  • Loading branch information
ypbnv authored and sgtcoolguy committed Aug 20, 2019
1 parent 632c439 commit a2a048f
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ClickHandler(int id)
}
public void onClick(DialogInterface dialog, int which)
{
handleEvent(result);
handleEvent(result, true);
hide(null);
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ private void processOptions(String[] optionText, int selectedIndex)
@Override
public void onClick(DialogInterface dialog, int which)
{
handleEvent(which);
handleEvent(which, true);
hide(null);
}
});
Expand All @@ -143,7 +143,7 @@ public void onClick(DialogInterface dialog, int which)
@Override
public void onClick(DialogInterface dialog, int which)
{
handleEvent(which);
handleEvent(which, false);
hide(null);
}
});
Expand Down Expand Up @@ -322,7 +322,8 @@ public void onCancel(DialogInterface dlg)
? TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_CANCEL))
: -1;
Log.d(TAG, "onCancelListener called. Sending index: " + cancelIndex, Log.DEBUG_MODE);
handleEvent(cancelIndex);
// In case wew cancel the Dialog we should not overwrite the selectedIndex
handleEvent(cancelIndex, false);
hide(null);
}
});
Expand Down Expand Up @@ -438,7 +439,7 @@ private void createBuilder()
}
}

public void handleEvent(int id)
public void handleEvent(int id, boolean saveSelectedIndex)
{
int cancelIndex =
(proxy.hasProperty(TiC.PROPERTY_CANCEL)) ? TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_CANCEL)) : -1;
Expand All @@ -452,8 +453,8 @@ public void handleEvent(int id)
id &= ~BUTTON_MASK;
} else {
data.put(TiC.PROPERTY_BUTTON, false);
// If an option was selected and the user accepted it, update the proxy.
if (proxy.hasProperty(TiC.PROPERTY_OPTIONS)) {
// If an option was selected, the user accepted and we are showing radio buttons, update the proxy.
if (proxy.hasProperty(TiC.PROPERTY_OPTIONS) && saveSelectedIndex) {
proxy.setProperty(TiC.PROPERTY_SELECTED_INDEX, id);
}
}
Expand Down

0 comments on commit a2a048f

Please sign in to comment.