From b9662e3aab0402eed93709400b151ff73eab5a9e Mon Sep 17 00:00:00 2001
From: leavesCZY <1990724437@qq.com>
Date: Thu, 7 Nov 2024 21:31:45 +0800
Subject: [PATCH] optimize code

---
 .github/workflows/create_release.yml          |  1 -
 .../leavesczy/compose_chat/MainApplication.kt |  2 +-
 .../leavesczy/compose_chat/utils/CoilUtils.kt | 27 ++++++++++++-------
 gradle/libs.versions.toml                     | 12 ++++-----
 4 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml
index ecca158..c70bc3b 100644
--- a/.github/workflows/create_release.yml
+++ b/.github/workflows/create_release.yml
@@ -40,7 +40,6 @@ jobs:
           allowUpdates: false
           generateReleaseNotes: false
           artifactErrorsFailBuild: true
-          body: "create by workflows"
           artifacts: "app/build/outputs/apk/release/*.apk"
           tag: ${{ steps.currentTime.outputs.formattedTime }}
           name: v${{ steps.currentTime.outputs.formattedTime }}
diff --git a/app/src/main/java/github/leavesczy/compose_chat/MainApplication.kt b/app/src/main/java/github/leavesczy/compose_chat/MainApplication.kt
index b7ca64f..c422b53 100644
--- a/app/src/main/java/github/leavesczy/compose_chat/MainApplication.kt
+++ b/app/src/main/java/github/leavesczy/compose_chat/MainApplication.kt
@@ -17,10 +17,10 @@ class MainApplication : Application() {
     override fun onCreate() {
         super.onCreate()
         ContextProvider.init(application = this)
-        CoilUtils.init(application = this)
         AppThemeProvider.init(application = this)
         AccountProvider.init(application = this)
         ComposeChat.accountProvider.init(application = this)
+        CoilUtils.init()
     }
 
 }
\ No newline at end of file
diff --git a/app/src/main/java/github/leavesczy/compose_chat/utils/CoilUtils.kt b/app/src/main/java/github/leavesczy/compose_chat/utils/CoilUtils.kt
index fff680d..98c10df 100644
--- a/app/src/main/java/github/leavesczy/compose_chat/utils/CoilUtils.kt
+++ b/app/src/main/java/github/leavesczy/compose_chat/utils/CoilUtils.kt
@@ -1,9 +1,11 @@
 package github.leavesczy.compose_chat.utils
 
 import android.content.Context
+import android.os.Build
 import coil3.ImageLoader
 import coil3.SingletonImageLoader
-import coil3.annotation.DelicateCoilApi
+import coil3.gif.AnimatedImageDecoder
+import coil3.gif.GifDecoder
 import coil3.imageLoader
 import coil3.request.ImageRequest
 import coil3.request.SuccessResult
@@ -20,14 +22,21 @@ import java.io.File
  */
 object CoilUtils {
 
-    @OptIn(DelicateCoilApi::class)
-    fun init(application: Context) {
-        val imageLoader = ImageLoader
-            .Builder(context = application)
-            .crossfade(enable = false)
-            .allowHardware(enable = true)
-            .build()
-        SingletonImageLoader.setUnsafe(imageLoader = imageLoader)
+    fun init() {
+        SingletonImageLoader.setSafe(factory = { context ->
+            ImageLoader
+                .Builder(context = context)
+                .crossfade(enable = false)
+                .allowHardware(enable = true)
+                .components {
+                    if (Build.VERSION.SDK_INT >= 28) {
+                        add(AnimatedImageDecoder.Factory())
+                    } else {
+                        add(GifDecoder.Factory())
+                    }
+                }
+                .build()
+        })
     }
 
     suspend fun getCachedFileOrDownload(context: Context, imageUrl: String): File? {
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index ad4b888..34aefb7 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -1,20 +1,20 @@
 [versions]
-android-plugin = "8.7.1"
-kotlin-plugin = "2.0.20"
+android-plugin = "8.7.2"
+kotlin-plugin = "2.0.21"
 track-plugin = "1.1.0"
 
 androidx-junit = "1.2.1"
 androidx-espresso = "3.6.1"
 androidx-appcompat = "1.7.0"
 androidx-activity = "1.9.3"
-androidx-lifecycle-viewmodel = "2.8.6"
+androidx-lifecycle-viewmodel = "2.8.7"
 androidx-exifinterface = "1.3.7"
-androidx-compose-bom = "2024.10.00"
+androidx-compose-bom = "2024.10.01"
 
 kotlinx-coroutines = "1.9.0"
 leavesczy-matisse = "2.1.2"
-tencent-imsdk = "8.2.6325"
-coil = "3.0.0-rc01"
+tencent-imsdk = "8.2.6333"
+coil = "3.0.1"
 junit = "4.13.2"
 
 [plugins]