|
|
@@ -10,6 +10,11 @@ import android.view.View;
|
|
|
import android.widget.FrameLayout;
|
|
|
import android.widget.ImageView;
|
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+import io.reactivex.Completable;
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.disposables.Disposable;
|
|
|
import kr.co.zumo.app.R;
|
|
|
import kr.co.zumo.app.lifeplus.view.FrameAnimation;
|
|
|
|
|
|
@@ -28,12 +33,19 @@ public class Loading {
|
|
|
private Activity activity;
|
|
|
private View view;
|
|
|
private FrameAnimation animation;
|
|
|
+ private int delayMs = 0;
|
|
|
+ private Disposable disposable;
|
|
|
|
|
|
|
|
|
public Loading(Activity context) {
|
|
|
this.activity = context;
|
|
|
}
|
|
|
|
|
|
+ public Loading(Activity activity, int delayMs) {
|
|
|
+ this.activity = activity;
|
|
|
+ this.delayMs = delayMs;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Waiter 표시
|
|
|
* - android.R.id.content 최상위에 표시한다.
|
|
|
@@ -41,6 +53,17 @@ public class Loading {
|
|
|
* @return
|
|
|
*/
|
|
|
public Loading show() {
|
|
|
+ if (delayMs > 0) {
|
|
|
+ disposable = Completable.timer(delayMs, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(this::showInternal);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ showInternal();
|
|
|
+ }
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showInternal() {
|
|
|
if (null == view) {
|
|
|
FrameLayout frameLayout = activity.findViewById(android.R.id.content);
|
|
|
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
@@ -52,13 +75,16 @@ public class Loading {
|
|
|
|
|
|
frameLayout.addView(view);
|
|
|
}
|
|
|
- return this;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* hide
|
|
|
*/
|
|
|
public void hide() {
|
|
|
+ if (null != disposable) {
|
|
|
+ disposable.dispose();
|
|
|
+ disposable = null;
|
|
|
+ }
|
|
|
if (null != view) {
|
|
|
animation.stopAnimation();
|
|
|
FrameLayout frameLayout = activity.findViewById(android.R.id.content);
|