ソースを参照

[feat]键盘插件,Ai生成列表的Loading,替换为Lottie动画,并修复Ai键盘的爱心加载动画,没有限制宽高的问题

hezihao 7 ヶ月 前
コミット
e8a6ee336b

ファイルの差分が大きいため隠しています
+ 1 - 0
plugins/keyboard_android/android/src/main/assets/lottie/anim_loading.json


+ 23 - 1
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/item/AiGenerateLoadingViewBinder.kt

@@ -4,6 +4,8 @@ import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import androidx.recyclerview.widget.RecyclerView
+import com.airbnb.lottie.LottieAnimationView
+import com.airbnb.lottie.LottieDrawable
 import com.atmob.keyboard_android.R
 import com.atmob.keyboard_android.model.AiGenerateLoadingModel
 import me.drakeet.multitype.ItemViewBinder
@@ -30,7 +32,27 @@ class AiGenerateLoadingViewBinder :
         holder: InnerViewBinder,
         item: AiGenerateLoadingModel
     ) {
+        playLottieAnimation(holder.vLoadingLottieView)
     }
 
-    inner class InnerViewBinder(itemView: View) : RecyclerView.ViewHolder(itemView)
+    /**
+     * 播放Lottie动画
+     */
+    private fun playLottieAnimation(animationView: LottieAnimationView) {
+        animationView.setAnimation("lottie/anim_loading.json")
+        animationView.repeatCount = LottieDrawable.INFINITE
+        animationView.playAnimation()
+    }
+
+    /**
+     * 停止Lottie动画
+     */
+    private fun stopLottieAnimation(animationView: LottieAnimationView) {
+        animationView.cancelAnimation()
+    }
+
+    inner class InnerViewBinder(itemView: View) : RecyclerView.ViewHolder(itemView) {
+        var vLoadingLottieView: LottieAnimationView =
+            itemView.findViewById(R.id.loading_lottie_view)
+    }
 }

+ 6 - 6
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/item/AiKeyboardKeyViewBinder.kt

@@ -34,18 +34,18 @@ class AiKeyboardKeyViewBinder(
     ) {
         // 加载中,显示Loading,隐藏文字
         if (item.isLoading) {
-            holder.vLoadingLottieView.setVisible()
+            holder.vLoveFlyLoadingLottieView.setVisible()
             holder.vKeyText.setGone()
-            playLottieAnimation(holder.vLoadingLottieView)
+            playLottieAnimation(holder.vLoveFlyLoadingLottieView)
         } else {
             // 隐藏Loading,显示文字
-            holder.vLoadingLottieView.setGone()
+            holder.vLoveFlyLoadingLottieView.setGone()
             holder.vKeyText.setVisible()
             // 文字
             holder.vKeyText.apply {
                 text = item.text
             }
-            stopLottieAnimation(holder.vLoadingLottieView)
+            stopLottieAnimation(holder.vLoveFlyLoadingLottieView)
         }
         holder.itemView.click {
             onItemClick.invoke(item)
@@ -70,7 +70,7 @@ class AiKeyboardKeyViewBinder(
 
     inner class InnerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
         val vKeyText: TextView = itemView.findViewById(R.id.key_text)
-        val vLoadingLottieView: LottieAnimationView =
-            itemView.findViewById(R.id.loading_lottie_view)
+        val vLoveFlyLoadingLottieView: LottieAnimationView =
+            itemView.findViewById(R.id.love_fly_loading_lottie_view)
     }
 }

+ 10 - 4
plugins/keyboard_android/android/src/main/res/layout/dialog_loading.xml

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <FrameLayout 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"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
@@ -12,9 +13,14 @@
         android:gravity="center"
         android:orientation="vertical">
 
-        <ProgressBar
-            android:layout_width="48dp"
-            android:layout_height="48dp"
-            android:indeterminate="true" />
+        <com.airbnb.lottie.LottieAnimationView
+            android:id="@+id/loading_lottie_view"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:visibility="visible"
+            app:lottie_autoPlay="true"
+            app:lottie_fileName="lottie/anim_loading.json"
+            app:lottie_loop="true" />
     </LinearLayout>
 </FrameLayout>

+ 8 - 2
plugins/keyboard_android/android/src/main/res/layout/item_ai_generate_loading.xml

@@ -1,5 +1,6 @@
 <?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"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">
@@ -12,12 +13,17 @@
         android:paddingTop="8dp"
         android:paddingBottom="8dp">
 
-        <ImageView
+        <com.airbnb.lottie.LottieAnimationView
+            android:id="@+id/loading_lottie_view"
             android:layout_width="14dp"
             android:layout_height="14dp"
+            android:layout_gravity="center"
             android:layout_marginStart="10dp"
             android:layout_marginEnd="8dp"
-            android:src="@mipmap/ic_loading" />
+            android:visibility="visible"
+            app:lottie_autoPlay="true"
+            app:lottie_fileName="lottie/anim_loading.json"
+            app:lottie_loop="true" />
 
         <TextView
             android:layout_width="wrap_content"

+ 3 - 3
plugins/keyboard_android/android/src/main/res/layout/item_ai_keyboard_key.xml

@@ -21,9 +21,9 @@
         tools:text="哄女友" />
 
     <com.airbnb.lottie.LottieAnimationView
-        android:id="@+id/loading_lottie_view"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
+        android:id="@+id/love_fly_loading_lottie_view"
+        android:layout_width="40dp"
+        android:layout_height="40dp"
         android:layout_gravity="center"
         android:visibility="gone"
         app:lottie_autoPlay="true"