From e8de7a876ec7b8a80e1e2d4957864d7d7651a859 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 21 Aug 2020 16:08:31 +0200 Subject: [PATCH] Workaround AndroidX bug --- .../email/ContentLoadingProgressBar.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ContentLoadingProgressBar.java b/app/src/main/java/eu/faircode/email/ContentLoadingProgressBar.java index dfa67512f9..e89b34d7be 100644 --- a/app/src/main/java/eu/faircode/email/ContentLoadingProgressBar.java +++ b/app/src/main/java/eu/faircode/email/ContentLoadingProgressBar.java @@ -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); }