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 ResultCallAdapterFactory : CallAdapter.Factory() { | |
override fun get( | |
returnType: Type, | |
annotations: Array<Annotation>, | |
retrofit: Retrofit | |
) = when (getRawType(returnType)) { | |
Call::class.java -> { | |
val callType = getParameterUpperBound(0, returnType as ParameterizedType) | |
when (getRawType(callType)) { | |
Result::class.java -> { |
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 ResultsCallAdapterFactory private constructor() : CallAdapter.Factory() { | |
companion object { | |
@JvmStatic | |
fun create() = ResultsCallAdapterFactory() | |
} | |
override fun get(returnType: Type, annotations: Array<Annotation>, retrofit: Retrofit): CallAdapter<*, *>? { | |
return try { | |
val enclosedType = returnType as ParameterizedType |
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
sealed class Results<out T: Any> { | |
class Success<out T: Any>(val response: T): Results<T>() | |
class Failure(val message: String, val serverError: ServerError?): Results<Nothing>() | |
object NetworkError: Results<Nothing>() | |
} | |
class ResultsCallAdapterFactory private constructor() : CallAdapter.Factory() { | |
companion object { |