Skip to content

Commit

Permalink
Move coil.api functions to coil and move coil.extension functio…
Browse files Browse the repository at this point in the history
…ns to respective packages. (coil-kt#453)

* Move extensions.

* Add migration aids.

* Add deprecated placeholders.

* Update API.

* Clean up.

* Update API.

* Re-add deprecated APIs.

* Remove return types.
  • Loading branch information
colinrtwhite authored Jul 9, 2020
1 parent 6e8179f commit a80c8da
Show file tree
Hide file tree
Showing 22 changed files with 297 additions and 70 deletions.
3 changes: 2 additions & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions coil-base/api/coil-base.api
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ public final class coil/collection/SparseIntArraySet {
public final fun size ()I
}

public final class coil/collection/SparseIntArraySetKt {
public static final fun addAll (Lcoil/collection/SparseIntArraySet;Lcoil/collection/SparseIntArraySet;)V
public static final fun count (Lcoil/collection/SparseIntArraySet;)I
public static final fun forEach (Lcoil/collection/SparseIntArraySet;Lkotlin/jvm/functions/Function1;)V
public static final fun isEmpty (Lcoil/collection/SparseIntArraySet;)Z
public static final fun isNotEmpty (Lcoil/collection/SparseIntArraySet;)Z
public static final fun iterator (Lcoil/collection/SparseIntArraySet;)Lkotlin/collections/IntIterator;
public static final fun minusAssign (Lcoil/collection/SparseIntArraySet;I)V
public static final fun plus (Lcoil/collection/SparseIntArraySet;Lcoil/collection/SparseIntArraySet;)Lcoil/collection/SparseIntArraySet;
public static final fun plusAssign (Lcoil/collection/SparseIntArraySet;I)V
}

public final class coil/decode/DataSource : java/lang/Enum {
public static final field DISK Lcoil/decode/DataSource;
public static final field MEMORY Lcoil/decode/DataSource;
Expand Down Expand Up @@ -581,6 +593,12 @@ public final class coil/request/Parameters$Entry {
public fun toString ()Ljava/lang/String;
}

public final class coil/request/ParametersKt {
public static final fun count (Lcoil/request/Parameters;)I
public static final fun get (Lcoil/request/Parameters;Ljava/lang/String;)Ljava/lang/Object;
public static final fun isNotEmpty (Lcoil/request/Parameters;)Z
}

public abstract interface class coil/request/RequestDisposable {
public abstract fun await (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun dispose ()V
Expand Down
50 changes: 50 additions & 0 deletions coil-base/src/main/java/coil/collection/SparseIntArraySetExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@file:JvmName("SparseIntArraySetKt")
@file:Suppress("NOTHING_TO_INLINE", "unused")

package coil.collection

/** Returns the number of elements that this set currently stores. */
inline fun SparseIntArraySet.count(): Int = size

/** Adds the element to the set. */
inline operator fun SparseIntArraySet.plusAssign(element: Int) {
add(element)
}

/** Removes the element from the set. */
inline operator fun SparseIntArraySet.minusAssign(element: Int) {
remove(element)
}

/** Return true when the set contains no elements. */
inline fun SparseIntArraySet.isEmpty(): Boolean = size == 0

/** Return true when the set contains elements. */
inline fun SparseIntArraySet.isNotEmpty(): Boolean = size != 0

/** Create and return a new set that contains the elements of [this] plus the elements of [other]. */
operator fun SparseIntArraySet.plus(other: SparseIntArraySet): SparseIntArraySet {
val new = SparseIntArraySet(size + other.size)
new.addAll(this)
new.addAll(other)
return new
}

/** Add all elements from [other] to [this]. */
fun SparseIntArraySet.addAll(other: SparseIntArraySet) {
other.forEach { add(it) }
}

/** Performs the given [action] for each element in the set. */
inline fun SparseIntArraySet.forEach(action: (element: Int) -> Unit) {
for (index in 0 until size) {
action(elementAt(index))
}
}

/** Return an iterator over the set's values. */
operator fun SparseIntArraySet.iterator(): IntIterator = object : IntIterator() {
var index = 0
override fun hasNext() = index < size
override fun nextInt() = elementAt(index++)
}
15 changes: 9 additions & 6 deletions coil-base/src/main/java/coil/extension/Parameters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
package coil.extension

import coil.request.Parameters
import coil.request.count as _count
import coil.request.get as _get
import coil.request.isNotEmpty as _isNotEmpty

/** Returns the number of parameters in this object. */
inline fun Parameters.count(): Int = size
@Deprecated("Replace `coil.extension.count` with `coil.request.count`.")
inline fun Parameters.count() = _count()

/** Return true when the set contains elements. */
inline fun Parameters.isNotEmpty(): Boolean = !isEmpty()
@Deprecated("Replace `coil.extension.isNotEmpty` with `coil.request.isNotEmpty`.")
inline fun Parameters.isNotEmpty() = _isNotEmpty()

/** Returns the value associated with [key] or null if [key] has no mapping. */
inline operator fun Parameters.get(key: String): Any? = value(key)
@Deprecated("Replace `coil.extension.get` with `coil.request.get`.")
inline operator fun Parameters.get(key: String) = _get(key)
80 changes: 35 additions & 45 deletions coil-base/src/main/java/coil/extension/SparseIntArraySets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,39 @@
package coil.extension

import coil.collection.SparseIntArraySet
import coil.collection.addAll as _addAll
import coil.collection.count as _count
import coil.collection.forEach as _forEach
import coil.collection.isEmpty as _isEmpty
import coil.collection.isNotEmpty as _isNotEmpty
import coil.collection.iterator as _iterator
import coil.collection.minusAssign as _minusAssign
import coil.collection.plus as _plus
import coil.collection.plusAssign as _plusAssign

/** Returns the number of elements that this set currently stores. */
inline fun SparseIntArraySet.count(): Int = size

/** Adds the element to the set. */
inline operator fun SparseIntArraySet.plusAssign(element: Int) {
add(element)
}

/** Removes the element from the set. */
inline operator fun SparseIntArraySet.minusAssign(element: Int) {
remove(element)
}

/** Return true when the set contains no elements. */
inline fun SparseIntArraySet.isEmpty(): Boolean = size == 0

/** Return true when the set contains elements. */
inline fun SparseIntArraySet.isNotEmpty(): Boolean = size != 0

/** Create and return a new set that contains the elements of [this] plus the elements of [other]. */
operator fun SparseIntArraySet.plus(other: SparseIntArraySet): SparseIntArraySet {
val new = SparseIntArraySet(size + other.size)
new.addAll(this)
new.addAll(other)
return new
}

/** Add all elements from [other] to [this]. */
fun SparseIntArraySet.addAll(other: SparseIntArraySet) {
other.forEach { add(it) }
}

/** Performs the given [action] for each element in the set. */
inline fun SparseIntArraySet.forEach(action: (element: Int) -> Unit) {
for (index in 0 until size) {
action(elementAt(index))
}
}

/** Return an iterator over the set's values. */
operator fun SparseIntArraySet.iterator(): IntIterator = object : IntIterator() {
var index = 0
override fun hasNext() = index < size
override fun nextInt() = elementAt(index++)
}
@Deprecated("Replace `coil.extension.count` with `coil.collection.count`.")
inline fun SparseIntArraySet.count() = _count()

@Deprecated("Replace `coil.extension.plusAssign` with `coil.collection.plusAssign`.")
inline operator fun SparseIntArraySet.plusAssign(element: Int) = _plusAssign(element)

@Deprecated("Replace `coil.extension.minusAssign` with `coil.collection.minusAssign`.")
inline operator fun SparseIntArraySet.minusAssign(element: Int) = _minusAssign(element)

@Deprecated("Replace `coil.extension.isEmpty` with `coil.collection.isEmpty`.")
inline fun SparseIntArraySet.isEmpty() = _isEmpty()

@Deprecated("Replace `coil.extension.isNotEmpty` with `coil.collection.isNotEmpty`.")
inline fun SparseIntArraySet.isNotEmpty() = _isNotEmpty()

@Deprecated("Replace `coil.extension.plus` with `coil.collection.plus`.")
operator fun SparseIntArraySet.plus(other: SparseIntArraySet) = _plus(other)

@Deprecated("Replace `coil.extension.addAll` with `coil.collection.addAll`.")
fun SparseIntArraySet.addAll(other: SparseIntArraySet) = _addAll(other)

@Deprecated("Replace `coil.extension.forEach` with `coil.collection.forEach`.")
inline fun SparseIntArraySet.forEach(action: (element: Int) -> Unit) = _forEach(action)

@Deprecated("Replace `coil.extension.iterator` with `coil.collection.iterator`.")
operator fun SparseIntArraySet.iterator() = _iterator()
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.annotation.VisibleForTesting
import androidx.core.util.set
import coil.bitmappool.BitmapPool
import coil.collection.SparseIntArraySet
import coil.extension.plusAssign
import coil.collection.plusAssign
import coil.util.Logger
import coil.util.identityHashCode
import coil.util.log
Expand Down
4 changes: 2 additions & 2 deletions coil-base/src/main/java/coil/request/Parameters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Parameters private constructor(
*/
@JvmOverloads
fun set(key: String, value: Any?, cacheKey: String? = value?.toString()) = apply {
this.map[key] = Entry(value, cacheKey)
map[key] = Entry(value, cacheKey)
}

/**
Expand All @@ -99,7 +99,7 @@ class Parameters private constructor(
* @param key The parameter's key.
*/
fun remove(key: String) = apply {
this.map.remove(key)
map.remove(key)
}

/** Create a new [Parameters] instance. */
Expand Down
13 changes: 13 additions & 0 deletions coil-base/src/main/java/coil/request/ParametersExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@file:JvmName("ParametersKt")
@file:Suppress("NOTHING_TO_INLINE", "unused")

package coil.request

/** Returns the number of parameters in this object. */
inline fun Parameters.count(): Int = size

/** Return true when the set contains elements. */
inline fun Parameters.isNotEmpty(): Boolean = !isEmpty()

/** Returns the value associated with [key] or null if [key] has no mapping. */
inline operator fun Parameters.get(key: String): Any? = value(key)
5 changes: 5 additions & 0 deletions coil-gif/api/coil-gif.api
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ public final class coil/extension/Gifs {
public static final fun repeatCount (Lcoil/request/Parameters;)Ljava/lang/Integer;
}

public final class coil/request/Gifs {
public static final fun repeatCount (Lcoil/request/ImageRequest$Builder;I)Lcoil/request/ImageRequest$Builder;
public static final fun repeatCount (Lcoil/request/Parameters;)Ljava/lang/Integer;
}

2 changes: 1 addition & 1 deletion coil-gif/src/main/java/coil/decode/GifDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.os.Build.VERSION.SDK_INT
import coil.annotation.InternalCoilApi
import coil.bitmappool.BitmapPool
import coil.drawable.MovieDrawable
import coil.extension.repeatCount
import coil.request.repeatCount
import coil.size.Size
import okio.BufferedSource
import okio.buffer
Expand Down
2 changes: 1 addition & 1 deletion coil-gif/src/main/java/coil/decode/ImageDecoderDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import androidx.core.util.component2
import coil.annotation.InternalCoilApi
import coil.bitmappool.BitmapPool
import coil.drawable.ScaleDrawable
import coil.extension.repeatCount
import coil.request.repeatCount
import coil.size.PixelSize
import coil.size.Size
import okio.BufferedSource
Expand Down
14 changes: 14 additions & 0 deletions coil-gif/src/main/java/coil/extension/Deprecated.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@file:Suppress("unused")
@file:JvmName("Gifs")

package coil.extension

import coil.request.ImageRequest
import coil.request.Parameters
import coil.request.repeatCount as _repeatCount

@Deprecated("Replace `coil.extension.repeatCount` with `coil.request.repeatCount`.")
fun ImageRequest.Builder.repeatCount(repeatCount: Int) = _repeatCount(repeatCount)

@Deprecated("Replace `coil.extension.repeatCount` with `coil.request.repeatCount`.")
fun Parameters.repeatCount() = _repeatCount()
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
@file:Suppress("unused")
@file:JvmName("Gifs")

package coil.extension
package coil.request

import android.graphics.drawable.AnimatedImageDrawable
import android.graphics.drawable.Drawable
import coil.decode.GifDecoder.Companion.REPEAT_COUNT_KEY
import coil.drawable.MovieDrawable
import coil.request.ImageRequest
import coil.request.Parameters

/**
* Set the number of times to repeat the animation if the result is an animated [Drawable].
Expand Down
2 changes: 1 addition & 1 deletion coil-sample/src/main/java/coil/sample/ImageListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import coil.api.load
import coil.load
import coil.sample.ImageListAdapter.ViewHolder
import kotlin.math.ceil
import kotlin.math.roundToInt
Expand Down
2 changes: 1 addition & 1 deletion coil-sample/src/main/java/coil/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import androidx.core.view.updatePadding
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import androidx.recyclerview.widget.StaggeredGridLayoutManager.VERTICAL
import coil.api.load
import coil.load
import coil.sample.databinding.ActivityMainBinding
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect
Expand Down
20 changes: 20 additions & 0 deletions coil-singleton/api/coil-singleton.api
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ public abstract interface class coil/ImageLoaderFactory {
public abstract fun newImageLoader ()Lcoil/ImageLoader;
}

public final class coil/ImageViews {
public static final fun clear (Landroid/widget/ImageView;)V
public static final synthetic fun load (Landroid/widget/ImageView;ILcoil/ImageLoader;Lkotlin/jvm/functions/Function1;)Lcoil/request/RequestDisposable;
public static final synthetic fun load (Landroid/widget/ImageView;Landroid/graphics/Bitmap;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;)Lcoil/request/RequestDisposable;
public static final synthetic fun load (Landroid/widget/ImageView;Landroid/graphics/drawable/Drawable;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;)Lcoil/request/RequestDisposable;
public static final synthetic fun load (Landroid/widget/ImageView;Landroid/net/Uri;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;)Lcoil/request/RequestDisposable;
public static final synthetic fun load (Landroid/widget/ImageView;Ljava/io/File;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;)Lcoil/request/RequestDisposable;
public static final synthetic fun load (Landroid/widget/ImageView;Ljava/lang/String;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;)Lcoil/request/RequestDisposable;
public static final synthetic fun load (Landroid/widget/ImageView;Lokhttp3/HttpUrl;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;)Lcoil/request/RequestDisposable;
public static synthetic fun load$default (Landroid/widget/ImageView;ILcoil/ImageLoader;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcoil/request/RequestDisposable;
public static synthetic fun load$default (Landroid/widget/ImageView;Landroid/graphics/Bitmap;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcoil/request/RequestDisposable;
public static synthetic fun load$default (Landroid/widget/ImageView;Landroid/graphics/drawable/Drawable;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcoil/request/RequestDisposable;
public static synthetic fun load$default (Landroid/widget/ImageView;Landroid/net/Uri;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcoil/request/RequestDisposable;
public static synthetic fun load$default (Landroid/widget/ImageView;Ljava/io/File;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcoil/request/RequestDisposable;
public static synthetic fun load$default (Landroid/widget/ImageView;Ljava/lang/String;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcoil/request/RequestDisposable;
public static synthetic fun load$default (Landroid/widget/ImageView;Lokhttp3/HttpUrl;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcoil/request/RequestDisposable;
public static final synthetic fun loadAny (Landroid/widget/ImageView;Ljava/lang/Object;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;)Lcoil/request/RequestDisposable;
public static synthetic fun loadAny$default (Landroid/widget/ImageView;Ljava/lang/Object;Lcoil/ImageLoader;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcoil/request/RequestDisposable;
}

public final class coil/api/ImageViews {
public static final fun clear (Landroid/widget/ImageView;)V
public static final synthetic fun load (Landroid/widget/ImageView;ILcoil/ImageLoader;Lkotlin/jvm/functions/Function1;)Lcoil/request/RequestDisposable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
@file:JvmName("ImageViews")
@file:Suppress("unused")

package coil.api
package coil

import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.net.Uri
import android.widget.ImageView
import androidx.annotation.DrawableRes
import coil.Coil
import coil.ImageLoader
import coil.request.ImageRequest
import coil.request.RequestDisposable
import coil.util.CoilUtils
Expand Down
Loading

0 comments on commit a80c8da

Please sign in to comment.