Reputation: 934
Below is the following test method I have built to make my life slightly easier using Glide.
suspend fun retrieveImage(
glideRequests: GlideRequests,
uri: String,
options: (GlideRequest<Drawable>.() -> Unit)? = null,
targetCallback: ((FutureTarget<Drawable>) -> Unit)? = null
): Drawable? {
// The GlideRequest we should use to run our request
val request = glideRequests.load(uri)
// Apply the options to be used for our request
options?.invoke(request)
// Callback for our Future object so that it can be cancelled if necessary
val drawableFuture = request.submit()
targetCallback?.invoke(drawableFuture)
return try {
withContext(Dispatchers.IO) {
try {
drawableFuture.get()
} catch (unknownHostException: UnknownHostException) {
// Return null, this method was run with no network
null
} catch (interruptionException: InterruptedException) {
// Request has been cancelled
null
}
}
} catch (cancellationException: CancellationException) {
// Coroutine has been cancelled
null
}
}
It builds out to be the following for the JVM
import android.graphics.drawable.Drawable;
import com.bumptech.glide.request.FutureTarget;
import io.vadgroup.cirqle.application.GlideRequest;
import io.vadgroup.cirqle.application.GlideRequests;
import kotlinx.coroutines.Dispatchers;
import java.net.UnknownHostException;
@kotlin.Metadata(mv = {1, 1, 16}, bv = {1, 0, 3}, k = 1, d1 = {"\u00000\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u00c6\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002\u00a2\u0006\u0002\u0010\u0002J^\u0010\u0003\u001a\u0004\u0018\u00010\u00042\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\b2\u001b\b\u0002\u0010\t\u001a\u0015\u0012\u0004\u0012\u00020\u0006\u0012\u0004\u0012\u00020\u000b\u0018\u00010\n\u00a2\u0006\u0002\b\f2\u001c\b\u0002\u0010\r\u001a\u0016\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00040\u000e\u0012\u0004\u0012\u00020\u000b\u0018\u00010\nH\u0086@\u00f8\u0001\u0000\u00a2\u0006\u0002\u0010\u000f\u0082\u0002\u0004\n\u0002\b\u0019\u00a8\u0006\u0010"}, d2 = {"Lio/vadgroup/cirqle/utilities/GlideUtil;", "", "()V", "retrieveImage", "Landroid/graphics/drawable/Drawable;", "glideRequests", "error/NonExistentClass", "uri", "", "options", "Lkotlin/Function1;", "", "Lkotlin/ExtensionFunctionType;", "targetCallback", "Lcom/bumptech/glide/request/FutureTarget;", "(Lerror/NonExistentClass;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "app_debug"})
public final class GlideUtil {
public static final io.vadgroup.cirqle.utilities.GlideUtil INSTANCE = null;
@org.jetbrains.annotations.Nullable()
public final java.lang.Object retrieveImage(@org.jetbrains.annotations.NotNull()
GlideRequests glideRequests, @org.jetbrains.annotations.NotNull()
java.lang.String uri, @org.jetbrains.annotations.Nullable()
Function1<GlideRequest<android.graphics.drawable.Drawable>, kotlin.Unit> options, @org.jetbrains.annotations.Nullable()
kotlin.jvm.functions.Function1<? super com.bumptech.glide.request.FutureTarget<android.graphics.drawable.Drawable>, kotlin.Unit> targetCallback, @org.jetbrains.annotations.NotNull()
kotlin.coroutines.Continuation<? super android.graphics.drawable.Drawable> p4) {
return null;
}
private GlideUtil() {
super();
}
}
If you look at the above Java code, one can see two different Function1 objects, one with the complete Kotlin path and one without it.
I am suspecting this is happening due to a clash with Arrow-Core library I have since they also have a Function1 object. I completely removed the library, cleaned the cache and build, however, I still run across this problem.
I currently have used both Kotlin versions 1.3.70 and 1.3.71
Upvotes: 1
Views: 1262
Reputation: 934
I added the following item to the top of the import list
import kotlin.jvm.functions.*
Although greyed out and seeming to be unused, I was able to correctly build the project.
Upvotes: 2