6
6
import android .accounts .AccountManagerFuture ;
7
7
import android .accounts .AuthenticatorException ;
8
8
import android .accounts .OperationCanceledException ;
9
+ import android .app .Activity ;
9
10
import android .app .Application ;
10
11
import android .content .Context ;
11
12
import android .content .SharedPreferences ;
26
27
import java .io .File ;
27
28
import java .io .IOException ;
28
29
30
+ import javax .inject .Inject ;
31
+
32
+ import dagger .android .DispatchingAndroidInjector ;
33
+ import dagger .android .HasActivityInjector ;
29
34
import fr .free .nrw .commons .auth .AccountUtil ;
30
35
import fr .free .nrw .commons .caching .CacheController ;
31
36
import fr .free .nrw .commons .contributions .Contribution ;
32
37
import fr .free .nrw .commons .data .Category ;
33
38
import fr .free .nrw .commons .data .DBOpenHelper ;
39
+ import fr .free .nrw .commons .di .DaggerAppComponent ;
34
40
import fr .free .nrw .commons .modifications .ModifierSequence ;
35
41
import fr .free .nrw .commons .mwapi .ApacheHttpClientMediaWikiApi ;
36
42
import fr .free .nrw .commons .mwapi .MediaWikiApi ;
47
53
resDialogCommentPrompt = R .string .crash_dialog_comment_prompt ,
48
54
resDialogOkToast = R .string .crash_dialog_ok_toast
49
55
)
50
- public class CommonsApplication extends Application {
56
+ public class CommonsApplication extends Application implements HasActivityInjector {
51
57
52
58
private Account currentAccount = null ; // Unlike a savings account...
53
59
@@ -61,6 +67,9 @@ public class CommonsApplication extends Application {
61
67
public static final String FEEDBACK_EMAIL = "commons-app-android@googlegroups.com" ;
62
68
public static final String FEEDBACK_EMAIL_SUBJECT = "Commons Android App (%s) Feedback" ;
63
69
70
+ @ Inject DispatchingAndroidInjector <Activity > dispatchingActivityInjector ;
71
+ @ Inject MediaWikiApi mediaWikiApi ;
72
+
64
73
private static CommonsApplication instance = null ;
65
74
private MediaWikiApi api = null ;
66
75
private LruCache <String , String > thumbnailUrlCache = new LruCache <>(1024 );
@@ -123,7 +132,11 @@ public void onCreate() {
123
132
124
133
Timber .plant (new Timber .DebugTree ());
125
134
126
-
135
+ DaggerAppComponent
136
+ .builder ()
137
+ .application (this )
138
+ .build ()
139
+ .inject (this );
127
140
128
141
if (!BuildConfig .DEBUG ) {
129
142
ACRA .init (this );
@@ -168,11 +181,11 @@ public Boolean revalidateAuthToken() {
168
181
if (curAccount == null ) {
169
182
return false ; // This should never happen
170
183
}
171
-
172
- accountManager .invalidateAuthToken (AccountUtil .accountType (), getMWApi () .getAuthCookie ());
184
+
185
+ accountManager .invalidateAuthToken (AccountUtil .accountType (), mediaWikiApi .getAuthCookie ());
173
186
try {
174
187
String authCookie = accountManager .blockingGetAuthToken (curAccount , "" , false );
175
- getMWApi () .setAuthCookie (authCookie );
188
+ mediaWikiApi .setAuthCookie (authCookie );
176
189
return true ;
177
190
} catch (OperationCanceledException | NullPointerException | IOException | AuthenticatorException e ) {
178
191
e .printStackTrace ();
@@ -249,6 +262,11 @@ public void run(AccountManagerFuture<Boolean> accountManagerFuture) {
249
262
}
250
263
}
251
264
265
+ @ Override
266
+ public DispatchingAndroidInjector <Activity > activityInjector () {
267
+ return dispatchingActivityInjector ;
268
+ }
269
+
252
270
/**
253
271
* Deletes all tables and re-creates them.
254
272
*/
0 commit comments