Fixed occasional invalid spinner

This commit is contained in:
M66B 2019-02-11 11:06:53 +00:00
parent 05d26cbc70
commit deff5c4a75
1 changed files with 8 additions and 2 deletions

View File

@ -27,6 +27,10 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class ContentLoadingProgressBar extends ProgressBar {
private int visibility;
private static final int VISIBILITY_DELAY = 500; // milliseconds
public ContentLoadingProgressBar(@NonNull Context context) {
this(context, null);
}
@ -37,6 +41,7 @@ public class ContentLoadingProgressBar extends ProgressBar {
@Override
public void setVisibility(int visibility) {
this.visibility = visibility;
if (false && BuildConfig.DEBUG) {
super.setVisibility(visibility);
return;
@ -44,7 +49,7 @@ public class ContentLoadingProgressBar extends ProgressBar {
removeCallbacks(delayedShow);
if (visibility == VISIBLE) {
super.setVisibility(INVISIBLE);
postDelayed(delayedShow, 500);
postDelayed(delayedShow, VISIBILITY_DELAY);
} else
super.setVisibility(visibility);
}
@ -52,7 +57,8 @@ public class ContentLoadingProgressBar extends ProgressBar {
private final Runnable delayedShow = new Runnable() {
@Override
public void run() {
ContentLoadingProgressBar.super.setVisibility(VISIBLE);
if (visibility == VISIBLE)
ContentLoadingProgressBar.super.setVisibility(VISIBLE);
}
};
}