Skip to content

Commit

Permalink
Upgrade to Coil 3.0.3 (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 authored Nov 25, 2024
1 parent 19f9f03 commit 57bf812
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 23 deletions.
10 changes: 7 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ androidx-test-ext-junit = "1.2.1"
androidx-test-monitor = "1.7.2"
androidx-test-runner = "1.6.2"
androidx-tv-material = "1.0.0"
coil = "2.7.0"
coil = "3.0.3"
comscore = "6.11.1"
dependency-analysis-gradle-plugin = "2.4.2"
detekt = "1.23.7"
Expand Down Expand Up @@ -63,8 +63,12 @@ androidx-test-core = { module = "androidx.test:core", version.ref = "androidx-te
androidx-test-monitor = { module = "androidx.test:monitor", version.ref = "androidx-test-monitor" }
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test-runner" }
androidx-tv-material = { module = "androidx.tv:tv-material", version.ref = "androidx-tv-material" }
coil = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
coil-base = { module = "io.coil-kt:coil-compose-base", version.ref = "coil" }
coil = { group = "io.coil-kt.coil3", name = "coil", version.ref = "coil" }
coil-compose = { group = "io.coil-kt.coil3", name = "coil-compose", version.ref = "coil" }
coil-core = { group = "io.coil-kt.coil3", name = "coil-core", version.ref = "coil" }
coil-network-cache-control = { group = "io.coil-kt.coil3", name = "coil-network-cache-control", version.ref = "coil" }
coil-network-core = { group = "io.coil-kt.coil3", name = "coil-network-core", version.ref = "coil" }
coil-network-okhttp = { group = "io.coil-kt.coil3", name = "coil-network-okhttp", version.ref = "coil" }
dokka-gradle-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
json = { module = "org.json:json", version.ref = "json" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 6 additions & 1 deletion pillarbox-demo-tv/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ dependencies {
implementation(libs.androidx.paging.compose)
implementation(libs.androidx.tv.material)
implementation(libs.coil)
implementation(libs.coil.base)
implementation(libs.coil.compose)
implementation(libs.coil.core)
implementation(libs.coil.network.cache.control)
implementation(libs.coil.network.core)
implementation(libs.coil.network.okhttp)
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.serialization.core)
implementation(libs.okhttp)
implementation(libs.srg.data)
implementation(libs.srg.dataprovider.retrofit)

Expand Down
1 change: 1 addition & 0 deletions pillarbox-demo-tv/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:required="false" />

<application
android:name=".DemoApplication"
android:allowBackup="true"
android:banner="@mipmap/ic_pillarbox_banner"
android:icon="@mipmap/ic_launcher_pillarbox"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.demo.tv

import android.app.Application
import ch.srgssr.pillarbox.player.network.PillarboxOkHttp
import coil3.ImageLoader
import coil3.PlatformContext
import coil3.SingletonImageLoader
import coil3.annotation.ExperimentalCoilApi
import coil3.network.cachecontrol.CacheControlCacheStrategy
import coil3.network.okhttp.OkHttpNetworkFetcherFactory

/**
* Demo application that sets up Coil.
*/
class DemoApplication : Application(), SingletonImageLoader.Factory {
@OptIn(ExperimentalCoilApi::class)
override fun newImageLoader(context: PlatformContext): ImageLoader {
return ImageLoader.Builder(context)
.components {
add(
OkHttpNetworkFetcherFactory(
callFactory = { PillarboxOkHttp() },
cacheStrategy = { CacheControlCacheStrategy() },
)
)
}
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import ch.srgssr.pillarbox.demo.shared.ui.NavigationRoutes
import ch.srgssr.pillarbox.demo.shared.ui.examples.ExamplesViewModel
import ch.srgssr.pillarbox.demo.tv.ui.theme.PillarboxTheme
import ch.srgssr.pillarbox.demo.tv.ui.theme.paddings
import coil.compose.AsyncImage
import coil3.compose.AsyncImage
import kotlinx.coroutines.launch

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import ch.srgssr.pillarbox.demo.tv.R
import ch.srgssr.pillarbox.demo.tv.ui.player.PlayerActivity
import ch.srgssr.pillarbox.demo.tv.ui.theme.PillarboxTheme
import ch.srgssr.pillarbox.demo.tv.ui.theme.paddings
import coil.compose.AsyncImage
import coil3.compose.AsyncImage
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.launch
import java.util.Date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import ch.srgssr.pillarbox.demo.tv.ui.theme.PillarboxTheme
import ch.srgssr.pillarbox.demo.tv.ui.theme.paddings
import coil.compose.AsyncImage
import coil3.compose.AsyncImage

/**
* Media metadata view
Expand Down
6 changes: 5 additions & 1 deletion pillarbox-demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ dependencies {
implementation(libs.androidx.paging.common)
implementation(libs.androidx.paging.compose)
implementation(libs.coil)
implementation(libs.coil.base)
implementation(libs.coil.compose)
implementation(libs.coil.core)
implementation(libs.coil.network.cache.control)
implementation(libs.coil.network.core)
implementation(libs.coil.network.okhttp)
implementation(libs.guava)
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.coroutines.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ import ch.srgssr.pillarbox.analytics.AnalyticsConfig
import ch.srgssr.pillarbox.analytics.SRGAnalytics.initSRGAnalytics
import ch.srgssr.pillarbox.analytics.UserConsent
import ch.srgssr.pillarbox.analytics.comscore.ComScoreUserConsent
import ch.srgssr.pillarbox.player.network.PillarboxOkHttp
import coil3.ImageLoader
import coil3.PlatformContext
import coil3.SingletonImageLoader
import coil3.annotation.ExperimentalCoilApi
import coil3.network.cachecontrol.CacheControlCacheStrategy
import coil3.network.okhttp.OkHttpNetworkFetcherFactory

/**
* Demo application
* - Init SRG Analytics
* Demo application that initializes SRG Analytics and Coil.
*/
class DemoApplication : Application() {
class DemoApplication : Application(), SingletonImageLoader.Factory {

override fun onCreate() {
super.onCreate()
Expand All @@ -32,4 +38,18 @@ class DemoApplication : Application() {
)
initSRGAnalytics(config = config)
}

@OptIn(ExperimentalCoilApi::class)
override fun newImageLoader(context: PlatformContext): ImageLoader {
return ImageLoader.Builder(context)
.components {
add(
OkHttpNetworkFetcherFactory(
callFactory = { PillarboxOkHttp() },
cacheStrategy = { CacheControlCacheStrategy() },
)
)
}
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.media3.common.MediaMetadata
import ch.srgssr.pillarbox.demo.ui.theme.paddings
import coil.compose.AsyncImage
import coil3.compose.AsyncImage

/**
* Media metadata view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import ch.srgssr.pillarbox.demo.ui.player.PlayerView
import ch.srgssr.pillarbox.demo.ui.theme.PillarboxTheme
import ch.srgssr.pillarbox.demo.ui.theme.paddings
import ch.srgssr.pillarbox.player.asset.timeRange.Chapter
import coil.compose.AsyncImage
import coil3.compose.AsyncImage
import kotlin.time.Duration.Companion.minutes

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package ch.srgssr.pillarbox.demo.ui.showcases.layouts.thumbnail

import android.app.Application
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand All @@ -16,22 +15,21 @@ import androidx.media3.exoplayer.image.ImageOutput
import ch.srgssr.pillarbox.core.business.PillarboxExoPlayer
import ch.srgssr.pillarbox.core.business.SRGMediaItem
import ch.srgssr.pillarbox.demo.shared.data.DemoItem
import ch.srgssr.pillarbox.player.network.PillarboxOkHttp
import ch.srgssr.pillarbox.ui.ProgressTrackerState
import ch.srgssr.pillarbox.ui.SmoothProgressTrackerState
import coil.imageLoader
import coil.request.ImageRequest
import coil.size.Scale
import coil3.BitmapImage
import coil3.imageLoader
import coil3.request.ImageRequest
import coil3.request.allowConversionToBitmap
import coil3.size.Scale

/**
* A ViewModel to demonstrate how to work with Image track.
*
* @param application The [Application].
*/
class ThumbnailViewModel(application: Application) : AndroidViewModel(application), ImageOutput {
private val imageLoader = application.imageLoader.newBuilder()
.okHttpClient(PillarboxOkHttp())
.build()
private val imageLoader = application.imageLoader

/**
* Player
Expand All @@ -44,7 +42,7 @@ class ThumbnailViewModel(application: Application) : AndroidViewModel(applicatio
.scale(Scale.FILL) // FILL to have the source image size!
.allowConversionToBitmap(enable = true)
.target { result ->
val bitmap = (result as BitmapDrawable).bitmap
val bitmap = (result as BitmapImage).bitmap
onComplete(bitmap)
}
.build()
Expand Down

0 comments on commit 57bf812

Please sign in to comment.