Slide 41
Slide 41 text
G E T S T R E A M . I O
class NetworkResultCallAdapterFactory private constructor() : CallAdapter.Factory() {
override fun get(returnType: Type, annotations: Array, retrofit: Retrofit): CallAdapter<*, *>? {
if (getRawType(returnType) != Call::class.java) {
return null
}
val callType = getParameterUpperBound(0, returnType as ParameterizedType)
if (getRawType(callType) != NetworkResult::class.java) {
return null
}
val resultType = getParameterUpperBound(0, callType as ParameterizedType)
return NetworkResultCallAdapter(resultType)
}
companion object {
fun create(): NetworkResultCallAdapterFactory = NetworkResultCallAdapterFactory()
}
}
Modeling responses Retrofit CallAdapter Factory