Skip to content

Instantly share code, notes, and snippets.

@skydoves
Created April 11, 2022 11:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skydoves/feec92e1a113c2fe8c2406974f60da3e to your computer and use it in GitHub Desktop.
Save skydoves/feec92e1a113c2fe8c2406974f60da3e to your computer and use it in GitHub Desktop.
call_adapter_factory
class NetworkResultCallAdapterFactory private constructor() : CallAdapter.Factory() {
override fun get(
returnType: Type,
annotations: Array<out Annotation>,
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()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment