-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove progress dialogs #1280
Remove progress dialogs #1280
Changes from all commits
2fec554
d688455
4b363d4
863746e
ee7f6dd
526529c
704df98
a97a918
f24d3a7
23b5600
2a3dbc1
4d80006
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.firebase.ui.auth.ui; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.support.annotation.Nullable; | ||
import android.support.annotation.RestrictTo; | ||
import android.view.ContextThemeWrapper; | ||
import android.view.Gravity; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.FrameLayout; | ||
|
||
import com.firebase.ui.auth.R; | ||
|
||
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; | ||
|
||
/** | ||
* Base classes for activities that are just simple overlays. | ||
*/ | ||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
public class InvisibleActivityBase extends HelperActivityBase { | ||
|
||
// Minimum time that the spinner will stay on screen, once it is shown. | ||
private static final long MIN_SPINNER_MS = 750; | ||
|
||
private Handler mHandler = new Handler(); | ||
private MaterialProgressBar mProgressBar; | ||
|
||
// Last time that the progress bar was actually shown | ||
private long mLastShownTime = 0; | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.fui_activity_invisible); | ||
|
||
// Create an indeterminate, circular progress bar in the app's theme | ||
mProgressBar = new MaterialProgressBar(new ContextThemeWrapper(this, getFlowParams().themeId)); | ||
mProgressBar.setIndeterminate(true); | ||
mProgressBar.setVisibility(View.GONE); | ||
|
||
// Set bar to float in the center | ||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( | ||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); | ||
params.gravity = Gravity.CENTER; | ||
|
||
// Add to the container | ||
FrameLayout container = findViewById(R.id.invisible_frame); | ||
container.addView(mProgressBar, params); | ||
} | ||
|
||
@Override | ||
public void showProgress(int message) { | ||
if (mProgressBar.getVisibility() == View.VISIBLE) { | ||
mHandler.removeCallbacksAndMessages(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Glad to see you know that trick too! I've been burned so many times using |
||
return; | ||
} | ||
|
||
mLastShownTime = System.currentTimeMillis(); | ||
mProgressBar.setVisibility(View.VISIBLE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I'm wondering, what if we also had a really small (like 300ms) delay to show progress? Would that make the app feel faster? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So do you mean possibly avoid showing it at all for things that take under 300ms? Sounds like a great idea to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually since we are launching into a different activity here (which affects a lot of things underlying) it's better to show immediately. |
||
} | ||
|
||
@Override | ||
public void hideProgress() { | ||
doAfterTimeout(new Runnable() { | ||
@Override | ||
public void run() { | ||
mLastShownTime = 0; | ||
mProgressBar.setVisibility(View.GONE); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void finish(int resultCode, @Nullable Intent intent) { | ||
setResult(resultCode, intent); | ||
doAfterTimeout(new Runnable() { | ||
@Override | ||
public void run() { | ||
finish(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain your reasoning for waiting to finish? Since there's no text to read or anything like that, I feel like we should finish instantly. Or did that feel janky? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a comment. Basically sometimes we call |
||
} | ||
}); | ||
} | ||
|
||
/** | ||
* For certain actions (like finishing or hiding the progress dialog) we want to make sure | ||
* that we have shown the progress state for at least MIN_SPINNER_MS to prevent flickering. | ||
* | ||
* This method performs some action after the window has passed, or immediately if we have | ||
* already waited longer than that. | ||
*/ | ||
private void doAfterTimeout(Runnable runnable) { | ||
long currentTime = System.currentTimeMillis(); | ||
long diff = currentTime - mLastShownTime; | ||
|
||
// 'diff' is how long it's been since we showed the spinner, so in the | ||
// case where diff is greater than our minimum spinner duration then our | ||
// remaining wait time is 0. | ||
long remaining = Math.max(MIN_SPINNER_MS - diff, 0); | ||
|
||
mHandler.postDelayed(runnable, remaining); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ public ProgressDialogHolder(Context context) { | |
|
||
private void showLoadingDialog(String message) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we really can't kill this class yet? 😭 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now it just acts as a "fallback" implementation. If you were to add a new activity or fragment and not override the progress methods to do something special, it would use a dialog. Once phone auth is updated we can remove the base implementation, I think. |
||
dismissDialog(); | ||
|
||
if (mProgressDialog == null) { | ||
mProgressDialog = new ProgressDialog(mContext); | ||
mProgressDialog.setIndeterminate(true); | ||
|
@@ -34,10 +33,11 @@ public void showLoadingDialog(@StringRes int stringResource) { | |
} | ||
|
||
public void dismissDialog() { | ||
if (mProgressDialog != null) { | ||
if (isProgressDialogShowing()) { | ||
mProgressDialog.dismiss(); | ||
mProgressDialog = null; | ||
} | ||
|
||
mProgressDialog = null; | ||
} | ||
|
||
public boolean isProgressDialogShowing() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.firebase.ui.auth.ui; | ||
|
||
import android.support.annotation.RestrictTo; | ||
import android.support.annotation.StringRes; | ||
|
||
/** | ||
* View (Activity or Fragment, normally) that can respond to progress events. | ||
*/ | ||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
public interface ProgressView { | ||
|
||
void showProgress(@StringRes int message); | ||
|
||
void hideProgress(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,9 @@ | |
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.ProgressBar; | ||
import android.widget.TextView; | ||
|
||
import com.firebase.ui.auth.R; | ||
|
@@ -62,6 +64,9 @@ interface CheckEmailListener { | |
|
||
private CheckEmailHandler mHandler; | ||
|
||
private Button mNextButton; | ||
private ProgressBar mProgressBar; | ||
|
||
private EditText mEmailEditText; | ||
private TextInputLayout mEmailLayout; | ||
|
||
|
@@ -85,6 +90,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, | |
|
||
@Override | ||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | ||
mNextButton = view.findViewById(R.id.button_next); | ||
mProgressBar = view.findViewById(R.id.top_progress_bar); | ||
|
||
// Email field and validator | ||
mEmailLayout = view.findViewById(R.id.email_layout); | ||
mEmailEditText = view.findViewById(R.id.email); | ||
|
@@ -98,7 +106,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat | |
mEmailEditText.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO); | ||
} | ||
|
||
view.findViewById(R.id.button_next).setOnClickListener(this); | ||
mNextButton.setOnClickListener(this); | ||
|
||
TextView termsText = view.findViewById(R.id.email_tos_and_pp_text); | ||
TextView footerText = view.findViewById(R.id.email_footer_tos_and_pp_text); | ||
|
@@ -193,4 +201,16 @@ private void validateAndProceed() { | |
mHandler.fetchProvider(email); | ||
} | ||
} | ||
|
||
@Override | ||
public void showProgress(int message) { | ||
mNextButton.setEnabled(false); | ||
mProgressBar.setVisibility(View.VISIBLE); | ||
} | ||
|
||
@Override | ||
public void hideProgress() { | ||
mNextButton.setEnabled(true); | ||
mProgressBar.setVisibility(View.INVISIBLE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ | |
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.ProgressBar; | ||
import android.widget.TextView; | ||
|
||
import com.firebase.ui.auth.AuthUI; | ||
|
@@ -44,6 +46,9 @@ public class RegisterEmailFragment extends FragmentBase implements | |
|
||
private EmailProviderResponseHandler mHandler; | ||
|
||
private Button mNextButton; | ||
private ProgressBar mProgressBar; | ||
|
||
private EditText mEmailEditText; | ||
private EditText mNameEditText; | ||
private EditText mPasswordEditText; | ||
|
@@ -112,6 +117,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, | |
|
||
@Override | ||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | ||
mNextButton = view.findViewById(R.id.button_create); | ||
mProgressBar = view.findViewById(R.id.top_progress_bar); | ||
|
||
mEmailEditText = view.findViewById(R.id.email); | ||
mNameEditText = view.findViewById(R.id.name); | ||
mPasswordEditText = view.findViewById(R.id.password); | ||
|
@@ -137,7 +145,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat | |
mEmailEditText.setOnFocusChangeListener(this); | ||
mNameEditText.setOnFocusChangeListener(this); | ||
mPasswordEditText.setOnFocusChangeListener(this); | ||
view.findViewById(R.id.button_create).setOnClickListener(this); | ||
mNextButton.setOnClickListener(this); | ||
|
||
// Only show the name field if required | ||
nameInput.setVisibility(requireName ? View.VISIBLE : View.GONE); | ||
|
@@ -226,6 +234,18 @@ public void onDonePressed() { | |
validateAndRegisterUser(); | ||
} | ||
|
||
@Override | ||
public void showProgress(int message) { | ||
mNextButton.setEnabled(false); | ||
mProgressBar.setVisibility(View.VISIBLE); | ||
} | ||
|
||
@Override | ||
public void hideProgress() { | ||
mNextButton.setEnabled(true); | ||
mProgressBar.setVisibility(View.INVISIBLE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here |
||
} | ||
|
||
private void validateAndRegisterUser() { | ||
String email = mEmailEditText.getText().toString(); | ||
String password = mPasswordEditText.getText().toString(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we haven't gotten rid of all of progress dialogs yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think once you're done with Phone auth we can really kill the whole ProgressDialogHolder thing.