Visibility delaying

pull/184/head
M66B 4 years ago
parent 0221816e21
commit 33c00d0c9b

@ -27,7 +27,8 @@ 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 int visibility = VISIBLE;
private boolean delaying = false;
private static final int VISIBILITY_DELAY = 500; // milliseconds private static final int VISIBILITY_DELAY = 500; // milliseconds
@ -51,12 +52,16 @@ public class ContentLoadingProgressBar extends ProgressBar {
public void setVisibility(int visibility) { public void setVisibility(int visibility) {
this.visibility = visibility; this.visibility = visibility;
ApplicationEx.getMainHandler().removeCallbacks(delayedShow);
if (visibility == VISIBLE) { if (visibility == VISIBLE) {
if (delaying)
return;
delaying = true;
super.setVisibility(INVISIBLE); super.setVisibility(INVISIBLE);
ApplicationEx.getMainHandler().postDelayed(delayedShow, VISIBILITY_DELAY); ApplicationEx.getMainHandler().postDelayed(delayedShow, VISIBILITY_DELAY);
} else } else {
ApplicationEx.getMainHandler().removeCallbacks(delayedShow);
super.setVisibility(visibility); super.setVisibility(visibility);
}
} }
@Override @Override
@ -67,6 +72,7 @@ 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() {
delaying = false;
if (visibility == VISIBLE) if (visibility == VISIBLE)
ContentLoadingProgressBar.super.setVisibility(VISIBLE); ContentLoadingProgressBar.super.setVisibility(VISIBLE);
} }

@ -27,7 +27,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView; import androidx.appcompat.widget.AppCompatTextView;
public class ViewTextDelayed extends AppCompatTextView { public class ViewTextDelayed extends AppCompatTextView {
private int visibility; private int visibility = VISIBLE;
private static final int VISIBILITY_DELAY = 500; // milliseconds private static final int VISIBILITY_DELAY = 500; // milliseconds
@ -47,13 +47,13 @@ public class ViewTextDelayed extends AppCompatTextView {
public void setVisibility(int visibility) { public void setVisibility(int visibility) {
this.visibility = visibility; this.visibility = visibility;
removeCallbacks(delayedShow); ApplicationEx.getMainHandler().removeCallbacks(delayedShow);
removeCallbacks(delayedHide); ApplicationEx.getMainHandler().removeCallbacks(delayedHide);
if (visibility == VISIBLE) if (visibility == VISIBLE)
postDelayed(delayedShow, VISIBILITY_DELAY); ApplicationEx.getMainHandler().postDelayed(delayedShow, VISIBILITY_DELAY);
else if (visibility == GONE) else if (visibility == GONE)
postDelayed(delayedHide, VISIBILITY_DELAY); ApplicationEx.getMainHandler().postDelayed(delayedHide, VISIBILITY_DELAY);
else else
super.setVisibility(visibility); super.setVisibility(visibility);
} }

Loading…
Cancel
Save