Added loading show delay attribute

This commit is contained in:
M66B 2021-05-08 09:25:29 +02:00
parent 5761169f1f
commit e1c8b3be17
3 changed files with 18 additions and 1 deletions

View File

@ -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;

View File

@ -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" />

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ContentLoadingProgressBar">
<attr name="show_delay" format="integer" />
</declare-styleable>
</resources>