mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-01 07:13:56 +01:00
First baby steps into the world of dependency injection using Dagger.
This commit is contained in:
parent
04f676c320
commit
8fe2816ca9
32 changed files with 351 additions and 115 deletions
|
|
@ -10,6 +10,9 @@ import android.net.Uri;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.AndroidInjection;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
|
@ -33,10 +36,12 @@ public class ModificationsContentProvider extends ContentProvider{
|
|||
return Uri.parse(BASE_URI.toString() + "/" + id);
|
||||
}
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
return false;
|
||||
AndroidInjection.inject(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -53,7 +58,7 @@ public class ModificationsContentProvider extends ContentProvider{
|
|||
throw new IllegalArgumentException("Unknown URI" + uri);
|
||||
}
|
||||
|
||||
SQLiteDatabase db = CommonsApplication.getInstance().getDBOpenHelper().getReadableDatabase();
|
||||
SQLiteDatabase db = application.getDBOpenHelper().getReadableDatabase();
|
||||
|
||||
Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
|
||||
cursor.setNotificationUri(getContext().getContentResolver(), uri);
|
||||
|
|
@ -69,7 +74,7 @@ public class ModificationsContentProvider extends ContentProvider{
|
|||
@Override
|
||||
public Uri insert(@NonNull Uri uri, ContentValues contentValues) {
|
||||
int uriType = uriMatcher.match(uri);
|
||||
SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
|
||||
SQLiteDatabase sqlDB = application.getDBOpenHelper().getWritableDatabase();
|
||||
long id = 0;
|
||||
switch (uriType) {
|
||||
case MODIFICATIONS:
|
||||
|
|
@ -85,7 +90,7 @@ public class ModificationsContentProvider extends ContentProvider{
|
|||
@Override
|
||||
public int delete(@NonNull Uri uri, String s, String[] strings) {
|
||||
int uriType = uriMatcher.match(uri);
|
||||
SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
|
||||
SQLiteDatabase sqlDB = application.getDBOpenHelper().getWritableDatabase();
|
||||
switch (uriType) {
|
||||
case MODIFICATIONS_ID:
|
||||
String id = uri.getLastPathSegment();
|
||||
|
|
@ -103,7 +108,7 @@ public class ModificationsContentProvider extends ContentProvider{
|
|||
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
|
||||
Timber.d("Hello, bulk insert! (ModificationsContentProvider)");
|
||||
int uriType = uriMatcher.match(uri);
|
||||
SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
|
||||
SQLiteDatabase sqlDB = application.getDBOpenHelper().getWritableDatabase();
|
||||
sqlDB.beginTransaction();
|
||||
switch (uriType) {
|
||||
case MODIFICATIONS:
|
||||
|
|
@ -131,7 +136,7 @@ public class ModificationsContentProvider extends ContentProvider{
|
|||
In here, the only concat created argument is for id. It is cast to an int, and will error out otherwise.
|
||||
*/
|
||||
int uriType = uriMatcher.match(uri);
|
||||
SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
|
||||
SQLiteDatabase sqlDB = application.getDBOpenHelper().getWritableDatabase();
|
||||
int rowsUpdated = 0;
|
||||
switch (uriType) {
|
||||
case MODIFICATIONS:
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import android.os.RemoteException;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
|
|
@ -23,6 +25,8 @@ import timber.log.Timber;
|
|||
|
||||
public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
|
||||
@Inject CommonsApplication application;
|
||||
|
||||
public ModificationsSyncAdapter(Context context, boolean autoInitialize) {
|
||||
super(context, autoInitialize);
|
||||
}
|
||||
|
|
@ -30,6 +34,7 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||
@Override
|
||||
public void onPerformSync(Account account, Bundle bundle, String s, ContentProviderClient contentProviderClient, SyncResult syncResult) {
|
||||
// This code is fraught with possibilities of race conditions, but lalalalala I can't hear you!
|
||||
((CommonsApplication)getContext().getApplicationContext()).injector().inject(this);
|
||||
|
||||
Cursor allModifications;
|
||||
try {
|
||||
|
|
@ -59,7 +64,7 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||
return;
|
||||
}
|
||||
|
||||
MediaWikiApi api = CommonsApplication.getInstance().getMWApi();
|
||||
MediaWikiApi api = application.getMWApi();
|
||||
api.setAuthCookie(authCookie);
|
||||
String editToken;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue