Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More injection for WeatherApi #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

afaucogney
Copy link

As discussed in this issue stephanenicolas/toothpick#244, here is a version with more injections for the WeartherApi.

The WeatherApi just inject the RetrofitClient and its recursive dependencies. I'm not sure this is the best way of doing with TP and Retrofit, but I think this is a good example to discuss and then push the best solution.

This PR also update the dep and sdk versions

@@ -20,7 +20,7 @@ android {
}
}
buildTypes.each {
it.buildConfigField 'String', 'WEATHER_API_KEY', "\"<YOUR WEATHER_API_KEY>\""
it.buildConfigField 'String', 'WEATHER_API_KEY', "\"c1302d276960198b7803920222ab1dfb\""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets make sure we dont expose your api key here ;)

class HttpClientProvider @Inject constructor(@Named("application") var application: Application) : Provider<OkHttpClient> {

companion object {
private val sizeOfHttpCache: Long = 10 * 1024 * 1024 // 10 MiB
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix up the naming here so we have uppercase underscore naming instead.
SIZE_OF_CACHE

clientBuilder.addNetworkInterceptor(CacheControlInterceptor(application))
return clientBuilder.build()
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

.addConverterFactory(retrofit2.converter.moshi.MoshiConverterFactory.create())
.build()
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

bind(Geocoder::class.java).toProviderInstance(GeocoderProvider(application))
bind(CompositeDisposable::class.java).toProviderInstance(CompositeDisposableProvider())

bind(String::class.java).withName("url").toInstance(WeatherService.BASE_URL)
bind(OkHttpClient::class.java).withName("okHttpClient").toProviderInstance(HttpClientProvider(application))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so sure we need the @nAmed injection here as we are utilizing only one provider / instance in this app of the OkHttpClient, Retrofit instance and WeatherAPI. Is there a benefit here for named injection that Im missing ?

}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:3.1.0-alpha01'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets just bump this to 3.0.0 to avoid having to use an alpha version

@ekamp
Copy link
Owner

ekamp commented Nov 27, 2017

Thanks for this PR @afaucogney ! A few questions regarding the named injections, as I feel just normal providers without named instances in this case should do the trick. Besides that we should just upgrade to GAP 3.0.0 to avoid using an alpha version. Again thanks a lot this looks great! Let me know what you think, Ill make sure to get back to you a lot faster this time, havent have too much time to check this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants