Workaround AndroidX bug

This commit is contained in:
M66B 2020-08-21 16:08:31 +02:00
parent 69c3fd691c
commit e8de7a876e
1 changed files with 21 additions and 2 deletions

View File

@ -20,6 +20,8 @@ package eu.faircode.email;
*/
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.widget.ProgressBar;
@ -28,25 +30,42 @@ import androidx.annotation.Nullable;
public class ContentLoadingProgressBar extends ProgressBar {
private int visibility;
private Handler handler;
private static final int VISIBILITY_DELAY = 500; // milliseconds
public ContentLoadingProgressBar(@NonNull Context context) {
this(context, null);
init();
}
public ContentLoadingProgressBar(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs, 0);
init();
}
public ContentLoadingProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
public ContentLoadingProgressBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
handler = new Handler(Looper.getMainLooper());
}
@Override
public void setVisibility(int visibility) {
this.visibility = visibility;
removeCallbacks(delayedShow);
handler.removeCallbacks(delayedShow);
if (visibility == VISIBLE) {
super.setVisibility(INVISIBLE);
postDelayed(delayedShow, VISIBILITY_DELAY);
handler.postDelayed(delayedShow, VISIBILITY_DELAY);
} else
super.setVisibility(visibility);
}