mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Introduce dagger
This commit is contained in:
parent
c926437a0e
commit
6a7b7cbbe8
7 changed files with 108 additions and 6 deletions
|
|
@ -6,6 +6,7 @@ import android.accounts.AccountManagerCallback;
|
|||
import android.accounts.AccountManagerFuture;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
|
@ -26,11 +27,16 @@ import org.acra.annotation.ReportsCrashes;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.DispatchingAndroidInjector;
|
||||
import dagger.android.HasActivityInjector;
|
||||
import fr.free.nrw.commons.auth.AccountUtil;
|
||||
import fr.free.nrw.commons.caching.CacheController;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.data.Category;
|
||||
import fr.free.nrw.commons.data.DBOpenHelper;
|
||||
import fr.free.nrw.commons.di.DaggerAppComponent;
|
||||
import fr.free.nrw.commons.modifications.ModifierSequence;
|
||||
import fr.free.nrw.commons.mwapi.ApacheHttpClientMediaWikiApi;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
|
|
@ -47,7 +53,7 @@ import timber.log.Timber;
|
|||
resDialogCommentPrompt = R.string.crash_dialog_comment_prompt,
|
||||
resDialogOkToast = R.string.crash_dialog_ok_toast
|
||||
)
|
||||
public class CommonsApplication extends Application {
|
||||
public class CommonsApplication extends Application implements HasActivityInjector {
|
||||
|
||||
private Account currentAccount = null; // Unlike a savings account...
|
||||
|
||||
|
|
@ -61,6 +67,9 @@ public class CommonsApplication extends Application {
|
|||
public static final String FEEDBACK_EMAIL = "commons-app-android@googlegroups.com";
|
||||
public static final String FEEDBACK_EMAIL_SUBJECT = "Commons Android App (%s) Feedback";
|
||||
|
||||
@Inject DispatchingAndroidInjector<Activity> dispatchingActivityInjector;
|
||||
@Inject MediaWikiApi mediaWikiApi;
|
||||
|
||||
private static CommonsApplication instance = null;
|
||||
private MediaWikiApi api = null;
|
||||
private LruCache<String, String> thumbnailUrlCache = new LruCache<>(1024);
|
||||
|
|
@ -123,7 +132,11 @@ public class CommonsApplication extends Application {
|
|||
|
||||
Timber.plant(new Timber.DebugTree());
|
||||
|
||||
|
||||
DaggerAppComponent
|
||||
.builder()
|
||||
.application(this)
|
||||
.build()
|
||||
.inject(this);
|
||||
|
||||
if (!BuildConfig.DEBUG) {
|
||||
ACRA.init(this);
|
||||
|
|
@ -168,11 +181,11 @@ public class CommonsApplication extends Application {
|
|||
if (curAccount == null) {
|
||||
return false; // This should never happen
|
||||
}
|
||||
|
||||
accountManager.invalidateAuthToken(AccountUtil.accountType(), getMWApi().getAuthCookie());
|
||||
|
||||
accountManager.invalidateAuthToken(AccountUtil.accountType(), mediaWikiApi.getAuthCookie());
|
||||
try {
|
||||
String authCookie = accountManager.blockingGetAuthToken(curAccount, "", false);
|
||||
getMWApi().setAuthCookie(authCookie);
|
||||
mediaWikiApi.setAuthCookie(authCookie);
|
||||
return true;
|
||||
} catch (OperationCanceledException | NullPointerException | IOException | AuthenticatorException e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -249,6 +262,11 @@ public class CommonsApplication extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DispatchingAndroidInjector<Activity> activityInjector() {
|
||||
return dispatchingActivityInjector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all tables and re-creates them.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue