From e1c8b3be171014c256337e8264b5b61aca043fd0 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 8 May 2021 09:25:29 +0200 Subject: [PATCH] Added loading show delay attribute --- .../eu/faircode/email/ContentLoadingProgressBar.java | 12 +++++++++++- .../main/res/layout/include_message_navigation.xml | 1 + app/src/main/res/values/attrs.xml | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/values/attrs.xml diff --git a/app/src/main/java/eu/faircode/email/ContentLoadingProgressBar.java b/app/src/main/java/eu/faircode/email/ContentLoadingProgressBar.java index 01e5358c3b..864cb9ca02 100644 --- a/app/src/main/java/eu/faircode/email/ContentLoadingProgressBar.java +++ b/app/src/main/java/eu/faircode/email/ContentLoadingProgressBar.java @@ -20,6 +20,7 @@ package eu.faircode.email; */ import android.content.Context; +import android.content.res.TypedArray; import android.util.AttributeSet; import android.widget.ProgressBar; @@ -29,6 +30,7 @@ import androidx.annotation.Nullable; public class ContentLoadingProgressBar extends ProgressBar { private int visibility = VISIBLE; private boolean init = false; + private int delay = VISIBILITY_DELAY; private boolean delaying = false; private static final int VISIBILITY_DELAY = 1500; // milliseconds @@ -39,14 +41,22 @@ public class ContentLoadingProgressBar extends ProgressBar { public ContentLoadingProgressBar(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs, 0); + getAttr(context, attrs); } public ContentLoadingProgressBar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + getAttr(context, attrs); } public ContentLoadingProgressBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); + getAttr(context, attrs); + } + + private void getAttr(Context context, AttributeSet attrs) { + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ContentLoadingProgressBar, 0, 0); + this.delay = a.getInt(R.styleable.ContentLoadingProgressBar_show_delay, VISIBILITY_DELAY); } @Override @@ -59,7 +69,7 @@ public class ContentLoadingProgressBar extends ProgressBar { init = true; delaying = true; super.setVisibility(INVISIBLE); - ApplicationEx.getMainHandler().postDelayed(delayedShow, VISIBILITY_DELAY); + ApplicationEx.getMainHandler().postDelayed(delayedShow, delay); } else { ApplicationEx.getMainHandler().removeCallbacks(delayedShow); delaying = false; diff --git a/app/src/main/res/layout/include_message_navigation.xml b/app/src/main/res/layout/include_message_navigation.xml index 3881eeac22..a2c8c927e5 100644 --- a/app/src/main/res/layout/include_message_navigation.xml +++ b/app/src/main/res/layout/include_message_navigation.xml @@ -20,6 +20,7 @@ android:layout_width="36dp" android:layout_height="36dp" android:indeterminate="true" + app:show_delay="750" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/vSeparator" /> diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml new file mode 100644 index 0000000000..bf648727fb --- /dev/null +++ b/app/src/main/res/values/attrs.xml @@ -0,0 +1,6 @@ + + + + + +