7
7
import dagger .Provides ;
8
8
import fr .free .nrw .commons .BetaConstants ;
9
9
import fr .free .nrw .commons .BuildConfig ;
10
+ import fr .free .nrw .commons .OkHttpConnectionFactory ;
10
11
import fr .free .nrw .commons .actions .PageEditClient ;
11
12
import fr .free .nrw .commons .actions .PageEditInterface ;
12
13
import fr .free .nrw .commons .actions .ThanksInterface ;
27
28
import fr .free .nrw .commons .upload .UploadInterface ;
28
29
import fr .free .nrw .commons .upload .WikiBaseInterface ;
29
30
import fr .free .nrw .commons .upload .depicts .DepictsInterface ;
31
+ import fr .free .nrw .commons .wikidata .CommonsServiceFactory ;
30
32
import fr .free .nrw .commons .wikidata .WikidataInterface ;
31
33
import java .io .File ;
32
34
import java .util .Locale ;
39
41
import okhttp3 .logging .HttpLoggingInterceptor ;
40
42
import okhttp3 .logging .HttpLoggingInterceptor .Level ;
41
43
import fr .free .nrw .commons .auth .csrf .CsrfTokenClient ;
42
- import org .wikipedia .dataclient . ServiceFactory ;
44
+ import org .wikipedia .AppAdapter ;
43
45
import org .wikipedia .dataclient .WikiSite ;
44
46
import org .wikipedia .json .GsonUtil ;
45
47
import fr .free .nrw .commons .auth .login .LoginClient ;
@@ -53,7 +55,6 @@ public class NetworkingModule {
53
55
54
56
public static final long OK_HTTP_CACHE_SIZE = 10 * 1024 * 1024 ;
55
57
56
- public static final String NAMED_COMMONS_WIKI_SITE = "commons-wikisite" ;
57
58
private static final String NAMED_WIKI_DATA_WIKI_SITE = "wikidata-wikisite" ;
58
59
private static final String NAMED_WIKI_PEDIA_WIKI_SITE = "wikipedia-wikisite" ;
59
60
@@ -75,6 +76,12 @@ public OkHttpClient provideOkHttpClient(Context context,
75
76
.build ();
76
77
}
77
78
79
+ @ Provides
80
+ @ Singleton
81
+ public CommonsServiceFactory serviceFactory () {
82
+ return new CommonsServiceFactory (AppAdapter .get ().getOkHttpClient ());
83
+ }
84
+
78
85
@ Provides
79
86
@ Singleton
80
87
public HttpLoggingInterceptor provideHttpLoggingInterceptor () {
@@ -110,14 +117,14 @@ public CsrfTokenClient provideCommonsCsrfTokenClient(SessionManager sessionManag
110
117
111
118
@ Provides
112
119
@ Singleton
113
- public CsrfTokenInterface provideCsrfTokenInterface (@ Named ( NAMED_COMMONS_WIKI_SITE ) WikiSite commonsWikiSite ) {
114
- return ServiceFactory . get ( commonsWikiSite , BuildConfig .COMMONS_URL , CsrfTokenInterface .class );
120
+ public CsrfTokenInterface provideCsrfTokenInterface (CommonsServiceFactory serviceFactory ) {
121
+ return serviceFactory . create ( BuildConfig .COMMONS_URL , CsrfTokenInterface .class );
115
122
}
116
123
117
124
@ Provides
118
125
@ Singleton
119
- public LoginInterface provideLoginInterface (@ Named ( NAMED_COMMONS_WIKI_SITE ) WikiSite commonsWikiSite ) {
120
- return ServiceFactory . get ( commonsWikiSite , BuildConfig .COMMONS_URL , LoginInterface .class );
126
+ public LoginInterface provideLoginInterface (CommonsServiceFactory serviceFactory ) {
127
+ return serviceFactory . create ( BuildConfig .COMMONS_URL , LoginInterface .class );
121
128
}
122
129
123
130
@ Provides
@@ -142,13 +149,6 @@ public HttpUrl provideToolsForgeUrl() {
142
149
return HttpUrl .parse (TOOLS_FORGE_URL );
143
150
}
144
151
145
- @ Provides
146
- @ Singleton
147
- @ Named (NAMED_COMMONS_WIKI_SITE )
148
- public WikiSite provideCommonsWikiSite () {
149
- return new WikiSite (BuildConfig .COMMONS_URL );
150
- }
151
-
152
152
@ Provides
153
153
@ Singleton
154
154
@ Named (NAMED_WIKI_DATA_WIKI_SITE )
@@ -169,40 +169,40 @@ public Gson provideGson() {
169
169
170
170
@ Provides
171
171
@ Singleton
172
- public ReviewInterface provideReviewInterface (@ Named ( NAMED_COMMONS_WIKI_SITE ) WikiSite commonsWikiSite ) {
173
- return ServiceFactory . get ( commonsWikiSite , BuildConfig .COMMONS_URL , ReviewInterface .class );
172
+ public ReviewInterface provideReviewInterface (CommonsServiceFactory serviceFactory ) {
173
+ return serviceFactory . create ( BuildConfig .COMMONS_URL , ReviewInterface .class );
174
174
}
175
175
176
176
@ Provides
177
177
@ Singleton
178
- public DepictsInterface provideDepictsInterface (@ Named ( NAMED_WIKI_DATA_WIKI_SITE ) WikiSite wikidataWikiSite ) {
179
- return ServiceFactory . get ( wikidataWikiSite , BuildConfig .WIKIDATA_URL , DepictsInterface .class );
178
+ public DepictsInterface provideDepictsInterface (CommonsServiceFactory serviceFactory ) {
179
+ return serviceFactory . create ( BuildConfig .WIKIDATA_URL , DepictsInterface .class );
180
180
}
181
181
182
182
@ Provides
183
183
@ Singleton
184
- public WikiBaseInterface provideWikiBaseInterface (@ Named ( NAMED_COMMONS_WIKI_SITE ) WikiSite commonsWikiSite ) {
185
- return ServiceFactory . get ( commonsWikiSite , BuildConfig .COMMONS_URL , WikiBaseInterface .class );
184
+ public WikiBaseInterface provideWikiBaseInterface (CommonsServiceFactory serviceFactory ) {
185
+ return serviceFactory . create ( BuildConfig .COMMONS_URL , WikiBaseInterface .class );
186
186
}
187
187
188
188
@ Provides
189
189
@ Singleton
190
- public UploadInterface provideUploadInterface (@ Named ( NAMED_COMMONS_WIKI_SITE ) WikiSite commonsWikiSite ) {
191
- return ServiceFactory . get ( commonsWikiSite , BuildConfig .COMMONS_URL , UploadInterface .class );
190
+ public UploadInterface provideUploadInterface (CommonsServiceFactory serviceFactory ) {
191
+ return serviceFactory . create ( BuildConfig .COMMONS_URL , UploadInterface .class );
192
192
}
193
193
194
194
@ Named ("commons-page-edit-service" )
195
195
@ Provides
196
196
@ Singleton
197
- public PageEditInterface providePageEditService (@ Named ( NAMED_COMMONS_WIKI_SITE ) WikiSite commonsWikiSite ) {
198
- return ServiceFactory . get ( commonsWikiSite , BuildConfig .COMMONS_URL , PageEditInterface .class );
197
+ public PageEditInterface providePageEditService (CommonsServiceFactory serviceFactory ) {
198
+ return serviceFactory . create ( BuildConfig .COMMONS_URL , PageEditInterface .class );
199
199
}
200
200
201
201
@ Named ("wikidata-page-edit-service" )
202
202
@ Provides
203
203
@ Singleton
204
- public PageEditInterface provideWikiDataPageEditService (@ Named ( NAMED_WIKI_DATA_WIKI_SITE ) WikiSite wikiDataWikiSite ) {
205
- return ServiceFactory . get ( wikiDataWikiSite , BuildConfig .WIKIDATA_URL , PageEditInterface .class );
204
+ public PageEditInterface provideWikiDataPageEditService (CommonsServiceFactory serviceFactory ) {
205
+ return serviceFactory . create ( BuildConfig .WIKIDATA_URL , PageEditInterface .class );
206
206
}
207
207
208
208
@ Named ("commons-page-edit" )
@@ -215,8 +215,8 @@ public PageEditClient provideCommonsPageEditClient(@Named(NAMED_COMMONS_CSRF) Cs
215
215
216
216
@ Provides
217
217
@ Singleton
218
- public MediaInterface provideMediaInterface (@ Named ( NAMED_COMMONS_WIKI_SITE ) WikiSite commonsWikiSite ) {
219
- return ServiceFactory . get ( commonsWikiSite , BuildConfig .COMMONS_URL , MediaInterface .class );
218
+ public MediaInterface provideMediaInterface (CommonsServiceFactory serviceFactory ) {
219
+ return serviceFactory . create ( BuildConfig .COMMONS_URL , MediaInterface .class );
220
220
}
221
221
222
222
/**
@@ -227,52 +227,44 @@ public MediaInterface provideMediaInterface(@Named(NAMED_COMMONS_WIKI_SITE) Wiki
227
227
*/
228
228
@ Provides
229
229
@ Singleton
230
- public WikidataMediaInterface provideWikidataMediaInterface (
231
- @ Named (NAMED_COMMONS_WIKI_SITE ) final WikiSite commonsWikiSite ) {
232
- return ServiceFactory .get (commonsWikiSite ,
233
- BetaConstants .COMMONS_URL , WikidataMediaInterface .class );
230
+ public WikidataMediaInterface provideWikidataMediaInterface (CommonsServiceFactory serviceFactory ) {
231
+ return serviceFactory .create (BetaConstants .COMMONS_URL , WikidataMediaInterface .class );
234
232
}
235
233
236
234
@ Provides
237
235
@ Singleton
238
- public MediaDetailInterface providesMediaDetailInterface (@ Named ( NAMED_COMMONS_WIKI_SITE ) WikiSite commonsWikisite ) {
239
- return ServiceFactory . get ( commonsWikisite , BuildConfig .COMMONS_URL , MediaDetailInterface .class );
236
+ public MediaDetailInterface providesMediaDetailInterface (CommonsServiceFactory serviceFactory ) {
237
+ return serviceFactory . create ( BuildConfig .COMMONS_URL , MediaDetailInterface .class );
240
238
}
241
239
242
240
@ Provides
243
241
@ Singleton
244
- public CategoryInterface provideCategoryInterface (
245
- @ Named (NAMED_COMMONS_WIKI_SITE ) WikiSite commonsWikiSite ) {
246
- return ServiceFactory
247
- .get (commonsWikiSite , BuildConfig .COMMONS_URL , CategoryInterface .class );
242
+ public CategoryInterface provideCategoryInterface (CommonsServiceFactory serviceFactory ) {
243
+ return serviceFactory .create (BuildConfig .COMMONS_URL , CategoryInterface .class );
248
244
}
249
245
250
246
@ Provides
251
247
@ Singleton
252
- public ThanksInterface provideThanksInterface (
253
- @ Named (NAMED_COMMONS_WIKI_SITE ) WikiSite commonsWikiSite ) {
254
- return ServiceFactory
255
- .get (commonsWikiSite , BuildConfig .COMMONS_URL , ThanksInterface .class );
248
+ public ThanksInterface provideThanksInterface (CommonsServiceFactory serviceFactory ) {
249
+ return serviceFactory .create (BuildConfig .COMMONS_URL , ThanksInterface .class );
256
250
}
257
251
258
252
@ Provides
259
253
@ Singleton
260
- public NotificationInterface provideNotificationInterface (
261
- @ Named (NAMED_COMMONS_WIKI_SITE ) WikiSite commonsWikiSite ) {
262
- return ServiceFactory
263
- .get (commonsWikiSite , BuildConfig .COMMONS_URL , NotificationInterface .class );
254
+ public NotificationInterface provideNotificationInterface (CommonsServiceFactory serviceFactory ) {
255
+ return serviceFactory .create (BuildConfig .COMMONS_URL , NotificationInterface .class );
264
256
}
265
257
266
258
@ Provides
267
259
@ Singleton
268
- public UserInterface provideUserInterface (@ Named ( NAMED_COMMONS_WIKI_SITE ) WikiSite commonsWikiSite ) {
269
- return ServiceFactory . get ( commonsWikiSite , BuildConfig .COMMONS_URL , UserInterface .class );
260
+ public UserInterface provideUserInterface (CommonsServiceFactory serviceFactory ) {
261
+ return serviceFactory . create ( BuildConfig .COMMONS_URL , UserInterface .class );
270
262
}
271
263
272
264
@ Provides
273
265
@ Singleton
274
- public WikidataInterface provideWikidataInterface (@ Named ( NAMED_WIKI_DATA_WIKI_SITE ) WikiSite wikiDataWikiSite ) {
275
- return ServiceFactory . get ( wikiDataWikiSite , BuildConfig .WIKIDATA_URL , WikidataInterface .class );
266
+ public WikidataInterface provideWikidataInterface (CommonsServiceFactory serviceFactory ) {
267
+ return serviceFactory . create ( BuildConfig .WIKIDATA_URL , WikidataInterface .class );
276
268
}
277
269
278
270
/**
@@ -281,8 +273,8 @@ public WikidataInterface provideWikidataInterface(@Named(NAMED_WIKI_DATA_WIKI_SI
281
273
*/
282
274
@ Provides
283
275
@ Singleton
284
- public PageMediaInterface providePageMediaInterface (@ Named (NAMED_LANGUAGE_WIKI_PEDIA_WIKI_SITE ) WikiSite wikiSite ) {
285
- return ServiceFactory . get ( wikiSite , wikiSite .url (), PageMediaInterface .class );
276
+ public PageMediaInterface providePageMediaInterface (@ Named (NAMED_LANGUAGE_WIKI_PEDIA_WIKI_SITE ) WikiSite wikiSite , CommonsServiceFactory serviceFactory ) {
277
+ return serviceFactory . create ( wikiSite .url (), PageMediaInterface .class );
286
278
}
287
279
288
280
@ Provides
0 commit comments