|
@@ -1,29 +1,28 @@
|
|
|
package com.cooleshow.base.widgets
|
|
|
|
|
|
-import android.app.Dialog
|
|
|
import android.content.Context
|
|
|
-import android.graphics.drawable.AnimationDrawable
|
|
|
import android.view.Gravity
|
|
|
import android.widget.ImageView
|
|
|
import android.widget.TextView
|
|
|
+import com.airbnb.lottie.LottieAnimationView
|
|
|
import com.cooleshow.base.R
|
|
|
import com.cooleshow.base.utils.LogUtils
|
|
|
import com.cooleshow.base.utils.UiUtils
|
|
|
+import com.cooleshow.base.widgets.dialog.BaseFullDialog
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
|
import kotlinx.coroutines.launch
|
|
|
-import kotlinx.coroutines.withContext
|
|
|
|
|
|
/**
|
|
|
* 上传进度条
|
|
|
*/
|
|
|
class UploadProgressLoading private constructor(context: Context, theme: Int) :
|
|
|
- Dialog(context, theme) {
|
|
|
+ BaseFullDialog(context, theme) {
|
|
|
|
|
|
companion object {
|
|
|
private lateinit var mDialog: UploadProgressLoading
|
|
|
- private var animDrawable: AnimationDrawable? = null
|
|
|
private var tvProgress: TextView? = null;
|
|
|
+ private var mViewLoadingAnim: LottieAnimationView? = null
|
|
|
|
|
|
/*
|
|
|
创建加载对话框
|
|
@@ -39,16 +38,19 @@ class UploadProgressLoading private constructor(context: Context, theme: Int) :
|
|
|
mDialog.window?.attributes?.gravity = Gravity.CENTER
|
|
|
|
|
|
val lp = mDialog.window?.attributes
|
|
|
- lp?.dimAmount = 0.2f
|
|
|
+ lp?.dimAmount = 0.3f
|
|
|
//设置属性
|
|
|
mDialog.window?.attributes = lp
|
|
|
|
|
|
//获取动画视图
|
|
|
+ //获取动画视图
|
|
|
val loadingView = mDialog.findViewById<ImageView>(R.id.iv_loading)
|
|
|
|
|
|
tvProgress = mDialog.findViewById<TextView>(R.id.tv_progress)
|
|
|
-
|
|
|
- animDrawable = loadingView.background as AnimationDrawable
|
|
|
+ mViewLoadingAnim = mDialog.findViewById<LottieAnimationView>(R.id.view_loading_anim)
|
|
|
+ mViewLoadingAnim?.imageAssetsFolder = "lottie/refresh/images/"
|
|
|
+ mViewLoadingAnim?.setAnimation("lottie/refresh_anim.json")
|
|
|
+ mViewLoadingAnim?.loop(true)
|
|
|
|
|
|
return mDialog
|
|
|
}
|
|
@@ -78,7 +80,7 @@ class UploadProgressLoading private constructor(context: Context, theme: Int) :
|
|
|
fun showLoading() {
|
|
|
GlobalScope.launch(Dispatchers.Main) {
|
|
|
super.show()
|
|
|
- animDrawable?.start()
|
|
|
+ mViewLoadingAnim?.playAnimation()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -88,11 +90,14 @@ class UploadProgressLoading private constructor(context: Context, theme: Int) :
|
|
|
fun hideLoading() {
|
|
|
GlobalScope.launch(Dispatchers.Main) {
|
|
|
super.dismiss()
|
|
|
- animDrawable?.stop()
|
|
|
+ mViewLoadingAnim?.cancelAnimation()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
fun stopAnim() {
|
|
|
- animDrawable?.stop()
|
|
|
+ GlobalScope.launch(Dispatchers.Main) {
|
|
|
+ super.dismiss()
|
|
|
+ mViewLoadingAnim?.cancelAnimation()
|
|
|
+ }
|
|
|
}
|
|
|
}
|