Fixed occasional invalid spinner

pull/147/head
M66B 6 years ago
parent 05d26cbc70
commit deff5c4a75

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

Loading…
Cancel
Save