Skip to content

Commit 888213c

Browse files
authored
Fix dialog NPE and IllegalStateExceptions by guarding (#927)
1 parent 6a32081 commit 888213c

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

auth/src/main/java/com/firebase/ui/auth/ui/phone/CompletableProgressDialog.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,23 @@ public final class CompletableProgressDialog extends DialogFragment {
3838

3939
public static CompletableProgressDialog show(FragmentManager manager) {
4040
CompletableProgressDialog dialog = new CompletableProgressDialog();
41-
dialog.show(manager, TAG);
41+
dialog.showAllowingStateLoss(manager, TAG);
4242
return dialog;
4343
}
4444

45+
/**
46+
* This method is adapted from {@link #show(FragmentManager, String)}
47+
*/
48+
public void showAllowingStateLoss(FragmentManager manager, String tag) {
49+
// This prevents us from hitting FragmentManager.checkStateLoss() which
50+
// throws a runtime exception if state has already been saved.
51+
if (manager.isStateSaved()) {
52+
return;
53+
}
54+
55+
show(manager, tag);
56+
}
57+
4558
@NonNull
4659
@Override
4760
public Dialog onCreateDialog(Bundle savedInstanceState) {
@@ -60,12 +73,18 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
6073

6174
public void onComplete(String msg) {
6275
setMessage(msg);
63-
mProgress.setVisibility(View.GONE);
64-
mSuccessImage.setVisibility(View.VISIBLE);
76+
77+
if (mProgress != null) {
78+
mProgress.setVisibility(View.GONE);
79+
}
80+
81+
if (mSuccessImage != null) {
82+
mSuccessImage.setVisibility(View.VISIBLE);
83+
}
6584
}
6685

6786
public void setMessage(CharSequence message) {
68-
if (mProgress != null) {
87+
if (mProgress != null && mMessageView != null) {
6988
mMessageView.setText(message);
7089
} else {
7190
mMessage = message;

0 commit comments

Comments
 (0)