Commit 6c58549c authored by dfalcantara's avatar dfalcantara Committed by Commit bot

[Download Home] Deal with the infinite spinny

Because of timing delays, and because cancelling a Runnable doesn't
guarantee that it won't run, the LoadingView can get into a state
where it posts a task to animate itself showing up on screen but it
doesn't re-check if it still needs to be visible.

BUG=641262

Review-Url: https://codereview.chromium.org/2319213004
Cr-Commit-Position: refs/heads/master@{#417417}
parent 0ad8e815
......@@ -26,12 +26,20 @@ public class LoadingView extends ProgressBar {
private final Runnable mDelayedShow = new Runnable() {
@Override
public void run() {
if (!mShouldShow) return;
mStartTime = SystemClock.elapsedRealtime();
setVisibility(View.VISIBLE);
setAlpha(1.0f);
}
};
/**
* Tracks whether the View should be displayed when {@link #mDelayedShow} is run. Android
* doesn't always cancel a Runnable when requested, meaning that the View could be hidden before
* it even has a chance to be shown.
*/
private boolean mShouldShow;
// Material loading design spec requires us to show progress spinner at least 500ms, so we need
// this delayed runnable to implement that.
private final Runnable mDelayedHide = new Runnable() {
......@@ -67,6 +75,7 @@ public class LoadingView extends ProgressBar {
public void showLoadingUI() {
removeCallbacks(mDelayedShow);
removeCallbacks(mDelayedHide);
mShouldShow = true;
setVisibility(GONE);
postDelayed(mDelayedShow, LOADING_ANIMATION_DELAY_MS);
......@@ -79,6 +88,7 @@ public class LoadingView extends ProgressBar {
public void hideLoadingUI() {
removeCallbacks(mDelayedShow);
removeCallbacks(mDelayedHide);
mShouldShow = false;
if (getVisibility() == VISIBLE) {
postDelayed(mDelayedHide, Math.max(0,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment