-
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 8 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,90 @@ | ||
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 android.widget.ProgressBar; | ||
|
||
import com.firebase.ui.auth.R; | ||
|
||
|
||
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. Nit: extra new line |
||
/** | ||
* Base classes for activities that are just simple overlays. | ||
*/ | ||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
public class InvisibleActivityBase extends HelperActivityBase { | ||
|
||
private static final long MIN_SPINNER_MS = 1000; | ||
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. Ooof, this seems like a long time. How about 500ms or even 750? 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. Moved to 750. You'd be surprised how "flickery" 500 feels. |
||
|
||
private Handler mHandler = new Handler(); | ||
private ProgressBar mProgressBar; | ||
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 ProgressBar(new ContextThemeWrapper(this, getFlowParams().themeId)); | ||
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. Shouldn't we use the material library version to get sexiness pre-L? (And consistent behavior in general.) |
||
mProgressBar.setIndeterminate(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. Why are we using |
||
|
||
// 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.INVISIBLE); | ||
} | ||
}); | ||
} | ||
|
||
@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 |
||
} | ||
}); | ||
} | ||
|
||
private void doAfterTimeout(Runnable runnable) { | ||
long currentTime = System.currentTimeMillis(); | ||
long diff = currentTime - mLastShownTime; | ||
long remaining = Math.max(MIN_SPINNER_MS - diff, 0); | ||
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 we maybe add a comment saying we want at least 0 and the diff can be really big? I was confused as to why we needed |
||
|
||
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 com.firebase.ui.auth.R; | ||
import com.firebase.ui.auth.data.model.User; | ||
|
@@ -59,6 +61,9 @@ interface CheckEmailListener { | |
|
||
private CheckEmailHandler mHandler; | ||
|
||
private Button mNextButton; | ||
private ProgressBar mProgressBar; | ||
|
||
private EditText mEmailEditText; | ||
private TextInputLayout mEmailLayout; | ||
|
||
|
@@ -82,6 +87,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); | ||
|
@@ -95,7 +103,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); | ||
} | ||
|
||
@Override | ||
|
@@ -175,4 +183,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; | ||
|
@@ -110,6 +115,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); | ||
|
@@ -135,7 +143,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); | ||
|
@@ -223,6 +231,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.