com.deque.networking.models.ResultCallAdapterFactory.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of axe-devtools-android-data Show documentation
Show all versions of axe-devtools-android-data Show documentation
The Axe Devtools Android Data Library
package com.deque.networking.models
import retrofit2.Call
import retrofit2.CallAdapter
import retrofit2.Retrofit
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
@Suppress("UNCHECKED_CAST")
class ResultCallAdapterFactory : CallAdapter.Factory() {
override fun get(
returnType: Type,
annotations: Array,
retrofit: Retrofit
): CallAdapter<*, *>? {
if (getRawType(returnType) != Call::class.java || returnType !is ParameterizedType) {
return null
}
val upperBound = getParameterUpperBound(0, returnType)
return if (upperBound is ParameterizedType && upperBound.rawType == Result::class.java) {
object : CallAdapter>> {
override fun responseType(): Type = getParameterUpperBound(0, upperBound)
override fun adapt(call: Call): Call> =
ResultCall(call) as Call>
}
} else {
null
}
}
}