From 5d573fba91a7eb6c686b0afd7c64973124bb21fe Mon Sep 17 00:00:00 2001 From: John Carlson Date: Mon, 4 Nov 2024 23:25:10 -0600 Subject: [PATCH] Coil 3 --- .github/workflows/ci.yml | 21 ++++++++--- .github/workflows/publish-release.yml | 35 +++++++++++++++++++ .jitpack.yml | 2 +- CHANGELOG.md | 3 ++ buildSrc/src/main/kotlin/Extensions.kt | 2 +- gradle.properties | 6 ++-- sample/build.gradle.kts | 22 ++++++------ .../coiltransformations/sample/App.kt | 14 ++++---- .../coiltransformations/sample/Image.kt | 2 +- .../sample/ImageListAdapter.kt | 4 +-- .../sample/MainActivity.kt | 3 +- .../build.gradle.kts | 13 +++---- .../CenterOnFaceTransformation.kt | 6 ++-- transformations-gpu/build.gradle.kts | 11 +++--- .../gpu/GPUFilterTransformation.kt | 6 ++-- transformations/build.gradle.kts | 13 +++---- .../coiltransformations/BlurTransformation.kt | 6 ++-- .../ColorFilterTransformation.kt | 6 ++-- .../coiltransformations/CropTransformation.kt | 8 ++--- .../GrayscaleTransformation.kt | 6 ++-- .../coiltransformations/MaskTransformation.kt | 6 ++-- .../SquareCropTransformation.kt | 7 ++-- .../com/commit451/coiltransformations/ext.kt | 11 ------ 23 files changed, 122 insertions(+), 91 deletions(-) create mode 100644 .github/workflows/publish-release.yml delete mode 100644 transformations/src/main/java/com/commit451/coiltransformations/ext.kt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 170f790..7605c4d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,23 @@ name: Build -on: [pull_request, push] + +on: [push, pull_request] + jobs: build: runs-on: ubuntu-latest + steps: - - name: Checkout the code - uses: actions/checkout@v2 - - name: Build the app + - name: Checkout + uses: actions/checkout@v4 + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1 + + - name: Configure JDK + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + + - name: Test run: ./gradlew build diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 0000000..1947480 --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,35 @@ +name: Publish Release + +on: + push: + tags: + - '*' +env: + RELEASE_SIGNING_ENABLED: true + +jobs: + publish: + + runs-on: ubuntu-latest + if: github.repository == 'Commit451/coil-transformations' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install JDK + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 17 + + - name: Set version + run: sed -i "s/VERSION_NAME=0.0.1/VERSION_NAME=$GITHUB_REF_NAME/" gradle.properties + + - name: Release to Maven Central + run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_PRIVATE_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} diff --git a/.jitpack.yml b/.jitpack.yml index 88cfba7..bb8a4f6 100644 --- a/.jitpack.yml +++ b/.jitpack.yml @@ -1 +1 @@ -jdk: openjdk11 +jdk: openjdk17 diff --git a/CHANGELOG.md b/CHANGELOG.md index 48c6ee4..5cc507b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## [3.0.0] - November 5, 2024 +- Updates to support Coil 3.0 + ## [2.0.0] - March 16, 2022 - Updates to support Coil 2.0 diff --git a/buildSrc/src/main/kotlin/Extensions.kt b/buildSrc/src/main/kotlin/Extensions.kt index 18c5ee7..31e90f9 100644 --- a/buildSrc/src/main/kotlin/Extensions.kt +++ b/buildSrc/src/main/kotlin/Extensions.kt @@ -1,4 +1,4 @@ -@file:Suppress("NOTHING_TO_INLINE", "unused") +@file:Suppress("unused") package coiltransformations diff --git a/gradle.properties b/gradle.properties index 0147a57..d89c053 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,12 +5,12 @@ android.useAndroidX=true # Config minSdk=21 -targetSdk=32 -coilVersion=2.0.0 +targetSdk=35 +coilVersion=3.0.0 GROUP=com.commit451.coiltransformations # Overwritten by CI -VERSION_NAME=1.0.0 +VERSION_NAME=0.0.1 POM_NAME=Transformations for Coil POM_DESCRIPTION=Various transformations for Coil diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index f93fd9f..982e570 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -26,11 +26,11 @@ android { } } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = "1.8" + jvmTarget = JavaVersion.VERSION_17.toString() } } @@ -38,15 +38,15 @@ dependencies { implementation(project(":transformations")) implementation(project(":transformations-gpu")) implementation(project(":transformations-face-detection")) - implementation("io.coil-kt:coil:${project.coilVersion}") + implementation("io.coil-kt.coil3:coil-compose:${project.coilVersion}") - implementation("androidx.appcompat:appcompat:1.4.1") - implementation("androidx.constraintlayout:constraintlayout:2.1.3") - implementation("androidx.core:core-ktx:1.7.0") + implementation("androidx.appcompat:appcompat:1.7.0") + implementation("androidx.constraintlayout:constraintlayout:2.2.0") + implementation("androidx.core:core-ktx:1.15.0") implementation("androidx.lifecycle:lifecycle-extensions:2.2.0") - implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.4.1") - implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1") - implementation("androidx.recyclerview:recyclerview:1.2.1") + implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.8.7") + implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7") + implementation("androidx.recyclerview:recyclerview:1.3.2") - implementation("com.google.android.material:material:1.5.0") + implementation("com.google.android.material:material:1.12.0") } diff --git a/sample/src/main/java/com/commit451/coiltransformations/sample/App.kt b/sample/src/main/java/com/commit451/coiltransformations/sample/App.kt index 99c810c..56723e9 100644 --- a/sample/src/main/java/com/commit451/coiltransformations/sample/App.kt +++ b/sample/src/main/java/com/commit451/coiltransformations/sample/App.kt @@ -3,20 +3,18 @@ package com.commit451.coiltransformations.sample import android.app.Application -import android.util.Log -import coil.Coil -import coil.ImageLoader -import coil.memory.MemoryCache -import coil.util.DebugLogger +import coil3.ImageLoader +import coil3.SingletonImageLoader +import coil3.request.crossfade +import coil3.util.DebugLogger class App : Application() { override fun onCreate() { super.onCreate() - Coil.setImageLoader { + SingletonImageLoader.setSafe { ImageLoader.Builder(this) - .logger(DebugLogger(level = Log.DEBUG)) - .memoryCache(MemoryCache.Builder(this).maxSizePercent(0.5).build()) + .logger(DebugLogger()) .crossfade(true) .build() } diff --git a/sample/src/main/java/com/commit451/coiltransformations/sample/Image.kt b/sample/src/main/java/com/commit451/coiltransformations/sample/Image.kt index 06e0f6a..ad0a4c3 100644 --- a/sample/src/main/java/com/commit451/coiltransformations/sample/Image.kt +++ b/sample/src/main/java/com/commit451/coiltransformations/sample/Image.kt @@ -1,7 +1,7 @@ package com.commit451.coiltransformations.sample import androidx.annotation.DrawableRes -import coil.transform.Transformation +import coil3.transform.Transformation data class Image( val transformation: Transformation, diff --git a/sample/src/main/java/com/commit451/coiltransformations/sample/ImageListAdapter.kt b/sample/src/main/java/com/commit451/coiltransformations/sample/ImageListAdapter.kt index 2e5b33a..2821a3b 100644 --- a/sample/src/main/java/com/commit451/coiltransformations/sample/ImageListAdapter.kt +++ b/sample/src/main/java/com/commit451/coiltransformations/sample/ImageListAdapter.kt @@ -7,8 +7,8 @@ import android.widget.TextView import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView -import coil.load -import com.commit451.coiltransformations.facedetection.CenterOnFaceTransformation +import coil3.load +import coil3.request.transformations import com.commit451.coiltransformations.sample.ImageListAdapter.ViewHolder class ImageListAdapter( diff --git a/sample/src/main/java/com/commit451/coiltransformations/sample/MainActivity.kt b/sample/src/main/java/com/commit451/coiltransformations/sample/MainActivity.kt index 9e668c5..d4e3eef 100644 --- a/sample/src/main/java/com/commit451/coiltransformations/sample/MainActivity.kt +++ b/sample/src/main/java/com/commit451/coiltransformations/sample/MainActivity.kt @@ -9,7 +9,8 @@ import androidx.core.view.isVisible import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import coil.load +import coil3.load +import coil3.request.transformations class MainActivity : AppCompatActivity() { diff --git a/transformations-face-detection/build.gradle.kts b/transformations-face-detection/build.gradle.kts index e7f7f89..a1dbbbf 100644 --- a/transformations-face-detection/build.gradle.kts +++ b/transformations-face-detection/build.gradle.kts @@ -18,18 +18,15 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = "1.8" - } - libraryVariants.all { - generateBuildConfigProvider?.configure { enabled = false } + jvmTarget = JavaVersion.VERSION_17.toString() } } dependencies { - api("io.coil-kt:coil-base:${project.coilVersion}") - api("com.google.mlkit:face-detection:16.1.5") + api("io.coil-kt.coil3:coil-core:${project.coilVersion}") + api("com.google.mlkit:face-detection:16.1.7") } diff --git a/transformations-face-detection/src/main/java/com/commit451/coiltransformations/facedetection/CenterOnFaceTransformation.kt b/transformations-face-detection/src/main/java/com/commit451/coiltransformations/facedetection/CenterOnFaceTransformation.kt index 04d49b4..0fc077c 100644 --- a/transformations-face-detection/src/main/java/com/commit451/coiltransformations/facedetection/CenterOnFaceTransformation.kt +++ b/transformations-face-detection/src/main/java/com/commit451/coiltransformations/facedetection/CenterOnFaceTransformation.kt @@ -4,8 +4,8 @@ import android.graphics.Bitmap import android.graphics.Rect import android.util.Log import android.util.LruCache -import coil.size.Size -import coil.transform.Transformation +import coil3.size.Size +import coil3.transform.Transformation import com.google.mlkit.vision.common.InputImage import com.google.mlkit.vision.face.FaceDetection import com.google.mlkit.vision.face.FaceDetectorOptions @@ -29,7 +29,7 @@ import kotlin.coroutines.resumeWithException class CenterOnFaceTransformation constructor( private val cache: LruCache? = null, val zoom: Int -) : Transformation { +) : Transformation() { companion object { private const val TAG = "CenterOnFaceTransform" diff --git a/transformations-gpu/build.gradle.kts b/transformations-gpu/build.gradle.kts index 78d4b21..34b02e6 100644 --- a/transformations-gpu/build.gradle.kts +++ b/transformations-gpu/build.gradle.kts @@ -18,18 +18,15 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = "1.8" - } - libraryVariants.all { - generateBuildConfigProvider?.configure { enabled = false } + jvmTarget = JavaVersion.VERSION_17.toString() } } dependencies { - api("io.coil-kt:coil-base:${project.coilVersion}") + api("io.coil-kt.coil3:coil-core:${project.coilVersion}") api("jp.co.cyberagent.android:gpuimage:2.1.0") } diff --git a/transformations-gpu/src/main/java/com/commit451/coiltransformations/gpu/GPUFilterTransformation.kt b/transformations-gpu/src/main/java/com/commit451/coiltransformations/gpu/GPUFilterTransformation.kt index cb9a729..4bc6ade 100644 --- a/transformations-gpu/src/main/java/com/commit451/coiltransformations/gpu/GPUFilterTransformation.kt +++ b/transformations-gpu/src/main/java/com/commit451/coiltransformations/gpu/GPUFilterTransformation.kt @@ -2,8 +2,8 @@ package com.commit451.coiltransformations.gpu import android.content.Context import android.graphics.Bitmap -import coil.size.Size -import coil.transform.Transformation +import coil3.size.Size +import coil3.transform.Transformation import jp.co.cyberagent.android.gpuimage.GPUImage import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter @@ -14,7 +14,7 @@ import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter */ abstract class GPUFilterTransformation( private val context: Context -) : Transformation { +) : Transformation() { /** * Create the [GPUImageFilter] to apply to this [Transformation] diff --git a/transformations/build.gradle.kts b/transformations/build.gradle.kts index 6b6ceb9..c5f9064 100644 --- a/transformations/build.gradle.kts +++ b/transformations/build.gradle.kts @@ -18,18 +18,15 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = "1.8" - } - libraryVariants.all { - generateBuildConfigProvider?.configure { enabled = false } + jvmTarget = JavaVersion.VERSION_17.toString() } } dependencies { - api("io.coil-kt:coil-base:${project.coilVersion}") - api("androidx.core:core-ktx:1.7.0") + api("io.coil-kt.coil3:coil-core:${project.coilVersion}") + api("androidx.core:core-ktx:1.15.0") } diff --git a/transformations/src/main/java/com/commit451/coiltransformations/BlurTransformation.kt b/transformations/src/main/java/com/commit451/coiltransformations/BlurTransformation.kt index e58a9f5..0452667 100644 --- a/transformations/src/main/java/com/commit451/coiltransformations/BlurTransformation.kt +++ b/transformations/src/main/java/com/commit451/coiltransformations/BlurTransformation.kt @@ -12,8 +12,8 @@ import android.renderscript.ScriptIntrinsicBlur import androidx.annotation.RequiresApi import androidx.core.graphics.applyCanvas import androidx.core.graphics.createBitmap -import coil.size.Size -import coil.transform.Transformation +import coil3.size.Size +import coil3.transform.Transformation import com.commit451.coiltransformations.Util.safeConfig /** @@ -29,7 +29,7 @@ class BlurTransformation @JvmOverloads constructor( private val context: Context, private val radius: Float = DEFAULT_RADIUS, private val sampling: Float = DEFAULT_SAMPLING -) : Transformation { +) : Transformation() { init { require(radius in 0.0..25.0) { "radius must be in [0, 25]." } diff --git a/transformations/src/main/java/com/commit451/coiltransformations/ColorFilterTransformation.kt b/transformations/src/main/java/com/commit451/coiltransformations/ColorFilterTransformation.kt index c1cd074..d601feb 100644 --- a/transformations/src/main/java/com/commit451/coiltransformations/ColorFilterTransformation.kt +++ b/transformations/src/main/java/com/commit451/coiltransformations/ColorFilterTransformation.kt @@ -3,8 +3,8 @@ package com.commit451.coiltransformations import android.graphics.* import androidx.annotation.ColorInt import androidx.core.graphics.createBitmap -import coil.size.Size -import coil.transform.Transformation +import coil3.size.Size +import coil3.transform.Transformation import com.commit451.coiltransformations.Util.safeConfig /** @@ -13,7 +13,7 @@ import com.commit451.coiltransformations.Util.safeConfig */ class ColorFilterTransformation( @ColorInt private val color: Int -) : Transformation { +) : Transformation() { override val cacheKey: String = "${ColorFilterTransformation::class.java.name}-$color" diff --git a/transformations/src/main/java/com/commit451/coiltransformations/CropTransformation.kt b/transformations/src/main/java/com/commit451/coiltransformations/CropTransformation.kt index e7726ee..0c4199b 100644 --- a/transformations/src/main/java/com/commit451/coiltransformations/CropTransformation.kt +++ b/transformations/src/main/java/com/commit451/coiltransformations/CropTransformation.kt @@ -4,9 +4,9 @@ import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.RectF import androidx.core.graphics.createBitmap -import coil.size.Size -import coil.size.pxOrElse -import coil.transform.Transformation +import coil3.size.Size +import coil3.size.pxOrElse +import coil3.transform.Transformation import com.commit451.coiltransformations.Util.safeConfig import kotlin.math.max @@ -16,7 +16,7 @@ import kotlin.math.max */ class CropTransformation( private val cropType: CropType = CropType.CENTER -) : Transformation { +) : Transformation() { enum class CropType { TOP, diff --git a/transformations/src/main/java/com/commit451/coiltransformations/GrayscaleTransformation.kt b/transformations/src/main/java/com/commit451/coiltransformations/GrayscaleTransformation.kt index 3c2a379..c91383b 100644 --- a/transformations/src/main/java/com/commit451/coiltransformations/GrayscaleTransformation.kt +++ b/transformations/src/main/java/com/commit451/coiltransformations/GrayscaleTransformation.kt @@ -7,14 +7,14 @@ import android.graphics.ColorMatrixColorFilter import android.graphics.Paint import androidx.core.graphics.applyCanvas import androidx.core.graphics.createBitmap -import coil.size.Size -import coil.transform.Transformation +import coil3.size.Size +import coil3.transform.Transformation import com.commit451.coiltransformations.Util.safeConfig /** * A [Transformation] that converts an image to shades of gray. */ -class GrayscaleTransformation : Transformation { +class GrayscaleTransformation : Transformation() { override val cacheKey: String = GrayscaleTransformation::class.java.name diff --git a/transformations/src/main/java/com/commit451/coiltransformations/MaskTransformation.kt b/transformations/src/main/java/com/commit451/coiltransformations/MaskTransformation.kt index 0ce306f..d10b5b8 100644 --- a/transformations/src/main/java/com/commit451/coiltransformations/MaskTransformation.kt +++ b/transformations/src/main/java/com/commit451/coiltransformations/MaskTransformation.kt @@ -11,8 +11,8 @@ import androidx.annotation.DrawableRes import androidx.core.content.res.ResourcesCompat import androidx.core.graphics.applyCanvas import androidx.core.graphics.createBitmap -import coil.size.Size -import coil.transform.Transformation +import coil3.size.Size +import coil3.transform.Transformation import com.commit451.coiltransformations.Util.safeConfig import kotlin.math.max @@ -21,7 +21,7 @@ import kotlin.math.max * @param context context for loading the drawable * @param maskDrawableRes the drawable resource to use as the mask */ -class MaskTransformation(private val context: Context, @DrawableRes val maskDrawableRes: Int) : Transformation { +class MaskTransformation(private val context: Context, @DrawableRes val maskDrawableRes: Int) : Transformation() { companion object { private val paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG).apply { diff --git a/transformations/src/main/java/com/commit451/coiltransformations/SquareCropTransformation.kt b/transformations/src/main/java/com/commit451/coiltransformations/SquareCropTransformation.kt index 0695091..e407fd7 100644 --- a/transformations/src/main/java/com/commit451/coiltransformations/SquareCropTransformation.kt +++ b/transformations/src/main/java/com/commit451/coiltransformations/SquareCropTransformation.kt @@ -1,14 +1,15 @@ package com.commit451.coiltransformations import android.graphics.Bitmap -import coil.size.Size -import coil.transform.Transformation +import coil3.size.Size +import coil3.size.pxOrElse +import coil3.transform.Transformation import kotlin.math.max /** * A [Transformation] that applies a crop square transformation. */ -class SquareCropTransformation : Transformation { +class SquareCropTransformation : Transformation() { override val cacheKey: String = SquareCropTransformation::class.java.name diff --git a/transformations/src/main/java/com/commit451/coiltransformations/ext.kt b/transformations/src/main/java/com/commit451/coiltransformations/ext.kt deleted file mode 100644 index 80dbabb..0000000 --- a/transformations/src/main/java/com/commit451/coiltransformations/ext.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.commit451.coiltransformations - -import coil.size.Dimension - -/** - * If this is a [Dimension.Pixels] value, return its number of pixels. Else, invoke and return - * the value from [block]. - */ -internal inline fun Dimension.pxOrElse(block: () -> Int): Int { - return if (this is Dimension.Pixels) px else block() -}