mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Merge pull request #1047 from psh/more-database-cleanup
More database related cleanup
This commit is contained in:
commit
1224302ccb
22 changed files with 211 additions and 151 deletions
|
|
@ -21,8 +21,8 @@ import javax.inject.Named;
|
||||||
import dagger.android.AndroidInjector;
|
import dagger.android.AndroidInjector;
|
||||||
import dagger.android.DaggerApplication;
|
import dagger.android.DaggerApplication;
|
||||||
import fr.free.nrw.commons.auth.SessionManager;
|
import fr.free.nrw.commons.auth.SessionManager;
|
||||||
|
import fr.free.nrw.commons.category.CategoryDao;
|
||||||
import fr.free.nrw.commons.contributions.ContributionDao;
|
import fr.free.nrw.commons.contributions.ContributionDao;
|
||||||
import fr.free.nrw.commons.data.CategoryDao;
|
|
||||||
import fr.free.nrw.commons.data.DBOpenHelper;
|
import fr.free.nrw.commons.data.DBOpenHelper;
|
||||||
import fr.free.nrw.commons.di.CommonsApplicationComponent;
|
import fr.free.nrw.commons.di.CommonsApplicationComponent;
|
||||||
import fr.free.nrw.commons.di.CommonsApplicationModule;
|
import fr.free.nrw.commons.di.CommonsApplicationModule;
|
||||||
|
|
|
||||||
|
|
@ -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.MODIFICATIONS_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, MODIFICATIONS_AUTHORITY, true); // Enable sync by default!
|
||||||
}
|
}
|
||||||
|
|
||||||
private AccountManager accountManager() {
|
private AccountManager accountManager() {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package fr.free.nrw.commons.category;
|
package fr.free.nrw.commons.category;
|
||||||
|
|
||||||
import android.content.ContentProviderClient;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
|
@ -36,8 +35,6 @@ import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import dagger.android.support.DaggerFragment;
|
import dagger.android.support.DaggerFragment;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.data.Category;
|
|
||||||
import fr.free.nrw.commons.data.CategoryDao;
|
|
||||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||||
import fr.free.nrw.commons.upload.MwVolleyApi;
|
import fr.free.nrw.commons.upload.MwVolleyApi;
|
||||||
import fr.free.nrw.commons.utils.StringSortingUtils;
|
import fr.free.nrw.commons.utils.StringSortingUtils;
|
||||||
|
|
@ -48,7 +45,6 @@ import timber.log.Timber;
|
||||||
|
|
||||||
import static android.view.KeyEvent.ACTION_UP;
|
import static android.view.KeyEvent.ACTION_UP;
|
||||||
import static android.view.KeyEvent.KEYCODE_BACK;
|
import static android.view.KeyEvent.KEYCODE_BACK;
|
||||||
import static fr.free.nrw.commons.category.CategoryContentProvider.AUTHORITY;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the category suggestion and selection screen. Category search is initiated here.
|
* Displays the category suggestion and selection screen. Category search is initiated here.
|
||||||
|
|
@ -70,12 +66,12 @@ public class CategorizationFragment extends DaggerFragment {
|
||||||
|
|
||||||
@Inject MediaWikiApi mwApi;
|
@Inject MediaWikiApi mwApi;
|
||||||
@Inject @Named("default_preferences") SharedPreferences prefs;
|
@Inject @Named("default_preferences") SharedPreferences prefs;
|
||||||
|
@Inject CategoryDao categoryDao;
|
||||||
|
|
||||||
private RVRendererAdapter<CategoryItem> categoriesAdapter;
|
private RVRendererAdapter<CategoryItem> categoriesAdapter;
|
||||||
private OnCategoriesSaveHandler onCategoriesSaveHandler;
|
private OnCategoriesSaveHandler onCategoriesSaveHandler;
|
||||||
private HashMap<String, ArrayList<String>> categoriesCache;
|
private HashMap<String, ArrayList<String>> categoriesCache;
|
||||||
private List<CategoryItem> selectedCategories = new ArrayList<>();
|
private List<CategoryItem> selectedCategories = new ArrayList<>();
|
||||||
private ContentProviderClient databaseClient;
|
|
||||||
|
|
||||||
private final CategoriesAdapterFactory adapterFactory = new CategoriesAdapterFactory(item -> {
|
private final CategoriesAdapterFactory adapterFactory = new CategoriesAdapterFactory(item -> {
|
||||||
if (item.isSelected()) {
|
if (item.isSelected()) {
|
||||||
|
|
@ -141,7 +137,6 @@ public class CategorizationFragment extends DaggerFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
databaseClient.release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -179,7 +174,6 @@ public class CategorizationFragment extends DaggerFragment {
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
onCategoriesSaveHandler = (OnCategoriesSaveHandler) getActivity();
|
onCategoriesSaveHandler = (OnCategoriesSaveHandler) getActivity();
|
||||||
getActivity().setTitle(R.string.categories_activity_title);
|
getActivity().setTitle(R.string.categories_activity_title);
|
||||||
databaseClient = getActivity().getContentResolver().acquireContentProviderClient(AUTHORITY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCategoryList(String filter) {
|
private void updateCategoryList(String filter) {
|
||||||
|
|
@ -262,7 +256,7 @@ public class CategorizationFragment extends DaggerFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Observable<CategoryItem> recentCategories() {
|
private Observable<CategoryItem> recentCategories() {
|
||||||
return Observable.fromIterable(new CategoryDao(databaseClient).recentCategories(SEARCH_CATS_LIMIT))
|
return Observable.fromIterable(categoryDao.recentCategories(SEARCH_CATS_LIMIT))
|
||||||
.map(s -> new CategoryItem(s, false));
|
.map(s -> new CategoryItem(s, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -313,7 +307,6 @@ public class CategorizationFragment extends DaggerFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCategoryCount(CategoryItem item) {
|
private void updateCategoryCount(CategoryItem item) {
|
||||||
CategoryDao categoryDao = new CategoryDao(databaseClient);
|
|
||||||
Category category = categoryDao.find(item.getName());
|
Category category = categoryDao.find(item.getName());
|
||||||
|
|
||||||
// Newly used category...
|
// Newly used category...
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package fr.free.nrw.commons.data;
|
package fr.free.nrw.commons.category;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
|
@ -17,9 +17,9 @@ import fr.free.nrw.commons.data.DBOpenHelper;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
import static android.content.UriMatcher.NO_MATCH;
|
import static android.content.UriMatcher.NO_MATCH;
|
||||||
import static fr.free.nrw.commons.data.CategoryDao.Table.ALL_FIELDS;
|
import static fr.free.nrw.commons.category.CategoryDao.Table.ALL_FIELDS;
|
||||||
import static fr.free.nrw.commons.data.CategoryDao.Table.COLUMN_ID;
|
import static fr.free.nrw.commons.category.CategoryDao.Table.COLUMN_ID;
|
||||||
import static fr.free.nrw.commons.data.CategoryDao.Table.TABLE_NAME;
|
import static fr.free.nrw.commons.category.CategoryDao.Table.TABLE_NAME;
|
||||||
|
|
||||||
public class CategoryContentProvider extends ContentProvider {
|
public class CategoryContentProvider extends ContentProvider {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package fr.free.nrw.commons.data;
|
package fr.free.nrw.commons.category;
|
||||||
|
|
||||||
import android.content.ContentProviderClient;
|
import android.content.ContentProviderClient;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
|
@ -12,25 +12,31 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.free.nrw.commons.category.CategoryContentProvider;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
public class CategoryDao {
|
public class CategoryDao {
|
||||||
|
|
||||||
private final ContentProviderClient client;
|
private final Provider<ContentProviderClient> clientProvider;
|
||||||
|
|
||||||
public CategoryDao(ContentProviderClient client) {
|
@Inject
|
||||||
this.client = client;
|
public CategoryDao(@Named("category") Provider<ContentProviderClient> clientProvider) {
|
||||||
|
this.clientProvider = clientProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(Category category) {
|
public void save(Category category) {
|
||||||
|
ContentProviderClient db = clientProvider.get();
|
||||||
try {
|
try {
|
||||||
if (category.getContentUri() == null) {
|
if (category.getContentUri() == null) {
|
||||||
category.setContentUri(client.insert(CategoryContentProvider.BASE_URI, toContentValues(category)));
|
category.setContentUri(db.insert(CategoryContentProvider.BASE_URI, toContentValues(category)));
|
||||||
} else {
|
} else {
|
||||||
client.update(category.getContentUri(), toContentValues(category), null, null);
|
db.update(category.getContentUri(), toContentValues(category), null, null);
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
db.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,11 +46,12 @@ public class CategoryDao {
|
||||||
* @param name Category's name
|
* @param name Category's name
|
||||||
* @return category from database, or null if not found
|
* @return category from database, or null if not found
|
||||||
*/
|
*/
|
||||||
public @Nullable
|
@Nullable
|
||||||
Category find(String name) {
|
Category find(String name) {
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
ContentProviderClient db = clientProvider.get();
|
||||||
try {
|
try {
|
||||||
cursor = client.query(
|
cursor = db.query(
|
||||||
CategoryContentProvider.BASE_URI,
|
CategoryContentProvider.BASE_URI,
|
||||||
Table.ALL_FIELDS,
|
Table.ALL_FIELDS,
|
||||||
Table.COLUMN_NAME + "=?",
|
Table.COLUMN_NAME + "=?",
|
||||||
|
|
@ -60,6 +67,7 @@ public class CategoryDao {
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
db.release();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -69,12 +77,13 @@ public class CategoryDao {
|
||||||
*
|
*
|
||||||
* @return a list containing recent categories
|
* @return a list containing recent categories
|
||||||
*/
|
*/
|
||||||
public @NonNull
|
@NonNull
|
||||||
List<String> recentCategories(int limit) {
|
List<String> recentCategories(int limit) {
|
||||||
List<String> items = new ArrayList<>();
|
List<String> items = new ArrayList<>();
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
ContentProviderClient db = clientProvider.get();
|
||||||
try {
|
try {
|
||||||
cursor = client.query(
|
cursor = db.query(
|
||||||
CategoryContentProvider.BASE_URI,
|
CategoryContentProvider.BASE_URI,
|
||||||
Table.ALL_FIELDS,
|
Table.ALL_FIELDS,
|
||||||
null,
|
null,
|
||||||
|
|
@ -91,6 +100,7 @@ public class CategoryDao {
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
db.release();
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +157,7 @@ public class CategoryDao {
|
||||||
onCreate(db);
|
onCreate(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onUpdate(SQLiteDatabase db, int from, int to) {
|
public static void onUpdate(SQLiteDatabase db, int from, int to) {
|
||||||
if (from == to) {
|
if (from == to) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -11,44 +11,81 @@ 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.ContributionDao.Table.ALL_FIELDS;
|
||||||
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;
|
/*
|
||||||
|
This sorts in the following order:
|
||||||
|
Currently Uploading
|
||||||
|
Failed (Sorted in ascending order of time added - FIFO)
|
||||||
|
Queued to Upload (Sorted in ascending order of time added - FIFO)
|
||||||
|
Completed (Sorted in descending order of time added)
|
||||||
|
|
||||||
public ContributionDao(ContentProviderClient client) {
|
This is why Contribution.STATE_COMPLETED is -1.
|
||||||
this.client = client;
|
*/
|
||||||
|
static final String CONTRIBUTION_SORT = Table.COLUMN_STATE + " DESC, "
|
||||||
|
+ Table.COLUMN_UPLOADED + " DESC , ("
|
||||||
|
+ Table.COLUMN_TIMESTAMP + " * "
|
||||||
|
+ Table.COLUMN_STATE + ")";
|
||||||
|
|
||||||
|
private final Provider<ContentProviderClient> clientProvider;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ContributionDao(@Named("contribution") Provider<ContentProviderClient> clientProvider) {
|
||||||
|
this.clientProvider = clientProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cursor loadAllContributions() {
|
||||||
|
ContentProviderClient db = clientProvider.get();
|
||||||
|
try {
|
||||||
|
return db.query(BASE_URI, ALL_FIELDS, "", null, CONTRIBUTION_SORT);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
db.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContentValues toContentValues(Contribution contribution) {
|
ContentValues toContentValues(Contribution contribution) {
|
||||||
ContentValues cv = new ContentValues();
|
ContentValues cv = new ContentValues();
|
||||||
cv.put(Table.COLUMN_FILENAME, contribution.getFilename());
|
cv.put(Table.COLUMN_FILENAME, contribution.getFilename());
|
||||||
if (contribution.getLocalUri() != null) {
|
if (contribution.getLocalUri() != null) {
|
||||||
|
|
@ -74,7 +111,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;
|
||||||
|
|
@ -65,21 +65,6 @@ public class ContributionsActivity
|
||||||
private UploadService uploadService;
|
private UploadService uploadService;
|
||||||
private boolean isUploadServiceConnected;
|
private boolean isUploadServiceConnected;
|
||||||
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>();
|
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>();
|
||||||
private String CONTRIBUTION_SELECTION = "";
|
|
||||||
|
|
||||||
/*
|
|
||||||
This sorts in the following order:
|
|
||||||
Currently Uploading
|
|
||||||
Failed (Sorted in ascending order of time added - FIFO)
|
|
||||||
Queued to Upload (Sorted in ascending order of time added - FIFO)
|
|
||||||
Completed (Sorted in descending order of time added)
|
|
||||||
|
|
||||||
This is why Contribution.STATE_COMPLETED is -1.
|
|
||||||
*/
|
|
||||||
private String CONTRIBUTION_SORT = ContributionDao.Table.COLUMN_STATE + " DESC, "
|
|
||||||
+ ContributionDao.Table.COLUMN_UPLOADED + " DESC , ("
|
|
||||||
+ ContributionDao.Table.COLUMN_TIMESTAMP + " * "
|
|
||||||
+ ContributionDao.Table.COLUMN_STATE + ")";
|
|
||||||
|
|
||||||
private CompositeDisposable compositeDisposable = new CompositeDisposable();
|
private CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||||
|
|
||||||
|
|
@ -121,14 +106,13 @@ 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);
|
||||||
bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
allContributions = getContentResolver().query(BASE_URI, ALL_FIELDS,
|
allContributions = contributionDao.loadAllContributions();
|
||||||
CONTRIBUTION_SELECTION, null, CONTRIBUTION_SORT);
|
|
||||||
|
|
||||||
getSupportLoaderManager().initLoader(0, null, this);
|
getSupportLoaderManager().initLoader(0, null, this);
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +170,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 +181,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());
|
||||||
}
|
}
|
||||||
|
|
@ -238,8 +222,8 @@ public class ContributionsActivity
|
||||||
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
|
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
|
||||||
int uploads = prefs.getInt(UPLOADS_SHOWING, 100);
|
int uploads = prefs.getInt(UPLOADS_SHOWING, 100);
|
||||||
return new CursorLoader(this, BASE_URI,
|
return new CursorLoader(this, BASE_URI,
|
||||||
ALL_FIELDS, CONTRIBUTION_SELECTION, null,
|
ALL_FIELDS, "", null,
|
||||||
CONTRIBUTION_SORT + "LIMIT " + uploads);
|
ContributionDao.CONTRIBUTION_SORT + "LIMIT " + uploads);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -248,7 +232,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 +253,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());
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||||
LogEventResult result;
|
LogEventResult result;
|
||||||
Boolean done = false;
|
Boolean done = false;
|
||||||
String queryContinue = null;
|
String queryContinue = null;
|
||||||
|
ContributionDao contributionDao = new ContributionDao(() -> contentProviderClient);
|
||||||
while (!done) {
|
while (!done) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -121,7 +122,7 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||||
"", -1, dateUpdated, dateUpdated, user,
|
"", -1, dateUpdated, dateUpdated, user,
|
||||||
"", "");
|
"", "");
|
||||||
contrib.setState(STATE_COMPLETED);
|
contrib.setState(STATE_COMPLETED);
|
||||||
imageValues.add(ContributionDao.toContentValues(contrib));
|
imageValues.add(contributionDao.toContentValues(contrib));
|
||||||
|
|
||||||
if (imageValues.size() % COMMIT_THRESHOLD == 0) {
|
if (imageValues.size() % COMMIT_THRESHOLD == 0) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.category.CategoryDao;
|
||||||
import fr.free.nrw.commons.contributions.ContributionDao;
|
import fr.free.nrw.commons.contributions.ContributionDao;
|
||||||
import fr.free.nrw.commons.modifications.ModifierSequenceDao;
|
import fr.free.nrw.commons.modifications.ModifierSequenceDao;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package fr.free.nrw.commons.di;
|
package fr.free.nrw.commons.di;
|
||||||
|
|
||||||
|
import android.content.ContentProviderClient;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.util.LruCache;
|
import android.support.v4.util.LruCache;
|
||||||
|
|
@ -22,10 +23,14 @@ 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;
|
||||||
|
import static fr.free.nrw.commons.modifications.ModificationsContentProvider.MODIFICATIONS_AUTHORITY;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||||
public class CommonsApplicationModule {
|
public class CommonsApplicationModule {
|
||||||
|
public static final String CATEGORY_AUTHORITY = "fr.free.nrw.commons.categories.contentprovider";
|
||||||
|
|
||||||
private CommonsApplication application;
|
private CommonsApplication application;
|
||||||
|
|
||||||
public CommonsApplicationModule(CommonsApplication application) {
|
public CommonsApplicationModule(CommonsApplication application) {
|
||||||
|
|
@ -37,6 +42,24 @@ public class CommonsApplicationModule {
|
||||||
return new AccountUtil(application);
|
return new AccountUtil(application);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Named("category")
|
||||||
|
public ContentProviderClient provideCategoryContentProviderClient() {
|
||||||
|
return application.getContentResolver().acquireContentProviderClient(CATEGORY_AUTHORITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Named("contribution")
|
||||||
|
public ContentProviderClient provideContributionContentProviderClient() {
|
||||||
|
return application.getContentResolver().acquireContentProviderClient(CONTRIBUTION_AUTHORITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Named("modification")
|
||||||
|
public ContentProviderClient provideModificationContentProviderClient() {
|
||||||
|
return application.getContentResolver().acquireContentProviderClient(MODIFICATIONS_AUTHORITY);
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Named("application_preferences")
|
@Named("application_preferences")
|
||||||
public SharedPreferences providesApplicationSharedPreferences() {
|
public SharedPreferences providesApplicationSharedPreferences() {
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,15 @@ public class ModificationsContentProvider extends ContentProvider {
|
||||||
private static final int MODIFICATIONS = 1;
|
private static final int MODIFICATIONS = 1;
|
||||||
private static final int MODIFICATIONS_ID = 2;
|
private static final int MODIFICATIONS_ID = 2;
|
||||||
|
|
||||||
public static final String AUTHORITY = "fr.free.nrw.commons.modifications.contentprovider";
|
public static final String MODIFICATIONS_AUTHORITY = "fr.free.nrw.commons.modifications.contentprovider";
|
||||||
public static final String BASE_PATH = "modifications";
|
public static final String BASE_PATH = "modifications";
|
||||||
|
|
||||||
public static final Uri BASE_URI = Uri.parse("content://" + AUTHORITY + "/" + BASE_PATH);
|
public static final Uri BASE_URI = Uri.parse("content://" + MODIFICATIONS_AUTHORITY + "/" + BASE_PATH);
|
||||||
|
|
||||||
private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||||
static {
|
static {
|
||||||
uriMatcher.addURI(AUTHORITY, BASE_PATH, MODIFICATIONS);
|
uriMatcher.addURI(MODIFICATIONS_AUTHORITY, BASE_PATH, MODIFICATIONS);
|
||||||
uriMatcher.addURI(AUTHORITY, BASE_PATH + "/#", MODIFICATIONS_ID);
|
uriMatcher.addURI(MODIFICATIONS_AUTHORITY, BASE_PATH + "/#", MODIFICATIONS_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Uri uriForId(int id) {
|
public static Uri uriForId(int id) {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ import timber.log.Timber;
|
||||||
public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||||
|
|
||||||
@Inject MediaWikiApi mwApi;
|
@Inject MediaWikiApi mwApi;
|
||||||
|
@Inject ContributionDao contributionDao;
|
||||||
|
@Inject ModifierSequenceDao modifierSequenceDao;
|
||||||
|
|
||||||
public ModificationsSyncAdapter(Context context, boolean autoInitialize) {
|
public ModificationsSyncAdapter(Context context, boolean autoInitialize) {
|
||||||
super(context, autoInitialize);
|
super(context, autoInitialize);
|
||||||
|
|
@ -80,11 +82,10 @@ 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);
|
||||||
ModifierSequenceDao dao = new ModifierSequenceDao(contributionsClient);
|
|
||||||
Contribution contrib;
|
Contribution contrib;
|
||||||
|
|
||||||
Cursor contributionCursor;
|
Cursor contributionCursor;
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -122,7 +123,7 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||||
// FIXME: Log this somewhere else
|
// FIXME: Log this somewhere else
|
||||||
Timber.d("Non success result! %s", editResult);
|
Timber.d("Non success result! %s", editResult);
|
||||||
} else {
|
} else {
|
||||||
dao.delete(sequence);
|
modifierSequenceDao.delete(sequence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allModifications.moveToNext();
|
allModifications.moveToNext();
|
||||||
|
|
|
||||||
|
|
@ -11,20 +11,51 @@ import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
public class ModifierSequenceDao {
|
public class ModifierSequenceDao {
|
||||||
|
|
||||||
private final ContentProviderClient client;
|
private final Provider<ContentProviderClient> clientProvider;
|
||||||
|
|
||||||
public ModifierSequenceDao(ContentProviderClient client) {
|
@Inject
|
||||||
this.client = client;
|
public ModifierSequenceDao(@Named("modification") Provider<ContentProviderClient> clientProvider) {
|
||||||
|
this.clientProvider = clientProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ModifierSequence fromCursor(Cursor cursor) {
|
public void save(ModifierSequence sequence) {
|
||||||
|
ContentProviderClient db = clientProvider.get();
|
||||||
|
try {
|
||||||
|
if (sequence.getContentUri() == null) {
|
||||||
|
sequence.setContentUri(db.insert(ModificationsContentProvider.BASE_URI, toContentValues(sequence)));
|
||||||
|
} else {
|
||||||
|
db.update(sequence.getContentUri(), toContentValues(sequence), null, null);
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
db.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(ModifierSequence sequence) {
|
||||||
|
ContentProviderClient db = clientProvider.get();
|
||||||
|
try {
|
||||||
|
db.delete(sequence.getContentUri(), null, null);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
db.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ModifierSequence fromCursor(Cursor cursor) {
|
||||||
// Hardcoding column positions!
|
// Hardcoding column positions!
|
||||||
ModifierSequence ms = null;
|
ModifierSequence ms = null;
|
||||||
try {
|
try {
|
||||||
ms = new ModifierSequence(Uri.parse(cursor.getString(1)),
|
ms = new ModifierSequence(Uri.parse(cursor.getString(1)),
|
||||||
new JSONObject(cursor.getString(2)));
|
new JSONObject(cursor.getString(2)));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
@ -33,26 +64,6 @@ public class ModifierSequenceDao {
|
||||||
return ms;
|
return ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(ModifierSequence sequence) {
|
|
||||||
try {
|
|
||||||
if (sequence.getContentUri() == null) {
|
|
||||||
sequence.setContentUri(client.insert(ModificationsContentProvider.BASE_URI, toContentValues(sequence)));
|
|
||||||
} else {
|
|
||||||
client.update(sequence.getContentUri(), toContentValues(sequence), null, null);
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete(ModifierSequence sequence) {
|
|
||||||
try {
|
|
||||||
client.delete(sequence.getContentUri(), null, null);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private JSONObject toJSON(ModifierSequence sequence) {
|
private JSONObject toJSON(ModifierSequence sequence) {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package fr.free.nrw.commons.upload;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.ContentProviderClient;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
@ -55,6 +54,7 @@ public class MultipleShareActivity extends AuthenticatedActivity
|
||||||
@Inject MediaWikiApi mwApi;
|
@Inject MediaWikiApi mwApi;
|
||||||
@Inject SessionManager sessionManager;
|
@Inject SessionManager sessionManager;
|
||||||
@Inject UploadController uploadController;
|
@Inject UploadController uploadController;
|
||||||
|
@Inject ModifierSequenceDao modifierSequenceDao;
|
||||||
@Inject @Named("default_preferences") SharedPreferences prefs;
|
@Inject @Named("default_preferences") SharedPreferences prefs;
|
||||||
|
|
||||||
private ArrayList<Contribution> photosList = null;
|
private ArrayList<Contribution> photosList = null;
|
||||||
|
|
@ -166,19 +166,18 @@ public class MultipleShareActivity extends AuthenticatedActivity
|
||||||
@Override
|
@Override
|
||||||
public void onCategoriesSave(List<String> categories) {
|
public void onCategoriesSave(List<String> categories) {
|
||||||
if (categories.size() > 0) {
|
if (categories.size() > 0) {
|
||||||
ModifierSequenceDao dao = new ModifierSequenceDao(getContentResolver().acquireContentProviderClient(ModificationsContentProvider.AUTHORITY));
|
|
||||||
for (Contribution contribution : photosList) {
|
for (Contribution contribution : photosList) {
|
||||||
ModifierSequence categoriesSequence = new ModifierSequence(contribution.getContentUri());
|
ModifierSequence categoriesSequence = new ModifierSequence(contribution.getContentUri());
|
||||||
|
|
||||||
categoriesSequence.queueModifier(new CategoryModifier(categories.toArray(new String[]{})));
|
categoriesSequence.queueModifier(new CategoryModifier(categories.toArray(new String[]{})));
|
||||||
categoriesSequence.queueModifier(new TemplateRemoveModifier("Uncategorized"));
|
categoriesSequence.queueModifier(new TemplateRemoveModifier("Uncategorized"));
|
||||||
|
|
||||||
dao.save(categoriesSequence);
|
modifierSequenceDao.save(categoriesSequence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// FIXME: Make sure that the content provider is up
|
// FIXME: Make sure that the content provider is up
|
||||||
// This is the wrong place for it, but bleh - better than not having it turned on by default for people who don't go throughl ogin
|
// This is the wrong place for it, but bleh - better than not having it turned on by default for people who don't go throughl ogin
|
||||||
ContentResolver.setSyncAutomatically(sessionManager.getCurrentAccount(), ModificationsContentProvider.AUTHORITY, true); // Enable sync by default!
|
ContentResolver.setSyncAutomatically(sessionManager.getCurrentAccount(), ModificationsContentProvider.MODIFICATIONS_AUTHORITY, true); // Enable sync by default!
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ public class ShareActivity
|
||||||
@Inject CacheController cacheController;
|
@Inject CacheController cacheController;
|
||||||
@Inject SessionManager sessionManager;
|
@Inject SessionManager sessionManager;
|
||||||
@Inject UploadController uploadController;
|
@Inject UploadController uploadController;
|
||||||
|
@Inject ModifierSequenceDao modifierSequenceDao;
|
||||||
@Inject @Named("default_preferences") SharedPreferences prefs;
|
@Inject @Named("default_preferences") SharedPreferences prefs;
|
||||||
|
|
||||||
private String source;
|
private String source;
|
||||||
|
|
@ -166,13 +167,12 @@ public class ShareActivity
|
||||||
|
|
||||||
categoriesSequence.queueModifier(new CategoryModifier(categories.toArray(new String[]{})));
|
categoriesSequence.queueModifier(new CategoryModifier(categories.toArray(new String[]{})));
|
||||||
categoriesSequence.queueModifier(new TemplateRemoveModifier("Uncategorized"));
|
categoriesSequence.queueModifier(new TemplateRemoveModifier("Uncategorized"));
|
||||||
ModifierSequenceDao dao = new ModifierSequenceDao(getContentResolver().acquireContentProviderClient(ModificationsContentProvider.AUTHORITY));
|
modifierSequenceDao.save(categoriesSequence);
|
||||||
dao.save(categoriesSequence);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Make sure that the content provider is up
|
// FIXME: Make sure that the content provider is up
|
||||||
// This is the wrong place for it, but bleh - better than not having it turned on by default for people who don't go throughl ogin
|
// This is the wrong place for it, but bleh - better than not having it turned on by default for people who don't go throughl ogin
|
||||||
ContentResolver.setSyncAutomatically(sessionManager.getCurrentAccount(), ModificationsContentProvider.AUTHORITY, true); // Enable sync by default!
|
ContentResolver.setSyncAutomatically(sessionManager.getCurrentAccount(), ModificationsContentProvider.MODIFICATIONS_AUTHORITY, true); // Enable sync by default!
|
||||||
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.ContentProviderClient;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
@ -52,9 +51,9 @@ 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 NotificationCompat.Builder curProgressNotification;
|
private NotificationCompat.Builder curProgressNotification;
|
||||||
private int toUpload;
|
private int toUpload;
|
||||||
|
|
||||||
|
|
@ -67,7 +66,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 +105,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -115,7 +113,6 @@ public class UploadService extends HandlerService<Contribution> {
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
contributionsProviderClient.release();
|
|
||||||
Timber.d("UploadService.onDestroy; %s are yet to be uploaded", unfinishedUploads);
|
Timber.d("UploadService.onDestroy; %s are yet to be uploaded", unfinishedUploads);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,8 +121,6 @@ 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);
|
|
||||||
dao = new ContributionDao(contributionsProviderClient);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -147,7 +142,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 +257,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");
|
||||||
|
|
@ -274,7 +269,7 @@ public class UploadService extends HandlerService<Contribution> {
|
||||||
toUpload--;
|
toUpload--;
|
||||||
if (toUpload == 0) {
|
if (toUpload == 0) {
|
||||||
// Sync modifications right after all uplaods are processed
|
// Sync modifications right after all uplaods are processed
|
||||||
ContentResolver.requestSync(sessionManager.getCurrentAccount(), ModificationsContentProvider.AUTHORITY, new Bundle());
|
ContentResolver.requestSync(sessionManager.getCurrentAccount(), ModificationsContentProvider.MODIFICATIONS_AUTHORITY, new Bundle());
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -293,7 +288,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 {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package fr.free.nrw.commons.data;
|
package fr.free.nrw.commons.category;
|
||||||
|
|
||||||
import android.content.ContentProviderClient;
|
import android.content.ContentProviderClient;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
|
@ -27,8 +27,7 @@ import java.util.List;
|
||||||
|
|
||||||
import fr.free.nrw.commons.BuildConfig;
|
import fr.free.nrw.commons.BuildConfig;
|
||||||
import fr.free.nrw.commons.TestCommonsApplication;
|
import fr.free.nrw.commons.TestCommonsApplication;
|
||||||
import fr.free.nrw.commons.category.CategoryContentProvider;
|
import fr.free.nrw.commons.category.CategoryDao.Table;
|
||||||
import fr.free.nrw.commons.data.CategoryDao.Table;
|
|
||||||
|
|
||||||
import static fr.free.nrw.commons.category.CategoryContentProvider.BASE_URI;
|
import static fr.free.nrw.commons.category.CategoryContentProvider.BASE_URI;
|
||||||
import static fr.free.nrw.commons.category.CategoryContentProvider.uriForId;
|
import static fr.free.nrw.commons.category.CategoryContentProvider.uriForId;
|
||||||
|
|
@ -50,20 +49,20 @@ import static org.mockito.Mockito.when;
|
||||||
public class CategoryDaoTest {
|
public class CategoryDaoTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
ContentProviderClient client;
|
private ContentProviderClient client;
|
||||||
@Mock
|
@Mock
|
||||||
SQLiteDatabase database;
|
private SQLiteDatabase database;
|
||||||
@Captor
|
@Captor
|
||||||
ArgumentCaptor<ContentValues> captor;
|
private ArgumentCaptor<ContentValues> captor;
|
||||||
@Captor
|
@Captor
|
||||||
ArgumentCaptor<String[]> queryCaptor;
|
private ArgumentCaptor<String[]> queryCaptor;
|
||||||
|
|
||||||
private CategoryDao testObject;
|
private CategoryDao testObject;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
testObject = new CategoryDao(client);
|
testObject = new CategoryDao(() -> client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -52,14 +52,14 @@ public class ModifierSequenceDaoTest {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
testObject = new ModifierSequenceDao(client);
|
testObject = new ModifierSequenceDao(() -> client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createFromCursorWithEmptyModifiers() {
|
public void createFromCursorWithEmptyModifiers() {
|
||||||
MatrixCursor cursor = createCursor("");
|
MatrixCursor cursor = createCursor("");
|
||||||
|
|
||||||
ModifierSequence seq = ModifierSequenceDao.fromCursor(cursor);
|
ModifierSequence seq = testObject.fromCursor(cursor);
|
||||||
|
|
||||||
assertEquals(EXPECTED_MEDIA_URI, seq.getMediaUri().toString());
|
assertEquals(EXPECTED_MEDIA_URI, seq.getMediaUri().toString());
|
||||||
assertEquals(BASE_URI.buildUpon().appendPath("1").toString(), seq.getContentUri().toString());
|
assertEquals(BASE_URI.buildUpon().appendPath("1").toString(), seq.getContentUri().toString());
|
||||||
|
|
@ -70,7 +70,7 @@ public class ModifierSequenceDaoTest {
|
||||||
public void createFromCursorWtihCategoryModifier() {
|
public void createFromCursorWtihCategoryModifier() {
|
||||||
MatrixCursor cursor = createCursor("{\"name\": \"CategoriesModifier\", \"data\": {}}");
|
MatrixCursor cursor = createCursor("{\"name\": \"CategoriesModifier\", \"data\": {}}");
|
||||||
|
|
||||||
ModifierSequence seq = ModifierSequenceDao.fromCursor(cursor);
|
ModifierSequence seq = testObject.fromCursor(cursor);
|
||||||
|
|
||||||
assertEquals(1, seq.getModifiers().size());
|
assertEquals(1, seq.getModifiers().size());
|
||||||
assertTrue(seq.getModifiers().get(0) instanceof CategoryModifier);
|
assertTrue(seq.getModifiers().get(0) instanceof CategoryModifier);
|
||||||
|
|
@ -80,7 +80,7 @@ public class ModifierSequenceDaoTest {
|
||||||
public void createFromCursorWithRemoveModifier() {
|
public void createFromCursorWithRemoveModifier() {
|
||||||
MatrixCursor cursor = createCursor("{\"name\": \"TemplateRemoverModifier\", \"data\": {}}");
|
MatrixCursor cursor = createCursor("{\"name\": \"TemplateRemoverModifier\", \"data\": {}}");
|
||||||
|
|
||||||
ModifierSequence seq = ModifierSequenceDao.fromCursor(cursor);
|
ModifierSequence seq = testObject.fromCursor(cursor);
|
||||||
|
|
||||||
assertEquals(1, seq.getModifiers().size());
|
assertEquals(1, seq.getModifiers().size());
|
||||||
assertTrue(seq.getModifiers().get(0) instanceof TemplateRemoveModifier);
|
assertTrue(seq.getModifiers().get(0) instanceof TemplateRemoveModifier);
|
||||||
|
|
@ -89,7 +89,7 @@ public class ModifierSequenceDaoTest {
|
||||||
@Test
|
@Test
|
||||||
public void deleteSequence() throws Exception {
|
public void deleteSequence() throws Exception {
|
||||||
when(client.delete(isA(Uri.class), isNull(String.class), isNull(String[].class))).thenReturn(1);
|
when(client.delete(isA(Uri.class), isNull(String.class), isNull(String[].class))).thenReturn(1);
|
||||||
ModifierSequence seq = ModifierSequenceDao.fromCursor(createCursor(""));
|
ModifierSequence seq = testObject.fromCursor(createCursor(""));
|
||||||
|
|
||||||
testObject.delete(seq);
|
testObject.delete(seq);
|
||||||
|
|
||||||
|
|
@ -99,7 +99,7 @@ public class ModifierSequenceDaoTest {
|
||||||
@Test(expected = RuntimeException.class)
|
@Test(expected = RuntimeException.class)
|
||||||
public void deleteTranslatesRemoteExceptions() throws Exception {
|
public void deleteTranslatesRemoteExceptions() throws Exception {
|
||||||
when(client.delete(isA(Uri.class), isNull(String.class), isNull(String[].class))).thenThrow(new RemoteException(""));
|
when(client.delete(isA(Uri.class), isNull(String.class), isNull(String[].class))).thenThrow(new RemoteException(""));
|
||||||
ModifierSequence seq = ModifierSequenceDao.fromCursor(createCursor(""));
|
ModifierSequence seq = testObject.fromCursor(createCursor(""));
|
||||||
|
|
||||||
testObject.delete(seq);
|
testObject.delete(seq);
|
||||||
}
|
}
|
||||||
|
|
@ -110,9 +110,9 @@ public class ModifierSequenceDaoTest {
|
||||||
String expectedData = "{\"modifiers\":[" + modifierJson + "]}";
|
String expectedData = "{\"modifiers\":[" + modifierJson + "]}";
|
||||||
MatrixCursor cursor = createCursor(modifierJson);
|
MatrixCursor cursor = createCursor(modifierJson);
|
||||||
|
|
||||||
testObject.save(ModifierSequenceDao.fromCursor(cursor));
|
testObject.save(testObject.fromCursor(cursor));
|
||||||
|
|
||||||
verify(client).update(eq(ModifierSequenceDao.fromCursor(cursor).getContentUri()), contentValuesCaptor.capture(), isNull(String.class), isNull(String[].class));
|
verify(client).update(eq(testObject.fromCursor(cursor).getContentUri()), contentValuesCaptor.capture(), isNull(String.class), isNull(String[].class));
|
||||||
ContentValues cv = contentValuesCaptor.getValue();
|
ContentValues cv = contentValuesCaptor.getValue();
|
||||||
assertEquals(2, cv.size());
|
assertEquals(2, cv.size());
|
||||||
assertEquals(EXPECTED_MEDIA_URI, cv.get(ModifierSequenceDao.Table.COLUMN_MEDIA_URI));
|
assertEquals(EXPECTED_MEDIA_URI, cv.get(ModifierSequenceDao.Table.COLUMN_MEDIA_URI));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue