Skip to content

Instantly share code, notes, and snippets.

@dptsolutions
Created July 2, 2017 22:11
Show Gist options
  • Save dptsolutions/e14bc68d681203c66924b500d4a29923 to your computer and use it in GitHub Desktop.
Save dptsolutions/e14bc68d681203c66924b500d4a29923 to your computer and use it in GitHub Desktop.
Example AppGlideModule Injecting OkHttpClient using Dagger 2
/**
* {@link AppGlideModule} for the app
*/
@Excludes(OkHttpLibraryGlideModule.class)
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
//Below override should only be used if not using legacy modules registered via manifest
@Override
public boolean isManifestParsingEnabled() {
return false;
}
@Override
public void registerComponents(Context context, Registry registry) {
super.registerComponents(context, registry);
//This registers the OkHttpClient
//There has to be a better way to do this, but I don't see how at the moment.
ApplicationComponent applicationComponent =
((MyApplication)context.getApplicationContext()).getApplicationComponent();
registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(applicationComponent.imageHttpClient()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment