|
|
@@ -53,6 +53,8 @@ public class Loading {
|
|
|
* @return
|
|
|
*/
|
|
|
public Loading show() {
|
|
|
+ create();
|
|
|
+
|
|
|
if (delayMs > 0) {
|
|
|
disposable = Completable.timer(delayMs, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
|
|
|
.subscribe(this::showInternal);
|
|
|
@@ -63,17 +65,22 @@ public class Loading {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- private void showInternal() {
|
|
|
+ private void create() {
|
|
|
if (null == view) {
|
|
|
FrameLayout frameLayout = activity.findViewById(android.R.id.content);
|
|
|
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
view = inflater.inflate(R.layout.dialog_loading, null);
|
|
|
view.setClickable(true);
|
|
|
+ view.setAlpha(0f);
|
|
|
+ frameLayout.addView(view);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ private void showInternal() {
|
|
|
+ if (null != view) {
|
|
|
+ view.setAlpha(1f);
|
|
|
ImageView imageView = view.findViewById(R.id.image_loading);
|
|
|
animation = new FrameAnimation.Builder(imageView, R.array.loading_animation, 50).repeat(true).build();
|
|
|
-
|
|
|
- frameLayout.addView(view);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -86,11 +93,14 @@ public class Loading {
|
|
|
disposable = null;
|
|
|
}
|
|
|
if (null != view) {
|
|
|
- animation.stopAnimation();
|
|
|
FrameLayout frameLayout = activity.findViewById(android.R.id.content);
|
|
|
frameLayout.removeView(view);
|
|
|
view = null;
|
|
|
activity = null;
|
|
|
}
|
|
|
+ if (null != animation) {
|
|
|
+ animation.stopAnimation();
|
|
|
+ animation = null;
|
|
|
+ }
|
|
|
}
|
|
|
}
|