-
Notifications
You must be signed in to change notification settings - Fork 638
/
Fetcher.kt
37 lines (32 loc) · 1.21 KB
/
Fetcher.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package coil.fetch
import android.graphics.drawable.Drawable
import coil.ImageLoader
import coil.decode.ImageSource
import coil.request.Options
/**
* A [Fetcher] translates data into either an [ImageSource] or a [Drawable].
*
* To accomplish this, fetchers fit into one of two types:
*
* - Uses the data as a key to fetch bytes from a remote source (e.g. network, disk)
* and exposes it as an [ImageSource] (e.g. [HttpUriFetcher]).
* - Reads the data directly and translates it into a [Drawable] (e.g. [BitmapFetcher]).
*/
fun interface Fetcher {
/**
* Fetch the data provided by [Factory.create] or return 'null' to delegate to the next
* [Factory] in the component registry.
*/
suspend fun fetch(): FetchResult?
fun interface Factory<T : Any> {
/**
* Return a [Fetcher] that can fetch [data] or 'null' if this factory cannot create a
* fetcher for the data.
*
* @param data The data to fetch.
* @param options A set of configuration options for this request.
* @param imageLoader The [ImageLoader] that's executing this request.
*/
fun create(data: T, options: Options, imageLoader: ImageLoader): Fetcher?
}
}