mirror of https://github.com/M66B/FairEmail.git
Added loading show delay attribute
This commit is contained in:
parent
5761169f1f
commit
e1c8b3be17
|
@ -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;
|
||||
|
|
|
@ -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" />
|
||||
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue