Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
leavesCZY committed Nov 7, 2024
1 parent f93bc3c commit b9662e3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
1 change: 0 additions & 1 deletion .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

}
27 changes: 18 additions & 9 deletions app/src/main/java/github/leavesczy/compose_chat/utils/CoilUtils.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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? {
Expand Down
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down

0 comments on commit b9662e3

Please sign in to comment.