Skip to content

Instantly share code, notes, and snippets.

View allidoiswarren's full-sized avatar

Warren Smith allidoiswarren

View GitHub Profile
val retrofit = Retrofit.Builder()
.baseUrl("https://api.gdax.com/")
.addConverterFactory(MoshiMigrationConverter(MoshiConverterFactory.create()))
.addConverterFactory(GsonConverterFactory.create())
.build()
class MoshiMigrationConverter(private val moshiConverterFactory: MoshiConverterFactory)
: Converter.Factory() {
override fun responseBodyConverter(
type: Type,
annotations: Array<Annotation>,
retrofit: Retrofit): Converter<ResponseBody, *>? {
for (annotation in annotations) {
if (annotation.annotationClass == Moshi::class) {
return moshiConverterFactory.responseBodyConverter(type, annotations, retrofit)
@Target(AnnotationTarget.FUNCTION)
@Retention(RUNTIME)
annotation class Moshi
interface GdaxApi {
@GET("products") fun products(): Single<List<Product>>
@Moshi @GET("products") fun productsMoshi(): Single<List<Product>>
}
@Provides fun cache() = LruCache() // LruCache is bound
@Provides fun cache(): Cache = LruCache() // Cache is bound
@Component(modules = [AppModule::class, NetworkModule::class])
@Inject lateinit var foo: Set<@JvmSuppressWildcards Foo>
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target(AnnotationTarget.FIELD, AnnotationTarget.FUNCTION, AnnotationTarget.VALUE_PARAMETER)
annotation class AppContext
@Module abstract class AppModule {
@Binds abstract fun context(app: Application): Context
@Module companion object {
// Static @Provides
}
}
@Module object NetworkModule {
@Provides @JvmStatic fun httpClient() = OkHttpClient.Builder().build()
}