Removes time measuring functions from RoboHash
This commit is contained in:
@@ -13,8 +13,6 @@ import coil.request.ImageRequest
|
|||||||
import coil.request.Options
|
import coil.request.Options
|
||||||
import okio.Buffer
|
import okio.Buffer
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import kotlin.time.ExperimentalTime
|
|
||||||
import kotlin.time.measureTimedValue
|
|
||||||
|
|
||||||
private fun toHex(color: Color): String {
|
private fun toHex(color: Color): String {
|
||||||
val argb = color.toArgb()
|
val argb = color.toArgb()
|
||||||
@@ -66,26 +64,20 @@ class HashImageFetcher(
|
|||||||
private val data: Uri
|
private val data: Uri
|
||||||
) : Fetcher {
|
) : Fetcher {
|
||||||
|
|
||||||
@OptIn(ExperimentalTime::class)
|
|
||||||
override suspend fun fetch(): SourceResult {
|
override suspend fun fetch(): SourceResult {
|
||||||
val (value, elapsed) = measureTimedValue {
|
val source = try {
|
||||||
val source = try {
|
Buffer().apply { write(svgString(data.toString()).toByteArray()) }
|
||||||
Buffer().apply { write(svgString(data.toString()).toByteArray()) }
|
} finally {
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
|
|
||||||
SourceResult(
|
|
||||||
source = ImageSource(source, context),
|
|
||||||
mimeType = null,
|
|
||||||
dataSource = DataSource.MEMORY
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
println("Elapsed: $elapsed")
|
|
||||||
|
|
||||||
return value
|
return SourceResult(
|
||||||
|
source = ImageSource(source, context),
|
||||||
|
mimeType = null,
|
||||||
|
dataSource = DataSource.MEMORY
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class Factory : Fetcher.Factory<Uri> {
|
object Factory : Fetcher.Factory<Uri> {
|
||||||
override fun create(data: Uri, options: Options, imageLoader: ImageLoader): Fetcher {
|
override fun create(data: Uri, options: Options, imageLoader: ImageLoader): Fetcher {
|
||||||
return HashImageFetcher(options.context, data)
|
return HashImageFetcher(options.context, data)
|
||||||
}
|
}
|
||||||
@@ -96,7 +88,7 @@ object Robohash {
|
|||||||
return ImageRequest
|
return ImageRequest
|
||||||
.Builder(context)
|
.Builder(context)
|
||||||
.data("robohash:$message")
|
.data("robohash:$message")
|
||||||
.fetcherFactory(HashImageFetcher.Factory())
|
.fetcherFactory(HashImageFetcher.Factory)
|
||||||
.crossfade(100)
|
.crossfade(100)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user