فهرست منبع

修改全局loading样式

Pq 7 ماه پیش
والد
کامیت
19c12abd00

+ 16 - 8
BaseLibrary/src/main/java/com/cooleshow/base/widgets/ProgressLoading2.java

@@ -10,6 +10,7 @@ import android.view.WindowManager;
 import android.widget.ImageView;
 import android.widget.TextView;
 
+import com.airbnb.lottie.LottieAnimationView;
 import com.cooleshow.base.R;
 import com.cooleshow.base.widgets.dialog.BaseFullDialog;
 
@@ -22,7 +23,7 @@ public class ProgressLoading2 extends BaseFullDialog {
 
     private ImageView mImageView;
     private TextView mTvLoadingText;
-    private AnimationDrawable animDrawable;
+    private LottieAnimationView mViewLoadingAnim;
 
     public ProgressLoading2(@NonNull Context context) {
         super(context, R.style.LightProgressDialog);
@@ -40,20 +41,27 @@ public class ProgressLoading2 extends BaseFullDialog {
         getWindow().setAttributes(attributes);
         mImageView = findViewById(R.id.iv_loading);
         mTvLoadingText = findViewById(R.id.tv_loading_text);
-        animDrawable = (AnimationDrawable) mImageView.getBackground();
+        mViewLoadingAnim = findViewById(R.id.view_loading_anim);
+        mViewLoadingAnim.setImageAssetsFolder("lottie/refresh/images/");
+        mViewLoadingAnim.setAnimation("lottie/refresh_anim.json");
+        mViewLoadingAnim.loop(true);
     }
 
     public void showLoading() {
         super.show();
-        if (animDrawable != null) {
-            animDrawable.start();
+        if (mViewLoadingAnim != null) {
+            mViewLoadingAnim.playAnimation();
+        }
+        if (mTvLoadingText != null) {
+            mTvLoadingText.setText("加载中");
+            mTvLoadingText.setVisibility(View.VISIBLE);
         }
     }
 
     public void showLoading(String text) {
         super.show();
-        if (animDrawable != null) {
-            animDrawable.start();
+        if (mViewLoadingAnim != null) {
+            mViewLoadingAnim.playAnimation();
         }
         if (mTvLoadingText != null) {
             mTvLoadingText.setText(text);
@@ -74,8 +82,8 @@ public class ProgressLoading2 extends BaseFullDialog {
     }
 
     public void stopAnim() {
-        if (animDrawable != null) {
-            animDrawable.stop();
+        if (mViewLoadingAnim != null) {
+            mViewLoadingAnim.cancelAnimation();
         }
     }
 }

+ 16 - 11
BaseLibrary/src/main/java/com/cooleshow/base/widgets/UploadProgressLoading.kt

@@ -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()
+        }
     }
 }

+ 26 - 7
BaseLibrary/src/main/res/layout/progress_dialog.xml

@@ -1,24 +1,43 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
     style="@style/WrapWrap.Vertical"
-    android:padding="40dp"
-    android:background="@drawable/progress_dialog_bg"
-    android:gravity="center_horizontal">
+    android:layout_width="100dp"
+    android:minHeight="100dp"
+    android:paddingTop="12dp"
+    android:paddingBottom="12dp"
+    android:layout_height="wrap_content"
+    android:background="@drawable/bg_white_10dp"
+    android:gravity="center">
 
     <ImageView
+        android:visibility="gone"
         android:id="@+id/iv_loading"
         style="@style/WrapWrap"
         android:layout_gravity="center"
         android:background="@drawable/progress_dialog_anim" />
 
+    <com.airbnb.lottie.LottieAnimationView
+        android:id="@+id/view_loading_anim"
+        android:layout_width="wrap_content"
+        android:layout_height="47dp"
+        android:layout_gravity="center"
+        app:lottie_autoPlay="false"
+        app:lottie_imageAssetsFolder="lottie/refresh/images/"
+        app:lottie_loop="true" />
+
+
     <TextView
         android:layout_marginTop="5dp"
         android:layout_gravity="center_horizontal|bottom"
         android:id="@+id/tv_loading_text"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:text="加载中..."
-        android:textColor="@color/white"
-        android:textSize="@dimen/sp_13"
-        android:visibility="gone" />
+        android:text="加载中"
+        tools:text="加载中"
+        android:gravity="center"
+        android:textColor="@color/color_333333"
+        android:textSize="@dimen/sp_12"
+        android:visibility="visible" />
 </LinearLayout>

+ 17 - 12
BaseLibrary/src/main/res/layout/upload_progress_dialog.xml

@@ -1,23 +1,28 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     style="@style/WrapWrap.Vertical"
     android:layout_width="100dp"
     android:layout_height="wrap_content"
-    android:background="@drawable/progress_dialog_bg"
-    android:gravity="center_horizontal"
-    android:paddingTop="20dp"
-    android:paddingBottom="20dp">
+    android:minHeight="100dp"
+    android:paddingBottom="12dp"
+    android:paddingTop="12dp"
+    android:background="@drawable/bg_white_10dp"
+    android:gravity="center">
 
-    <ImageView
-        android:id="@+id/iv_loading"
-        style="@style/WrapWrap"
+    <com.airbnb.lottie.LottieAnimationView
+        android:id="@+id/view_loading_anim"
+        android:layout_width="wrap_content"
+        android:layout_height="47dp"
         android:layout_gravity="center"
-        android:background="@drawable/progress_dialog_anim" />
+        app:lottie_autoPlay="false"
+        app:lottie_imageAssetsFolder="lottie/refresh/images/"
+        app:lottie_loop="true" />
 
     <TextView
         android:id="@+id/tv_progress"
-        android:layout_width="wrap_content"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="10dp"
         android:gravity="center"
@@ -25,7 +30,7 @@
         android:text="0%"
         android:paddingStart="10dp"
         android:paddingEnd="10dp"
-        tools:text="封面上传中99.00%"
-        android:textColor="@color/white"
-        android:textSize="@dimen/sp_16" />
+        tools:text="上传中上传中99.00%"
+        android:textColor="@color/color_333333"
+        android:textSize="@dimen/sp_12" />
 </LinearLayout>