Forked from JorgeCastilloPrz/gist:615a3ce6956eec47d2ca
Created
December 9, 2015 01:30
-
-
Save AfzalivE/8ae077720a3a1e3e9ac6 to your computer and use it in GitHub Desktop.
Dagger ContextModule
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
/** | |
* A module for dependencies which require a {@link android.content.Context} or | |
* {@link android.app.Application} to create. | |
*/ | |
@Module( | |
library = true | |
) | |
public class ContextModule { | |
private Context appContext; | |
public ContextModule(Context appContext) { | |
this.appContext = appContext; | |
} | |
@Provides | |
public Context provideAppContext() { | |
return appContext; | |
} | |
@Provides | |
@Singleton | |
public DataController provideDataController(Context appContext) { | |
return new DataController(appContext); | |
} | |
@Provides | |
@Named("rest provider") | |
@Singleton | |
public AnimalProvider provideRestAnimalProvider(Context appContext) { | |
return new RestAnimalProvider(appContext); | |
} | |
@Provides | |
@Named("persistence provider") | |
@Singleton | |
public AnimalProvider providePersistenceAnimalProvider(Context appContext) { | |
return new PersistenceAnimalProvider(appContext); | |
} | |
@Provides | |
@Singleton | |
public AbstractFontFactory provideFontFactory(Context appContext) { | |
return new RobotoFontFactory(appContext); | |
} | |
@Provides | |
@Singleton | |
public GoogleApiClient provideGoogleApiClient(Context appContext) { | |
return new GoogleApiClient.Builder(appContext) | |
.addApi(Plus.API) | |
.addScope(Plus.SCOPE_PLUS_LOGIN) | |
.build(); | |
} | |
@Provides | |
@Singleton | |
public LocationManager provideLocationManager(Context appContext) { | |
return (LocationManager) appContext.getSystemService(Context.LOCATION_SERVICE); | |
} | |
@Provides | |
@Singleton | |
public LocationController provideLocationController(Context appContext, LocationManager locationManager) { | |
return new LocationController(appContext, locationManager); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment