mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
Refactor usage of dagger application with fixed dagger application
This commit is contained in:
parent
1224302ccb
commit
e1afa6081e
32 changed files with 556 additions and 311 deletions
|
|
@ -12,15 +12,17 @@ import android.text.TextUtils;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.Lazy;
|
||||
import dagger.android.AndroidInjection;
|
||||
import fr.free.nrw.commons.data.DBOpenHelper;
|
||||
import fr.free.nrw.commons.di.FixedDaggerContentProvider;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.content.UriMatcher.NO_MATCH;
|
||||
import static fr.free.nrw.commons.contributions.ContributionDao.Table.ALL_FIELDS;
|
||||
import static fr.free.nrw.commons.contributions.ContributionDao.Table.TABLE_NAME;
|
||||
|
||||
public class ContributionsContentProvider extends ContentProvider {
|
||||
public class ContributionsContentProvider extends FixedDaggerContentProvider {
|
||||
|
||||
private static final int CONTRIBUTIONS = 1;
|
||||
private static final int CONTRIBUTIONS_ID = 2;
|
||||
|
|
@ -39,11 +41,12 @@ public class ContributionsContentProvider extends ContentProvider {
|
|||
return Uri.parse(BASE_URI.toString() + "/" + id);
|
||||
}
|
||||
|
||||
@Inject DBOpenHelper dbOpenHelper;
|
||||
@Inject
|
||||
Lazy<DBOpenHelper> dbOpenHelper;
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
AndroidInjection.inject(this);
|
||||
super.onCreate();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +59,7 @@ public class ContributionsContentProvider extends ContentProvider {
|
|||
|
||||
int uriType = uriMatcher.match(uri);
|
||||
|
||||
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = dbOpenHelper.get().getReadableDatabase();
|
||||
Cursor cursor;
|
||||
|
||||
switch (uriType) {
|
||||
|
|
@ -92,7 +95,7 @@ public class ContributionsContentProvider extends ContentProvider {
|
|||
@Override
|
||||
public Uri insert(@NonNull Uri uri, ContentValues contentValues) {
|
||||
int uriType = uriMatcher.match(uri);
|
||||
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
|
||||
SQLiteDatabase sqlDB = dbOpenHelper.get().getWritableDatabase();
|
||||
long id = 0;
|
||||
switch (uriType) {
|
||||
case CONTRIBUTIONS:
|
||||
|
|
@ -111,7 +114,7 @@ public class ContributionsContentProvider extends ContentProvider {
|
|||
int rows;
|
||||
int uriType = uriMatcher.match(uri);
|
||||
|
||||
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
|
||||
SQLiteDatabase db = dbOpenHelper.get().getReadableDatabase();
|
||||
|
||||
switch (uriType) {
|
||||
case CONTRIBUTIONS_ID:
|
||||
|
|
@ -133,7 +136,7 @@ public class ContributionsContentProvider extends ContentProvider {
|
|||
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
|
||||
Timber.d("Hello, bulk insert! (ContributionsContentProvider)");
|
||||
int uriType = uriMatcher.match(uri);
|
||||
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
|
||||
SQLiteDatabase sqlDB = dbOpenHelper.get().getWritableDatabase();
|
||||
sqlDB.beginTransaction();
|
||||
switch (uriType) {
|
||||
case CONTRIBUTIONS:
|
||||
|
|
@ -164,7 +167,7 @@ public class ContributionsContentProvider extends ContentProvider {
|
|||
error out otherwise.
|
||||
*/
|
||||
int uriType = uriMatcher.match(uri);
|
||||
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
|
||||
SQLiteDatabase sqlDB = dbOpenHelper.get().getWritableDatabase();
|
||||
int rowsUpdated = 0;
|
||||
switch (uriType) {
|
||||
case CONTRIBUTIONS:
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package fr.free.nrw.commons.contributions;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
|
|
@ -25,8 +27,10 @@ import javax.inject.Named;
|
|||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import dagger.android.support.AndroidSupportInjection;
|
||||
import dagger.android.support.DaggerFragment;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.di.FixedDaggerFragment;
|
||||
import fr.free.nrw.commons.nearby.NearbyActivity;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
|
@ -36,7 +40,7 @@ import static android.app.Activity.RESULT_OK;
|
|||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static android.view.View.GONE;
|
||||
|
||||
public class ContributionsListFragment extends DaggerFragment {
|
||||
public class ContributionsListFragment extends FixedDaggerFragment {
|
||||
|
||||
@BindView(R.id.contributionsList)
|
||||
GridView contributionsList;
|
||||
|
|
@ -75,6 +79,11 @@ public class ContributionsListFragment extends DaggerFragment {
|
|||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
}
|
||||
|
||||
public ListAdapter getAdapter() {
|
||||
return contributionsList.getAdapter();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import javax.inject.Named;
|
|||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
||||
import fr.free.nrw.commons.mwapi.LogEventResult;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import timber.log.Timber;
|
||||
|
|
@ -81,7 +82,11 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||
@Override
|
||||
public void onPerformSync(Account account, Bundle bundle, String authority,
|
||||
ContentProviderClient contentProviderClient, SyncResult syncResult) {
|
||||
((CommonsApplication) getContext().getApplicationContext()).injector().inject(this);
|
||||
ApplicationlessInjection
|
||||
.getInstance(getContext()
|
||||
.getApplicationContext())
|
||||
.getCommonsApplicationComponent()
|
||||
.inject(this);
|
||||
// This code is fraught with possibilities of race conditions, but lalalalala I can't hear you!
|
||||
String user = account.name;
|
||||
String lastModified = prefs.getString("lastSyncTimestamp", "");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue