diff options
author | Sergei Kozelko <KozelkoS@yandex.ru> | 2022-12-15 12:23:41 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-15 12:23:41 +0000 |
commit | 20c729244e1d18f8b9b4232d303dbbf6f4761294 (patch) | |
tree | dfb7c5d98580cb481c74848b7492d848d23cb3a4 | |
parent | 99f10bddbc48c01ddd77a1f40d17da1b403831bc (diff) | |
download | infinity-for-reddit-20c729244e1d18f8b9b4232d303dbbf6f4761294.tar infinity-for-reddit-20c729244e1d18f8b9b4232d303dbbf6f4761294.tar.gz infinity-for-reddit-20c729244e1d18f8b9b4232d303dbbf6f4761294.tar.bz2 infinity-for-reddit-20c729244e1d18f8b9b4232d303dbbf6f4761294.tar.lz infinity-for-reddit-20c729244e1d18f8b9b4232d303dbbf6f4761294.tar.xz infinity-for-reddit-20c729244e1d18f8b9b4232d303dbbf6f4761294.tar.zst infinity-for-reddit-20c729244e1d18f8b9b4232d303dbbf6f4761294.zip |
Clean up NetworkModule (#1276)
Rename prefixes from `provides` to `provide`
Add Named annotations to all OkHttp and Retrofit providers
Remove RPAN OkHttp client
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java index 8af8fdb6..8638ea8b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java @@ -22,8 +22,9 @@ import retrofit2.converter.scalars.ScalarsConverterFactory; abstract class NetworkModule { @Provides + @Named("base") @Singleton - static OkHttpClient providesBaseOkhttp() { + static OkHttpClient provideBaseOkhttp() { return new OkHttpClient.Builder() .connectTimeout(30, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) @@ -32,8 +33,9 @@ abstract class NetworkModule { } @Provides + @Named("base") @Singleton - static Retrofit providesBaseRetrofit(OkHttpClient okHttpClient) { + static Retrofit provideBaseRetrofit(@Named("base") OkHttpClient okHttpClient) { return new Retrofit.Builder() .baseUrl(APIUtils.API_BASE_URI) .client(okHttpClient) @@ -44,19 +46,20 @@ abstract class NetworkModule { } @Provides - static ConnectionPool providesConnectionPool() { + static ConnectionPool provideConnectionPool() { return new ConnectionPool(0, 1, TimeUnit.NANOSECONDS); } @Provides @Named("no_oauth") - static Retrofit provideRetrofit(Retrofit retrofit) { + static Retrofit provideRetrofit(@Named("base") Retrofit retrofit) { return retrofit; } @Provides @Named("oauth") - static Retrofit providesOAuthRetrofit(Retrofit retrofit, @Named("default") OkHttpClient okHttpClient) { + static Retrofit provideOAuthRetrofit(@Named("base") Retrofit retrofit, + @Named("default") OkHttpClient okHttpClient) { return retrofit.newBuilder() .baseUrl(APIUtils.OAUTH_API_BASE_URI) .client(okHttpClient) @@ -66,8 +69,8 @@ abstract class NetworkModule { @Provides @Named("default") @Singleton - static OkHttpClient provideOkHttpClient(OkHttpClient httpClient, - Retrofit retrofit, + static OkHttpClient provideOkHttpClient(@Named("base") OkHttpClient httpClient, + @Named("base") Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase, @Named("current_account") SharedPreferences currentAccountSharedPreferences, ConnectionPool connectionPool) { @@ -80,7 +83,7 @@ abstract class NetworkModule { @Provides @Named("oauth_without_authenticator") @Singleton - static Retrofit provideOauthWithoutAuthenticatorRetrofit(Retrofit retrofit) { + static Retrofit provideOauthWithoutAuthenticatorRetrofit(@Named("base") Retrofit retrofit) { return retrofit.newBuilder() .baseUrl(APIUtils.OAUTH_API_BASE_URI) .build(); @@ -89,7 +92,7 @@ abstract class NetworkModule { @Provides @Named("upload_media") @Singleton - static Retrofit provideUploadMediaRetrofit(Retrofit retrofit) { + static Retrofit provideUploadMediaRetrofit(@Named("base") Retrofit retrofit) { return retrofit.newBuilder() .baseUrl(APIUtils.API_UPLOAD_MEDIA_URI) .build(); @@ -98,7 +101,7 @@ abstract class NetworkModule { @Provides @Named("upload_video") @Singleton - static Retrofit provideUploadVideoRetrofit(Retrofit retrofit) { + static Retrofit provideUploadVideoRetrofit(@Named("base") Retrofit retrofit) { return retrofit.newBuilder() .baseUrl(APIUtils.API_UPLOAD_VIDEO_URI) .build(); @@ -107,7 +110,7 @@ abstract class NetworkModule { @Provides @Named("download_media") @Singleton - static Retrofit provideDownloadRedditVideoRetrofit(Retrofit retrofit) { + static Retrofit provideDownloadRedditVideoRetrofit(@Named("base") Retrofit retrofit) { return retrofit.newBuilder() .baseUrl("http://localhost/") .build(); @@ -116,7 +119,7 @@ abstract class NetworkModule { @Provides @Named("gfycat") @Singleton - static Retrofit provideGfycatRetrofit(Retrofit retrofit) { + static Retrofit provideGfycatRetrofit(@Named("base") Retrofit retrofit) { return retrofit.newBuilder() .baseUrl(APIUtils.GFYCAT_API_BASE_URI) .build(); @@ -132,8 +135,8 @@ abstract class NetworkModule { @Named("redgifs") @Singleton static Retrofit provideRedgifsRetrofit(@Named("RedgifsAccessTokenAuthenticator") Interceptor accessTokenAuthenticator, - OkHttpClient httpClient, - Retrofit retrofit, + @Named("base") OkHttpClient httpClient, + @Named("base") Retrofit retrofit, ConnectionPool connectionPool) { OkHttpClient.Builder okHttpClientBuilder = httpClient.newBuilder() .addInterceptor(chain -> chain.proceed( @@ -154,7 +157,7 @@ abstract class NetworkModule { @Provides @Named("imgur") @Singleton - static Retrofit provideImgurRetrofit(Retrofit retrofit) { + static Retrofit provideImgurRetrofit(@Named("base") Retrofit retrofit) { return retrofit.newBuilder() .baseUrl(APIUtils.IMGUR_API_BASE_URI) .build(); @@ -163,7 +166,7 @@ abstract class NetworkModule { @Provides @Named("pushshift") @Singleton - static Retrofit providePushshiftRetrofit(Retrofit retrofit) { + static Retrofit providePushshiftRetrofit(@Named("base") Retrofit retrofit) { return retrofit.newBuilder() .baseUrl(APIUtils.PUSHSHIFT_API_BASE_URI) .build(); @@ -172,7 +175,7 @@ abstract class NetworkModule { @Provides @Named("reveddit") @Singleton - static Retrofit provideRevedditRetrofit(Retrofit retrofit) { + static Retrofit provideRevedditRetrofit(@Named("base") Retrofit retrofit) { return retrofit.newBuilder() .baseUrl(APIUtils.REVEDDIT_API_BASE_URI) .build(); @@ -181,7 +184,7 @@ abstract class NetworkModule { @Provides @Named("vReddIt") @Singleton - static Retrofit provideVReddItRetrofit(Retrofit retrofit) { + static Retrofit provideVReddItRetrofit(@Named("base") Retrofit retrofit) { return retrofit.newBuilder() .baseUrl("http://localhost/") .build(); @@ -190,7 +193,7 @@ abstract class NetworkModule { @Provides @Named("streamable") @Singleton - static Retrofit provideStreamableRetrofit(Retrofit retrofit) { + static Retrofit provideStreamableRetrofit(@Named("base") Retrofit retrofit) { return retrofit.newBuilder() .baseUrl(APIUtils.STREAMABLE_API_BASE_URI) .build(); |