diff --git a/app/build.gradle.kts b/app/build.gradle.kts index cefe5c8..1c37cb9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -54,6 +54,4 @@ dependencies { implementation(project(":coilimageloader")) implementation(project(":PhotoViewImageViewLoader")) - debugImplementation("io.github.didi.dokit:dokitx:3.5.0-beta01") - releaseImplementation("io.github.didi.dokit:dokitx-no-op:3.5.0-beta01") } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f866370..0d23aa6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,7 +22,8 @@ android:theme="@style/AppTheme" android:usesCleartextTraffic="true" android:requestLegacyExternalStorage="true"> - + diff --git a/app/src/main/java/net/mikaelzero/app/MainActivity.kt b/app/src/main/java/net/mikaelzero/app/MainActivity.kt index 0861503..e50929a 100644 --- a/app/src/main/java/net/mikaelzero/app/MainActivity.kt +++ b/app/src/main/java/net/mikaelzero/app/MainActivity.kt @@ -140,8 +140,7 @@ class MainActivity : AppCompatActivity() { } } binding.cacheBt.setOnClickListener { - imageLoader.memoryCache.clear() - CoilUtils.createDefaultCache(this).directory.delete() + imageLoader.memoryCache?.clear() CoilImageLoader.with(applicationContext).cleanCache() Glide.get(this).clearMemory() Thread { Glide.get(this).clearDiskCache() }.start() diff --git a/buildSrc/src/main/kotlin/Library.kt b/buildSrc/src/main/kotlin/Library.kt index 8816b78..bfe6ddb 100644 --- a/buildSrc/src/main/kotlin/Library.kt +++ b/buildSrc/src/main/kotlin/Library.kt @@ -50,7 +50,7 @@ object Library { const val ART_PLAY_CORE = "org.salient.artvideoplayer:artplayer-core:1.1.0" const val ART_PLAY_IJK = "org.salient.artvideoplayer:artplayer-ijk:1.1.0" const val ART_PLAY_V7A = "org.salient.artvideoplayer:artplayer-armv7a:1.1.0" - const val COIL = "io.coil-kt:coil:1.3.0" + const val COIL = "io.coil-kt:coil:2.1.0" // TEST diff --git a/coilimageloader/build.gradle.kts b/coilimageloader/build.gradle.kts index 003e8f3..ad78a1e 100644 --- a/coilimageloader/build.gradle.kts +++ b/coilimageloader/build.gradle.kts @@ -18,8 +18,9 @@ dependencies { implementation(mojito.Library.ANDROIDX_APPCOMPAT) implementation(mojito.Library.ANDROIDX_CORE) implementation(mojito.Library.OKHTTP) - implementation("io.coil-kt:coil-base:1.3.0") - implementation("io.coil-kt:coil-gif:1.3.0") - implementation("io.coil-kt:coil-svg:1.3.0") + implementation(mojito.Library.COIL) + implementation("io.coil-kt:coil-base:2.1.0") + implementation("io.coil-kt:coil-gif:2.1.0") + implementation("io.coil-kt:coil-svg:2.1.0") implementation(project(":mojito")) } diff --git a/coilimageloader/src/main/java/net/mikaelzero/coilimageloader/CoilImageLoader.kt b/coilimageloader/src/main/java/net/mikaelzero/coilimageloader/CoilImageLoader.kt index c66ae5d..0d9b89a 100644 --- a/coilimageloader/src/main/java/net/mikaelzero/coilimageloader/CoilImageLoader.kt +++ b/coilimageloader/src/main/java/net/mikaelzero/coilimageloader/CoilImageLoader.kt @@ -8,15 +8,11 @@ import android.os.Build.VERSION.SDK_INT import coil.decode.GifDecoder import coil.decode.ImageDecoderDecoder import coil.decode.SvgDecoder +import coil.imageLoader import coil.request.Disposable import coil.request.ImageRequest -import coil.util.CoilUtils -import net.mikaelzero.mojito.loader.ImageLoader -import okhttp3.Cache -import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import java.io.File -import java.util.* import kotlin.collections.set @@ -25,7 +21,7 @@ import kotlin.collections.set * @CreateDate: 2021/7/23 11:07 上午 * @Description: */ -class CoilImageLoader private constructor(val context: Context) : ImageLoader { +class CoilImageLoader private constructor(val context: Context) : net.mikaelzero.mojito.loader.ImageLoader { private val SCHEMES = setOf( ContentResolver.SCHEME_FILE, @@ -36,17 +32,16 @@ class CoilImageLoader private constructor(val context: Context) : ImageLoader { private fun getImageLoader(context: Context): coil.ImageLoader { return coil.ImageLoader.Builder(context) .crossfade(true) - .componentRegistry { + .components { if (SDK_INT >= 28) { - add(ImageDecoderDecoder(context)) + add(ImageDecoderDecoder.Factory()) } else { - add(GifDecoder()) + add(GifDecoder.Factory()) } - add(SvgDecoder(context)) + add(SvgDecoder.Factory()) } .okHttpClient { OkHttpClient.Builder() - .cache(CoilUtils.createDefaultCache(context)) .addInterceptor { chain -> val request = chain.request() val response = chain.proceed(request) @@ -66,7 +61,7 @@ class CoilImageLoader private constructor(val context: Context) : ImageLoader { private val mFlyingRequestTargets: MutableMap = HashMap(3) - override fun loadImage(requestId: Int, uri: Uri?, onlyRetrieveFromCache: Boolean, callback: ImageLoader.Callback?) { + override fun loadImage(requestId: Int, uri: Uri?, onlyRetrieveFromCache: Boolean, callback: net.mikaelzero.mojito.loader.ImageLoader.Callback?) { val localCache = uri.toString().getCoilCacheFile() if (onlyRetrieveFromCache && (localCache == null || !localCache.exists())) { callback?.onFail(Exception("")) @@ -109,14 +104,6 @@ class CoilImageLoader private constructor(val context: Context) : ImageLoader { rememberTarget(requestId, imageLoader.enqueue(request)) } - private fun String?.toFile(): File? { - if (this == null) { - return null - } - val f = File(this) - return if (f.exists()) f else null - } - fun Uri?.getCoilCacheFile(): File? { if (SCHEMES.contains(this?.scheme)) { if (this?.path == null) { @@ -129,9 +116,7 @@ class CoilImageLoader private constructor(val context: Context) : ImageLoader { } fun String?.getCoilCacheFile(): File? { - return this?.toFile() ?: this?.toHttpUrlOrNull()?.let { u -> - CoilUtils.createDefaultCache(context).directory.listFiles()?.lastOrNull { it.name.endsWith(".1") && it.name.contains(Cache.key(u)) } - } + return context.imageLoader.diskCache?.get(this.orEmpty())?.data?.toFile() } override fun prefetch(uri: Uri?) { @@ -164,8 +149,8 @@ class CoilImageLoader private constructor(val context: Context) : ImageLoader { } override fun cleanCache() { - getImageLoader(context).memoryCache.clear() - CoilUtils.createDefaultCache(context).directory.delete() + getImageLoader(context).memoryCache?.clear() + context.imageLoader.diskCache?.clear() } diff --git a/gradle.properties b/gradle.properties index 6624c51..778ff22 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,8 +18,8 @@ android.enableJetifier=true kotlin.code.style=official # Config minSdk=16 -targetSdk=30 -compileSdk=30 +targetSdk=31 +compileSdk=31 # Maven GROUP=com.github.mikaelzero VERSION_NAME=1.8.3 \ No newline at end of file