Created
July 2, 2017 22:11
-
-
Save dptsolutions/e14bc68d681203c66924b500d4a29923 to your computer and use it in GitHub Desktop.
Example AppGlideModule Injecting OkHttpClient using Dagger 2
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
/** | |
* {@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