mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Injected the ContributionDao where needed.
This commit is contained in:
parent
f2ed57a127
commit
9927879680
9 changed files with 70 additions and 46 deletions
|
|
@ -8,13 +8,13 @@ import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import fr.free.nrw.commons.contributions.ContributionsContentProvider;
|
|
||||||
import fr.free.nrw.commons.modifications.ModificationsContentProvider;
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
import static android.accounts.AccountManager.ERROR_CODE_REMOTE_EXCEPTION;
|
import static android.accounts.AccountManager.ERROR_CODE_REMOTE_EXCEPTION;
|
||||||
import static android.accounts.AccountManager.KEY_ACCOUNT_NAME;
|
import static android.accounts.AccountManager.KEY_ACCOUNT_NAME;
|
||||||
import static android.accounts.AccountManager.KEY_ACCOUNT_TYPE;
|
import static android.accounts.AccountManager.KEY_ACCOUNT_TYPE;
|
||||||
|
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.CONTRIBUTION_AUTHORITY;
|
||||||
|
import static fr.free.nrw.commons.modifications.ModificationsContentProvider.AUTHORITY;
|
||||||
|
|
||||||
public class AccountUtil {
|
public class AccountUtil {
|
||||||
|
|
||||||
|
|
@ -51,8 +51,8 @@ public class AccountUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: If the user turns it off, it shouldn't be auto turned back on
|
// FIXME: If the user turns it off, it shouldn't be auto turned back on
|
||||||
ContentResolver.setSyncAutomatically(account, ContributionsContentProvider.AUTHORITY, true); // Enable sync by default!
|
ContentResolver.setSyncAutomatically(account, CONTRIBUTION_AUTHORITY, true); // Enable sync by default!
|
||||||
ContentResolver.setSyncAutomatically(account, ModificationsContentProvider.AUTHORITY, true); // Enable sync by default!
|
ContentResolver.setSyncAutomatically(account, AUTHORITY, true); // Enable sync by default!
|
||||||
}
|
}
|
||||||
|
|
||||||
private AccountManager accountManager() {
|
private AccountManager accountManager() {
|
||||||
|
|
|
||||||
|
|
@ -11,40 +11,51 @@ import android.text.TextUtils;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import fr.free.nrw.commons.settings.Prefs;
|
import fr.free.nrw.commons.settings.Prefs;
|
||||||
|
|
||||||
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.BASE_URI;
|
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.BASE_URI;
|
||||||
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.uriForId;
|
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.uriForId;
|
||||||
|
|
||||||
public class ContributionDao {
|
public class ContributionDao {
|
||||||
private final ContentProviderClient client;
|
private final Provider<ContentProviderClient> clientProvider;
|
||||||
|
|
||||||
public ContributionDao(ContentProviderClient client) {
|
@Inject
|
||||||
this.client = client;
|
public ContributionDao(@Named("contribution") Provider<ContentProviderClient> clientProvider) {
|
||||||
|
this.clientProvider = clientProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(Contribution contribution) {
|
public void save(Contribution contribution) {
|
||||||
|
ContentProviderClient db = clientProvider.get();
|
||||||
try {
|
try {
|
||||||
if (contribution.getContentUri() == null) {
|
if (contribution.getContentUri() == null) {
|
||||||
contribution.setContentUri(client.insert(BASE_URI, toContentValues(contribution)));
|
contribution.setContentUri(db.insert(BASE_URI, toContentValues(contribution)));
|
||||||
} else {
|
} else {
|
||||||
client.update(contribution.getContentUri(), toContentValues(contribution), null, null);
|
db.update(contribution.getContentUri(), toContentValues(contribution), null, null);
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
db.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(Contribution contribution) {
|
public void delete(Contribution contribution) {
|
||||||
|
ContentProviderClient db = clientProvider.get();
|
||||||
try {
|
try {
|
||||||
if (contribution.getContentUri() == null) {
|
if (contribution.getContentUri() == null) {
|
||||||
// noooo
|
// noooo
|
||||||
throw new RuntimeException("tried to delete item with no content URI");
|
throw new RuntimeException("tried to delete item with no content URI");
|
||||||
} else {
|
} else {
|
||||||
client.delete(contribution.getContentUri(), null, null);
|
db.delete(contribution.getContentUri(), null, null);
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
db.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +85,7 @@ public class ContributionDao {
|
||||||
return cv;
|
return cv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Contribution fromCursor(Cursor cursor) {
|
public Contribution fromCursor(Cursor cursor) {
|
||||||
// Hardcoding column positions!
|
// Hardcoding column positions!
|
||||||
//Check that cursor has a value to avoid CursorIndexOutOfBoundsException
|
//Check that cursor has a value to avoid CursorIndexOutOfBoundsException
|
||||||
if (cursor.getCount() > 0) {
|
if (cursor.getCount() > 0) {
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ import timber.log.Timber;
|
||||||
import static android.content.ContentResolver.requestSync;
|
import static android.content.ContentResolver.requestSync;
|
||||||
import static fr.free.nrw.commons.contributions.Contribution.STATE_FAILED;
|
import static fr.free.nrw.commons.contributions.Contribution.STATE_FAILED;
|
||||||
import static fr.free.nrw.commons.contributions.ContributionDao.Table.ALL_FIELDS;
|
import static fr.free.nrw.commons.contributions.ContributionDao.Table.ALL_FIELDS;
|
||||||
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.AUTHORITY;
|
|
||||||
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.BASE_URI;
|
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.BASE_URI;
|
||||||
import static fr.free.nrw.commons.settings.Prefs.UPLOADS_SHOWING;
|
import static fr.free.nrw.commons.settings.Prefs.UPLOADS_SHOWING;
|
||||||
|
|
||||||
|
|
@ -58,6 +57,7 @@ public class ContributionsActivity
|
||||||
@Inject MediaWikiApi mediaWikiApi;
|
@Inject MediaWikiApi mediaWikiApi;
|
||||||
@Inject SessionManager sessionManager;
|
@Inject SessionManager sessionManager;
|
||||||
@Inject @Named("default_preferences") SharedPreferences prefs;
|
@Inject @Named("default_preferences") SharedPreferences prefs;
|
||||||
|
@Inject ContributionDao contributionDao;
|
||||||
|
|
||||||
private Cursor allContributions;
|
private Cursor allContributions;
|
||||||
private ContributionsListFragment contributionsList;
|
private ContributionsListFragment contributionsList;
|
||||||
|
|
@ -121,7 +121,7 @@ public class ContributionsActivity
|
||||||
@Override
|
@Override
|
||||||
protected void onAuthCookieAcquired(String authCookie) {
|
protected void onAuthCookieAcquired(String authCookie) {
|
||||||
// Do a sync everytime we get here!
|
// Do a sync everytime we get here!
|
||||||
requestSync(sessionManager.getCurrentAccount(), ContributionsContentProvider.AUTHORITY, new Bundle());
|
requestSync(sessionManager.getCurrentAccount(), ContributionsContentProvider.CONTRIBUTION_AUTHORITY, new Bundle());
|
||||||
Intent uploadServiceIntent = new Intent(this, UploadService.class);
|
Intent uploadServiceIntent = new Intent(this, UploadService.class);
|
||||||
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
|
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
|
||||||
startService(uploadServiceIntent);
|
startService(uploadServiceIntent);
|
||||||
|
|
@ -186,7 +186,7 @@ public class ContributionsActivity
|
||||||
|
|
||||||
public void retryUpload(int i) {
|
public void retryUpload(int i) {
|
||||||
allContributions.moveToPosition(i);
|
allContributions.moveToPosition(i);
|
||||||
Contribution c = ContributionDao.fromCursor(allContributions);
|
Contribution c = contributionDao.fromCursor(allContributions);
|
||||||
if (c.getState() == STATE_FAILED) {
|
if (c.getState() == STATE_FAILED) {
|
||||||
uploadService.queue(UploadService.ACTION_UPLOAD_FILE, c);
|
uploadService.queue(UploadService.ACTION_UPLOAD_FILE, c);
|
||||||
Timber.d("Restarting for %s", c.toString());
|
Timber.d("Restarting for %s", c.toString());
|
||||||
|
|
@ -197,10 +197,10 @@ public class ContributionsActivity
|
||||||
|
|
||||||
public void deleteUpload(int i) {
|
public void deleteUpload(int i) {
|
||||||
allContributions.moveToPosition(i);
|
allContributions.moveToPosition(i);
|
||||||
Contribution c = ContributionDao.fromCursor(allContributions);
|
Contribution c = contributionDao.fromCursor(allContributions);
|
||||||
if (c.getState() == STATE_FAILED) {
|
if (c.getState() == STATE_FAILED) {
|
||||||
Timber.d("Deleting failed contrib %s", c.toString());
|
Timber.d("Deleting failed contrib %s", c.toString());
|
||||||
new ContributionDao(getContentResolver().acquireContentProviderClient(AUTHORITY)).delete(c);
|
contributionDao.delete(c);
|
||||||
} else {
|
} else {
|
||||||
Timber.d("Skipping deletion for non-failed contrib %s", c.toString());
|
Timber.d("Skipping deletion for non-failed contrib %s", c.toString());
|
||||||
}
|
}
|
||||||
|
|
@ -248,7 +248,7 @@ public class ContributionsActivity
|
||||||
|
|
||||||
if (contributionsList.getAdapter() == null) {
|
if (contributionsList.getAdapter() == null) {
|
||||||
contributionsList.setAdapter(new ContributionsListAdapter(getApplicationContext(),
|
contributionsList.setAdapter(new ContributionsListAdapter(getApplicationContext(),
|
||||||
cursor, 0));
|
cursor, 0, contributionDao));
|
||||||
} else {
|
} else {
|
||||||
((CursorAdapter) contributionsList.getAdapter()).swapCursor(cursor);
|
((CursorAdapter) contributionsList.getAdapter()).swapCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
@ -269,7 +269,7 @@ public class ContributionsActivity
|
||||||
// not yet ready to return data
|
// not yet ready to return data
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return ContributionDao.fromCursor((Cursor) contributionsList.getAdapter().getItem(i));
|
return contributionDao.fromCursor((Cursor) contributionsList.getAdapter().getItem(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,13 @@ public class ContributionsContentProvider extends ContentProvider {
|
||||||
private static final int CONTRIBUTIONS_ID = 2;
|
private static final int CONTRIBUTIONS_ID = 2;
|
||||||
private static final String BASE_PATH = "contributions";
|
private static final String BASE_PATH = "contributions";
|
||||||
private static final UriMatcher uriMatcher = new UriMatcher(NO_MATCH);
|
private static final UriMatcher uriMatcher = new UriMatcher(NO_MATCH);
|
||||||
public static final String AUTHORITY = "fr.free.nrw.commons.contributions.contentprovider";
|
public static final String CONTRIBUTION_AUTHORITY = "fr.free.nrw.commons.contributions.contentprovider";
|
||||||
|
|
||||||
public static final Uri BASE_URI = Uri.parse("content://" + AUTHORITY + "/" + BASE_PATH);
|
public static final Uri BASE_URI = Uri.parse("content://" + CONTRIBUTION_AUTHORITY + "/" + BASE_PATH);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
uriMatcher.addURI(AUTHORITY, BASE_PATH, CONTRIBUTIONS);
|
uriMatcher.addURI(CONTRIBUTION_AUTHORITY, BASE_PATH, CONTRIBUTIONS);
|
||||||
uriMatcher.addURI(AUTHORITY, BASE_PATH + "/#", CONTRIBUTIONS_ID);
|
uriMatcher.addURI(CONTRIBUTION_AUTHORITY, BASE_PATH + "/#", CONTRIBUTIONS_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Uri uriForId(int id) {
|
public static Uri uriForId(int id) {
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,11 @@ import fr.free.nrw.commons.R;
|
||||||
|
|
||||||
class ContributionsListAdapter extends CursorAdapter {
|
class ContributionsListAdapter extends CursorAdapter {
|
||||||
|
|
||||||
public ContributionsListAdapter(Context context, Cursor c, int flags) {
|
private final ContributionDao contributionDao;
|
||||||
|
|
||||||
|
public ContributionsListAdapter(Context context, Cursor c, int flags, ContributionDao contributionDao) {
|
||||||
super(context, c, flags);
|
super(context, c, flags);
|
||||||
|
this.contributionDao = contributionDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -26,7 +29,7 @@ class ContributionsListAdapter extends CursorAdapter {
|
||||||
@Override
|
@Override
|
||||||
public void bindView(View view, Context context, Cursor cursor) {
|
public void bindView(View view, Context context, Cursor cursor) {
|
||||||
final ContributionViewHolder views = (ContributionViewHolder)view.getTag();
|
final ContributionViewHolder views = (ContributionViewHolder)view.getTag();
|
||||||
final Contribution contribution = ContributionDao.fromCursor(cursor);
|
final Contribution contribution = contributionDao.fromCursor(cursor);
|
||||||
|
|
||||||
views.imageView.setMedia(contribution);
|
views.imageView.setMedia(contribution);
|
||||||
views.titleView.setText(contribution.getDisplayTitle());
|
views.titleView.setText(contribution.getDisplayTitle());
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import fr.free.nrw.commons.nearby.NearbyPlaces;
|
||||||
import fr.free.nrw.commons.upload.UploadController;
|
import fr.free.nrw.commons.upload.UploadController;
|
||||||
|
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.CONTRIBUTION_AUTHORITY;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||||
|
|
@ -42,10 +43,16 @@ public class CommonsApplicationModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Named("category")
|
@Named("category")
|
||||||
public ContentProviderClient provideContentProviderClient() {
|
public ContentProviderClient provideCategoryContentProviderClient() {
|
||||||
return application.getContentResolver().acquireContentProviderClient(CATEGORY_AUTHORITY);
|
return application.getContentResolver().acquireContentProviderClient(CATEGORY_AUTHORITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Named("contribution")
|
||||||
|
public ContentProviderClient provideContributionContentProviderClient() {
|
||||||
|
return application.getContentResolver().acquireContentProviderClient(CONTRIBUTION_AUTHORITY);
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Named("application_preferences")
|
@Named("application_preferences")
|
||||||
public SharedPreferences providesApplicationSharedPreferences() {
|
public SharedPreferences providesApplicationSharedPreferences() {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import timber.log.Timber;
|
||||||
public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||||
|
|
||||||
@Inject MediaWikiApi mwApi;
|
@Inject MediaWikiApi mwApi;
|
||||||
|
@Inject ContributionDao contributionDao;
|
||||||
|
|
||||||
public ModificationsSyncAdapter(Context context, boolean autoInitialize) {
|
public ModificationsSyncAdapter(Context context, boolean autoInitialize) {
|
||||||
super(context, autoInitialize);
|
super(context, autoInitialize);
|
||||||
|
|
@ -80,7 +81,7 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||||
|
|
||||||
ContentProviderClient contributionsClient = null;
|
ContentProviderClient contributionsClient = null;
|
||||||
try {
|
try {
|
||||||
contributionsClient = getContext().getContentResolver().acquireContentProviderClient(ContributionsContentProvider.AUTHORITY);
|
contributionsClient = getContext().getContentResolver().acquireContentProviderClient(ContributionsContentProvider.CONTRIBUTION_AUTHORITY);
|
||||||
|
|
||||||
while (!allModifications.isAfterLast()) {
|
while (!allModifications.isAfterLast()) {
|
||||||
ModifierSequence sequence = ModifierSequenceDao.fromCursor(allModifications);
|
ModifierSequence sequence = ModifierSequenceDao.fromCursor(allModifications);
|
||||||
|
|
@ -94,7 +95,7 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
contributionCursor.moveToFirst();
|
contributionCursor.moveToFirst();
|
||||||
contrib = ContributionDao.fromCursor(contributionCursor);
|
contrib = contributionDao.fromCursor(contributionCursor);
|
||||||
|
|
||||||
if (contrib.getState() == Contribution.STATE_COMPLETED) {
|
if (contrib.getState() == Contribution.STATE_COMPLETED) {
|
||||||
String pageContent;
|
String pageContent;
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ public class UploadService extends HandlerService<Contribution> {
|
||||||
@Inject MediaWikiApi mwApi;
|
@Inject MediaWikiApi mwApi;
|
||||||
@Inject SessionManager sessionManager;
|
@Inject SessionManager sessionManager;
|
||||||
@Inject @Named("default_preferences") SharedPreferences prefs;
|
@Inject @Named("default_preferences") SharedPreferences prefs;
|
||||||
|
@Inject ContributionDao contributionDao;
|
||||||
|
|
||||||
private NotificationManager notificationManager;
|
private NotificationManager notificationManager;
|
||||||
private ContentProviderClient contributionsProviderClient;
|
private ContentProviderClient contributionsProviderClient;
|
||||||
|
|
@ -67,7 +68,6 @@ public class UploadService extends HandlerService<Contribution> {
|
||||||
public static final int NOTIFICATION_UPLOAD_IN_PROGRESS = 1;
|
public static final int NOTIFICATION_UPLOAD_IN_PROGRESS = 1;
|
||||||
public static final int NOTIFICATION_UPLOAD_COMPLETE = 2;
|
public static final int NOTIFICATION_UPLOAD_COMPLETE = 2;
|
||||||
public static final int NOTIFICATION_UPLOAD_FAILED = 3;
|
public static final int NOTIFICATION_UPLOAD_FAILED = 3;
|
||||||
private ContributionDao dao;
|
|
||||||
|
|
||||||
public UploadService() {
|
public UploadService() {
|
||||||
super("UploadService");
|
super("UploadService");
|
||||||
|
|
@ -107,7 +107,7 @@ public class UploadService extends HandlerService<Contribution> {
|
||||||
startForeground(NOTIFICATION_UPLOAD_IN_PROGRESS, curProgressNotification.build());
|
startForeground(NOTIFICATION_UPLOAD_IN_PROGRESS, curProgressNotification.build());
|
||||||
|
|
||||||
contribution.setTransferred(transferred);
|
contribution.setTransferred(transferred);
|
||||||
dao.save(contribution);
|
contributionDao.save(contribution);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -124,8 +124,7 @@ public class UploadService extends HandlerService<Contribution> {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
contributionsProviderClient = this.getContentResolver().acquireContentProviderClient(ContributionsContentProvider.AUTHORITY);
|
contributionsProviderClient = this.getContentResolver().acquireContentProviderClient(ContributionsContentProvider.CONTRIBUTION_AUTHORITY);
|
||||||
dao = new ContributionDao(contributionsProviderClient);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -147,7 +146,7 @@ public class UploadService extends HandlerService<Contribution> {
|
||||||
|
|
||||||
contribution.setState(Contribution.STATE_QUEUED);
|
contribution.setState(Contribution.STATE_QUEUED);
|
||||||
contribution.setTransferred(0);
|
contribution.setTransferred(0);
|
||||||
dao.save(contribution);
|
contributionDao.save(contribution);
|
||||||
toUpload++;
|
toUpload++;
|
||||||
if (curProgressNotification != null && toUpload != 1) {
|
if (curProgressNotification != null && toUpload != 1) {
|
||||||
curProgressNotification.setContentText(getResources().getQuantityString(R.plurals.uploads_pending_notification_indicator, toUpload, toUpload));
|
curProgressNotification.setContentText(getResources().getQuantityString(R.plurals.uploads_pending_notification_indicator, toUpload, toUpload));
|
||||||
|
|
@ -262,7 +261,7 @@ public class UploadService extends HandlerService<Contribution> {
|
||||||
contribution.setImageUrl(uploadResult.getImageUrl());
|
contribution.setImageUrl(uploadResult.getImageUrl());
|
||||||
contribution.setState(Contribution.STATE_COMPLETED);
|
contribution.setState(Contribution.STATE_COMPLETED);
|
||||||
contribution.setDateUploaded(uploadResult.getDateUploaded());
|
contribution.setDateUploaded(uploadResult.getDateUploaded());
|
||||||
dao.save(contribution);
|
contributionDao.save(contribution);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Timber.d("I have a network fuckup");
|
Timber.d("I have a network fuckup");
|
||||||
|
|
@ -293,7 +292,7 @@ public class UploadService extends HandlerService<Contribution> {
|
||||||
notificationManager.notify(NOTIFICATION_UPLOAD_FAILED, failureNotification);
|
notificationManager.notify(NOTIFICATION_UPLOAD_FAILED, failureNotification);
|
||||||
|
|
||||||
contribution.setState(Contribution.STATE_FAILED);
|
contribution.setState(Contribution.STATE_FAILED);
|
||||||
dao.save(contribution);
|
contributionDao.save(contribution);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String findUniqueFilename(String fileName) throws IOException {
|
private String findUniqueFilename(String fileName) throws IOException {
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,13 @@ import static fr.free.nrw.commons.contributions.Contribution.SOURCE_CAMERA;
|
||||||
import static fr.free.nrw.commons.contributions.Contribution.SOURCE_GALLERY;
|
import static fr.free.nrw.commons.contributions.Contribution.SOURCE_GALLERY;
|
||||||
import static fr.free.nrw.commons.contributions.Contribution.STATE_COMPLETED;
|
import static fr.free.nrw.commons.contributions.Contribution.STATE_COMPLETED;
|
||||||
import static fr.free.nrw.commons.contributions.Contribution.STATE_QUEUED;
|
import static fr.free.nrw.commons.contributions.Contribution.STATE_QUEUED;
|
||||||
import static fr.free.nrw.commons.contributions.ContributionDao.*;
|
import static fr.free.nrw.commons.contributions.ContributionDao.Table;
|
||||||
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.BASE_URI;
|
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.BASE_URI;
|
||||||
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.uriForId;
|
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.uriForId;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Matchers.isA;
|
import static org.mockito.Matchers.isA;
|
||||||
|
|
@ -49,22 +52,22 @@ public class ContributionDaoTest {
|
||||||
|
|
||||||
private static final String LOCAL_URI = "http://example.com/";
|
private static final String LOCAL_URI = "http://example.com/";
|
||||||
@Mock
|
@Mock
|
||||||
ContentProviderClient client;
|
private ContentProviderClient client;
|
||||||
@Mock
|
@Mock
|
||||||
SQLiteDatabase database;
|
private SQLiteDatabase database;
|
||||||
@Captor
|
@Captor
|
||||||
ArgumentCaptor<ContentValues> captor;
|
private ArgumentCaptor<ContentValues> captor;
|
||||||
|
|
||||||
private Uri contentUri;
|
private Uri contentUri;
|
||||||
private ContributionDao testObject;
|
private ContributionDao testObject;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
contentUri = uriForId(111);
|
contentUri = uriForId(111);
|
||||||
|
|
||||||
testObject = new ContributionDao(client);
|
testObject = new ContributionDao(() -> client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -288,7 +291,7 @@ public class ContributionDaoTest {
|
||||||
long uploaded = 456L;
|
long uploaded = 456L;
|
||||||
MatrixCursor mc = createCursor(created, uploaded, false, LOCAL_URI);
|
MatrixCursor mc = createCursor(created, uploaded, false, LOCAL_URI);
|
||||||
|
|
||||||
Contribution c = ContributionDao.fromCursor(mc);
|
Contribution c = testObject.fromCursor(mc);
|
||||||
|
|
||||||
assertEquals(uriForId(111), c.getContentUri());
|
assertEquals(uriForId(111), c.getContentUri());
|
||||||
assertEquals("file", c.getFilename());
|
assertEquals("file", c.getFilename());
|
||||||
|
|
@ -312,7 +315,7 @@ public class ContributionDaoTest {
|
||||||
public void createFromCursor_nullableTimestamps() {
|
public void createFromCursor_nullableTimestamps() {
|
||||||
MatrixCursor mc = createCursor(0L, 0L, false, LOCAL_URI);
|
MatrixCursor mc = createCursor(0L, 0L, false, LOCAL_URI);
|
||||||
|
|
||||||
Contribution c = ContributionDao.fromCursor(mc);
|
Contribution c = testObject.fromCursor(mc);
|
||||||
|
|
||||||
assertNull(c.getTimestamp());
|
assertNull(c.getTimestamp());
|
||||||
assertNull(c.getDateCreated());
|
assertNull(c.getDateCreated());
|
||||||
|
|
@ -323,7 +326,7 @@ public class ContributionDaoTest {
|
||||||
public void createFromCursor_nullableLocalUri() {
|
public void createFromCursor_nullableLocalUri() {
|
||||||
MatrixCursor mc = createCursor(0L, 0L, false, "");
|
MatrixCursor mc = createCursor(0L, 0L, false, "");
|
||||||
|
|
||||||
Contribution c = ContributionDao.fromCursor(mc);
|
Contribution c = testObject.fromCursor(mc);
|
||||||
|
|
||||||
assertNull(c.getLocalUri());
|
assertNull(c.getLocalUri());
|
||||||
assertNull(c.getDateCreated());
|
assertNull(c.getDateCreated());
|
||||||
|
|
@ -333,10 +336,10 @@ public class ContributionDaoTest {
|
||||||
@Test
|
@Test
|
||||||
public void createFromCursor_booleanEncoding() {
|
public void createFromCursor_booleanEncoding() {
|
||||||
MatrixCursor mcFalse = createCursor(0L, 0L, false, LOCAL_URI);
|
MatrixCursor mcFalse = createCursor(0L, 0L, false, LOCAL_URI);
|
||||||
assertFalse(ContributionDao.fromCursor(mcFalse).getMultiple());
|
assertFalse(testObject.fromCursor(mcFalse).getMultiple());
|
||||||
|
|
||||||
MatrixCursor mcHammer = createCursor(0L, 0L, true, LOCAL_URI);
|
MatrixCursor mcHammer = createCursor(0L, 0L, true, LOCAL_URI);
|
||||||
assertTrue(ContributionDao.fromCursor(mcHammer).getMultiple());
|
assertTrue(testObject.fromCursor(mcHammer).getMultiple());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue