[Network Connection] Implement Unavailable callback when the user cancels
UI should invoke NetworkRequestUserSelectionCallback.reject() callback when the user clicks cancel. Bug: 128876386 Test: atest NetworkRequestDialogFragment Change-Id: Ia5faedf8cc7113a602a4cda10b3252d02c3c8876
This commit is contained in:
@@ -124,7 +124,7 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
|
|||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||||
.setCustomTitle(customTitle)
|
.setCustomTitle(customTitle)
|
||||||
.setAdapter(mDialogAdapter, this)
|
.setAdapter(mDialogAdapter, this)
|
||||||
.setNegativeButton(R.string.cancel, (dialog, which) -> getActivity().finish())
|
.setNegativeButton(R.string.cancel, (dialog, which) -> onCancel(dialog))
|
||||||
// Do nothings, will replace the onClickListener to avoid auto closing dialog.
|
// Do nothings, will replace the onClickListener to avoid auto closing dialog.
|
||||||
.setNeutralButton(R.string.network_connection_request_dialog_showall,
|
.setNeutralButton(R.string.network_connection_request_dialog_showall,
|
||||||
null /* OnClickListener */);
|
null /* OnClickListener */);
|
||||||
@@ -221,6 +221,9 @@ public class NetworkRequestDialogFragment extends InstrumentedDialogFragment imp
|
|||||||
if (getActivity() != null) {
|
if (getActivity() != null) {
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
}
|
}
|
||||||
|
if (mUserSelectionCallback != null) {
|
||||||
|
mUserSelectionCallback.reject();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -330,4 +330,21 @@ public class NetworkRequestDialogFragmentTest {
|
|||||||
// Check
|
// Check
|
||||||
assertThat(button.getVisibility()).isEqualTo(View.GONE);
|
assertThat(button.getVisibility()).isEqualTo(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cancelDialog_callsReject() {
|
||||||
|
// Assert
|
||||||
|
networkRequestDialogFragment.show(mActivity.getSupportFragmentManager(), /* tag */ null);
|
||||||
|
final AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
final NetworkRequestUserSelectionCallback selectionCallback = mock(
|
||||||
|
NetworkRequestUserSelectionCallback.class);
|
||||||
|
networkRequestDialogFragment.onUserSelectionCallbackRegistration(selectionCallback);
|
||||||
|
|
||||||
|
// Action
|
||||||
|
final Button button = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
|
||||||
|
button.performClick();
|
||||||
|
|
||||||
|
// Check
|
||||||
|
verify(selectionCallback, times(1)).reject();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user