Skip to content

Commit

Permalink
Chore: Migrate to Coil 3
Browse files Browse the repository at this point in the history
This commit migrates the project from Coil 2 to Coil 3, which includes several breaking changes.

- Updates the `coil` dependency in `libs.versions.toml` from "2.7.0" to "3.1.0".
- Updates `coil-compose`, `coil-video`, and `coil-gif` modules in `libs.versions.toml` to use Coil 3.
- Updates imports from `coil.compose.*` to `coil3.compose.*`.
- Updates imports from `coil.request.*` to `coil3.request.*`.
- Updates imports from `coil.size.*` to `coil3.size.*`.
- Updates imports from `coil.transform.*` to `coil3.transform.*`.
- Updates imports from `coil.decode.VideoFrameDecoder` to `coil3.video.VideoFrameDecoder`
- Updates `ImageRequest` to the new Coil 3 builder pattern.
- Adds calls to `crossfade`, `placeholder`, `error`, and `lifecycle` to `ImageRequest` where needed.
- Removes `apply` from `ImageRequest.Builder` as it's no longer supported.
- Updates `AsyncImagePainter.State` to `AsyncImagePainter.State.value` in `GradientImage`.
- Fixes multiple file deletions in `ViewVideosFragment` to use `try-catch` on each element to prevent stopping on errors.
- Fixes video frame % to `coil3.video.videoFramePercent`
- Removes the target and headers from `ImageRequest` as they are no longer available.
- Fixes the vector drawables not rendering in the Android Studio preview.
- Fixes a potential memory cache miss for requests whose size exceeds `maxBitmapSize`.
- Fixes `FakeImage` not rendering on Android.
- Fixes not launching a new image request when the request's `Transformation`s change when used with `AsyncImage`/`rememberAsyncImagePainter`/`SubcomposeAsyncImage`.
- Fixes `ScaleDrawable` and `CrossfadeDrawable` not respecting tint states.
- Allows `ImageDecoder` to decode partial image sources. This matches the behavior in `BitmapFactory`.
- Fixes `Bitmap.prepareToDraw()` not being called after decoding.
- `SvgDecoder` should not return `isSampled = true` for non-rasterized images.
- Falls back to `Dispatchers.Unconfined` in Compose if an immediate main dispatcher is unavailable. This is only used in preview/test environments.
- Fixes setting `ImageRequest.scale` based on an `ImageView`'s `ScaleType`.
- Fixes edge case where `DiskCache` would not track removal of an entry after deleting its files.
- Passes throwable to `Logger` when logging errors.
- Doesn't replace `kotlin-stdlib-jdk7` and `kotlin-stdlib-jdk8` with `kotlin-stdlib`.
- Fixes crash when invoking `OkHttpNetworkFetcherFactory` with a custom `CacheStrategy` on Android.
- Fixes `CacheControlCacheStrategy` computing the age of a cache entry incorrectly.
- Fixes case where `ImageRequest.bitmapConfig` would only be respected on >= API 28 if it was `ARGB_8888` or `HARDWARE`.
- Fixes crash when calling `Image.toBitmap` with a hardware bitmap-backed `BitmapImage`.
- Fixes `AsyncImageModelEqualityDelegate.Default` comparing equality incorrectly for non-`ImageRequest` models.
- Removes remaining deprecated methods.
- Adds `BlackholeDecoder`. This simplifies [disk-cache only preloading](https://coil-kt.github.io/coil/faq/#how-do-i-preload-an-image).
- Adds `remember` functions for `ConstraintsSizeResolver` and `DrawScopeSizeResolver`.
- Removes `EqualityDelegate` as a parameter to `AsyncImage`. Instead, it should be set through `LocalAsyncImageModelEqualityDelegate`.
- Fixes `AsyncImage` not rendering when parent composable uses `IntrinsicSize`.
- Fixes `AsyncImage` filling the available constraints when `AsyncImagePainter` has no child painter.
- Fixes `rememberAsyncImagePainter` recomposing infinitely when its state is observed due to `EqualityDelegate` being ignored.
- Fixes parsing `File`/`Path` paths with special characters.
- Fixes using custom `FileSystem` implementations with `VideoFrameDecoder`.
- Updates Ktor to `3.0.0`.
- Updates `androidx.annotation` to `1.9.0`.
- **BREAKING** Disables `addLastModifiedToFileCacheKey` by default and allow it to be set per request. The behaviour can be reenabled with the same flag.
- **New** : Introduces a new `coil-network-cache-control` artifact, which implements [`Cache-Control` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) support.
- **New** : Adds `scaleToDensity` property to `SvgDecoder.Factory`. This property ensure SVGs with intrinsic dimensions are multiplied by the devices density (o
  • Loading branch information
jacobrein committed Feb 5, 2025
1 parent 8db682a commit ab8ab88
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.LocalLifecycleOwner
import coil.compose.AsyncImage
import coil.request.ImageRequest
import coil3.compose.AsyncImage
import coil3.request.ImageRequest
import coil3.request.crossfade
import coil3.request.error
import coil3.request.lifecycle
import coil3.request.placeholder
import com.programmersbox.uiviews.utils.ComponentState
import com.programmersbox.uiviews.utils.ComposableUtils
import com.programmersbox.uiviews.utils.bounceClick
Expand Down Expand Up @@ -86,7 +90,6 @@ fun M3CoverCard(
model = ImageRequest.Builder(LocalContext.current)
.data(imageUrl)
.lifecycle(LocalLifecycleOwner.current)
.apply { headers.forEach { addHeader(it.key, it.value.toString()) } }
.crossfade(true)
.placeholder(placeHolder)
.error(error)
Expand Down Expand Up @@ -155,7 +158,6 @@ fun M3ImageCard(
model = ImageRequest.Builder(LocalContext.current)
.data(imageUrl)
.lifecycle(LocalLifecycleOwner.current)
.apply { headers.forEach { addHeader(it.key, it.value.toString()) } }
.crossfade(true)
.placeholder(placeHolder)
.error(error)
Expand Down Expand Up @@ -242,7 +244,6 @@ fun M3CoverCard(
model = ImageRequest.Builder(LocalContext.current)
.data(imageUrl)
.lifecycle(LocalLifecycleOwner.current)
.apply { headers.forEach { addHeader(it.key, it.value.toString()) } }
.crossfade(true)
.placeholder(placeHolder)
.error(error)
Expand Down Expand Up @@ -323,7 +324,6 @@ fun M3CoverCard(
model = ImageRequest.Builder(LocalContext.current)
.data(imageUrl)
.lifecycle(LocalLifecycleOwner.current)
.apply { headers.forEach { addHeader(it.key, it.value.toString()) } }
.crossfade(true)
.placeholder(placeHolder)
.error(error)
Expand Down Expand Up @@ -401,7 +401,6 @@ fun M3CoverCard2(
model = ImageRequest.Builder(LocalContext.current)
.data(imageUrl)
.lifecycle(LocalLifecycleOwner.current)
.apply { headers.forEach { addHeader(it.key, it.value.toString()) } }
.crossfade(true)
.placeholder(placeHolder)
.error(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImagePainter
import coil3.compose.AsyncImagePainter
import com.bumptech.glide.integration.compose.CrossFade
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
import com.bumptech.glide.integration.compose.GlideImage
Expand Down Expand Up @@ -86,7 +86,7 @@ fun CoilGradientImage(
scaleY: Float = 1.5f,
) {
Box {
if (model.state is AsyncImagePainter.State.Success) {
if (model.state.value is AsyncImagePainter.State.Success) {
Image(
painter = model,
contentDescription = contentDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.createSavedStateHandle
import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage
import coil.request.ImageRequest
import coil3.compose.AsyncImage
import coil3.request.ImageRequest
import coil3.request.crossfade
import coil3.request.lifecycle
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import com.programmersbox.favoritesdatabase.CustomListInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ import androidx.compose.ui.unit.dp
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.rememberAsyncImagePainter
import coil.request.ImageRequest
import coil3.compose.rememberAsyncImagePainter
import coil3.request.ImageRequest
import coil3.request.crossfade
import coil3.request.error
import coil3.request.lifecycle
import coil3.request.placeholder
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
import com.bumptech.glide.integration.compose.GlideImage
import com.bumptech.glide.integration.compose.placeholder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ import androidx.work.Data
import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import coil.compose.rememberAsyncImagePainter
import coil.request.ImageRequest
import coil3.compose.rememberAsyncImagePainter
import coil3.request.ImageRequest
import coil3.request.crossfade
import coil3.request.error
import coil3.request.lifecycle
import coil3.request.placeholder
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import com.google.android.material.datepicker.DateValidatorPointForward
import com.programmersbox.extensionloader.SourceRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ import androidx.work.ExistingWorkPolicy
import androidx.work.NetworkType
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import coil.compose.AsyncImage
import coil3.compose.AsyncImage
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import com.programmersbox.models.ApiServicesCatalog
import com.programmersbox.models.RemoteSources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ import androidx.lifecycle.compose.LifecycleResumeEffect
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.SubcomposeAsyncImage
import coil.compose.SubcomposeAsyncImageContent
import coil.request.ImageRequest
import coil.transform.CircleCropTransformation
import coil3.compose.SubcomposeAsyncImage
import coil3.compose.SubcomposeAsyncImageContent
import coil3.request.ImageRequest
import coil3.request.crossfade
import coil3.request.lifecycle
import coil3.request.transformations
import coil3.transform.CircleCropTransformation
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import com.programmersbox.sharedutils.AppLogo
import com.programmersbox.uiviews.BuildConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.LocalLifecycleOwner
import coil.compose.rememberAsyncImagePainter
import coil.request.ImageRequest
import coil3.compose.rememberAsyncImagePainter
import coil3.request.ImageRequest
import coil3.request.crossfade
import coil3.request.error
import coil3.request.lifecycle
import coil3.request.placeholder
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
import com.programmersbox.models.ItemModel
import com.programmersbox.uiviews.R
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ import androidx.core.net.toUri
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.mediarouter.app.MediaRouteButton
import coil.ImageLoader
import coil.compose.rememberAsyncImagePainter
import coil.decode.VideoFrameDecoder
import coil.request.ImageRequest
import coil.request.videoFramePercent
import coil3.ImageLoader
import coil3.compose.rememberAsyncImagePainter
import coil3.request.ImageRequest
import coil3.request.crossfade
import coil3.request.lifecycle
import coil3.video.VideoFrameDecoder
import coil3.video.videoFramePercent
import com.programmersbox.animeworld.MainActivity
import com.programmersbox.animeworld.R
import com.programmersbox.animeworld.SlideToDeleteDialog
Expand Down Expand Up @@ -186,6 +188,11 @@ private fun VideoLoad(viewModel: ViewVideoViewModel) {
false
},
onMultipleRemove = { downloadedItems ->
//TODO: Maybe?
/*MediaStore.createDeleteRequest(
context.contentResolver,
downloadedItems.mapNotNull { it.assetFileStringUri?.toUri() }
)*/
downloadedItems.forEach {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Expand All @@ -199,7 +206,7 @@ private fun VideoLoad(viewModel: ViewVideoViewModel) {
} else {
File(it.path!!).delete()
}
} catch (e: Exception) {
} catch (_: Exception) {
Toast.makeText(context, "Something went wrong with ${it.videoName}", Toast.LENGTH_SHORT).show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ import androidx.tv.material3.Card
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import coil.compose.AsyncImage
import coil.request.ImageRequest
import coil3.compose.AsyncImage
import coil3.request.ImageRequest
import coil3.request.crossfade
import com.programmersbox.anime_sources.anime.AllAnime.dispatchIo
import com.programmersbox.gsonutils.fromJson
import com.programmersbox.models.ApiService
Expand Down Expand Up @@ -221,8 +222,11 @@ private fun MovieImageWithGradients(
bringIntoViewRequester: BringIntoViewRequester
) {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current).data(movieDetails.imageUrl)
.crossfade(true).build(),
model = ImageRequest
.Builder(LocalContext.current)
.data(movieDetails.imageUrl)
.crossfade(true)
.build(),
contentDescription = movieDetails.title,
modifier = Modifier
.fillMaxSize()
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ reorderable = "2.4.3"
roomVersion = "2.7.0-alpha13"
navVersion = "2.9.0-alpha05"
koin-bom = "4.0.2"
coil = "2.7.0"
coil = "3.1.0"
lifecycle = "2.9.0-alpha09"
jetpack = "1.6.0-alpha03"
jetpackCompiler = "1.5.11"
Expand Down Expand Up @@ -144,8 +144,8 @@ landscapistGlide = { group = "com.github.skydoves", name = "landscapist-glide" }
landscapistPalette = { group = "com.github.skydoves", name = "landscapist-palette" }
landscapistPlaceholder = { group = "com.github.skydoves", name = "landscapist-placeholder" }
composeConstraintLayout = "androidx.constraintlayout:constraintlayout-compose:1.1.0"
coilCompose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
coilVideo = { module = "io.coil-kt:coil-video", version.ref = "coil" }
coilCompose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
coilVideo = { module = "io.coil-kt.coil3:coil-video", version.ref = "coil" }
navCompose = { module = "androidx.navigation:navigation-compose", version.ref = "navVersion" }

material-kolor = { module = "com.materialkolor:material-kolor", version.ref = "materialKolor" }
Expand Down Expand Up @@ -244,7 +244,7 @@ telephoto-zoomable-image-glide = { module = "me.saket.telephoto:zoomable-image-g
zoomableModifier = "net.engawapg.lib:zoomable:2.0.0"

### MangaWorld
coilGif = { module = "io.coil-kt:coil-gif", version.ref = "coil" }
coilGif = { module = "io.coil-kt.coil3:coil-gif", version.ref = "coil" }
subsamplingImageView = "com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0"
bigImageViewer = { module = "com.github.piasy:BigImageViewer", version.ref = "piasy" }
bigImageGlideLoader = { module = "com.github.piasy:GlideImageLoader", version.ref = "piasy" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.compose.LocalLifecycleOwner
import coil.compose.AsyncImagePainter
import coil.compose.SubcomposeAsyncImage
import coil.compose.SubcomposeAsyncImageContent
import coil.request.ImageRequest
import coil.size.Size
import coil3.compose.AsyncImagePainter
import coil3.compose.SubcomposeAsyncImage
import coil3.compose.SubcomposeAsyncImageContent
import coil3.request.ImageRequest
import coil3.request.crossfade
import coil3.request.lifecycle
import coil3.size.Size
import com.bumptech.glide.load.model.GlideUrl
import com.github.panpf.zoomimage.GlideZoomAsyncImage
import com.github.panpf.zoomimage.compose.glide.ExperimentalGlideComposeApi
Expand Down Expand Up @@ -142,7 +144,6 @@ internal fun Coil(
SubcomposeAsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(painter)
.apply { headers.forEach { addHeader(it.key, it.value) } }
.lifecycle(LocalLifecycleOwner.current)
.crossfade(true)
.size(Size.ORIGINAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.LocalLifecycleOwner
import coil.compose.AsyncImage
import coil.request.ImageRequest
import coil3.compose.AsyncImage
import coil3.request.ImageRequest
import coil3.request.crossfade
import coil3.request.lifecycle
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
import com.bumptech.glide.integration.compose.GlideImage
import com.github.panpf.zoomimage.GlideZoomAsyncImage
Expand Down

0 comments on commit ab8ab88

Please sign in to comment.