-
-
Save skydoves/feec92e1a113c2fe8c2406974f60da3e to your computer and use it in GitHub Desktop.
call_adapter_factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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