Skip to content

Commit

Permalink
[TimePicker] Hide cancel button when it's not cancelable
Browse files Browse the repository at this point in the history
Resolves #2245

PiperOrigin-RevId: 381268475
  • Loading branch information
drchen authored and hunterstich committed Jun 28, 2021
1 parent c08a07d commit 35c2af3
Showing 1 changed file with 15 additions and 1 deletion.
Expand Up @@ -92,6 +92,7 @@ public final class MaterialTimePicker extends DialogFragment {
static final String OVERRIDE_THEME_RES_ID = "TIME_PICKER_OVERRIDE_THEME_RES_ID";

private MaterialButton modeButton;
private Button cancelButton;

@InputMode private int inputMode = INPUT_MODE_CLOCK;

Expand Down Expand Up @@ -246,7 +247,7 @@ public void onClick(View v) {
}
});

Button cancelButton = root.findViewById(R.id.material_timepicker_cancel_button);
cancelButton = root.findViewById(R.id.material_timepicker_cancel_button);
cancelButton.setOnClickListener(
new OnClickListener() {
@Override
Expand All @@ -257,6 +258,7 @@ public void onClick(View v) {
dismiss();
}
});
updateCancelButtonVisibility();

modeButton.setOnClickListener(
new OnClickListener() {
Expand Down Expand Up @@ -296,6 +298,12 @@ public final void onDismiss(@NonNull DialogInterface dialogInterface) {
super.onDismiss(dialogInterface);
}

@Override
public void setCancelable(boolean cancelable) {
super.setCancelable(cancelable);
updateCancelButtonVisibility();
}

private void updateInputMode(MaterialButton modeButton) {
if (activePresenter != null) {
activePresenter.hide();
Expand All @@ -309,6 +317,12 @@ private void updateInputMode(MaterialButton modeButton) {
modeButton.setContentDescription(getResources().getString(buttonData.second));
}

private void updateCancelButtonVisibility() {
if (cancelButton != null) {
cancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE);
}
}

private TimePickerPresenter initializeOrRetrieveActivePresenterForMode(int mode) {
if (mode == INPUT_MODE_CLOCK) {
timePickerClockPresenter =
Expand Down

0 comments on commit 35c2af3

Please sign in to comment.