Skip to content

Commit 691acbf

Browse files
authored
Merge pull request commons-app#768 from tised/#733_#732_fix
fix for commons-app#733,732 issue
2 parents e132012 + 8697909 commit 691acbf

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsContentProvider.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.text.TextUtils;
1111

1212
import fr.free.nrw.commons.CommonsApplication;
13-
import fr.free.nrw.commons.data.DBOpenHelper;
1413
import timber.log.Timber;
1514

1615
public class ContributionsContentProvider extends ContentProvider{
@@ -33,10 +32,8 @@ public static Uri uriForId(int id) {
3332
return Uri.parse(BASE_URI.toString() + "/" + id);
3433
}
3534

36-
private DBOpenHelper dbOpenHelper;
3735
@Override
3836
public boolean onCreate() {
39-
dbOpenHelper = CommonsApplication.getInstance().getDBOpenHelper();
4037
return false;
4138
}
4239

@@ -47,7 +44,7 @@ public Cursor query(Uri uri, String[] projection, String selection, String[] sel
4744

4845
int uriType = uriMatcher.match(uri);
4946

50-
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
47+
SQLiteDatabase db = CommonsApplication.getInstance().getDBOpenHelper().getReadableDatabase();
5148
Cursor cursor;
5249

5350
switch(uriType) {
@@ -81,7 +78,7 @@ public String getType(Uri uri) {
8178
@Override
8279
public Uri insert(Uri uri, ContentValues contentValues) {
8380
int uriType = uriMatcher.match(uri);
84-
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
81+
SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
8582
long id = 0;
8683
switch (uriType) {
8784
case CONTRIBUTIONS:
@@ -99,7 +96,7 @@ public int delete(Uri uri, String s, String[] strings) {
9996
int rows = 0;
10097
int uriType = uriMatcher.match(uri);
10198

102-
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
99+
SQLiteDatabase db = CommonsApplication.getInstance().getDBOpenHelper().getReadableDatabase();
103100

104101
switch(uriType) {
105102
case CONTRIBUTIONS_ID:
@@ -120,7 +117,7 @@ public int delete(Uri uri, String s, String[] strings) {
120117
public int bulkInsert(Uri uri, ContentValues[] values) {
121118
Timber.d("Hello, bulk insert! (ContributionsContentProvider)");
122119
int uriType = uriMatcher.match(uri);
123-
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
120+
SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
124121
sqlDB.beginTransaction();
125122
switch (uriType) {
126123
case CONTRIBUTIONS:
@@ -148,7 +145,7 @@ public int update(Uri uri, ContentValues contentValues, String selection, String
148145
In here, the only concat created argument is for id. It is cast to an int, and will error out otherwise.
149146
*/
150147
int uriType = uriMatcher.match(uri);
151-
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
148+
SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
152149
int rowsUpdated = 0;
153150
switch (uriType) {
154151
case CONTRIBUTIONS:

app/src/main/java/fr/free/nrw/commons/modifications/ModificationsContentProvider.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.text.TextUtils;
1111

1212
import fr.free.nrw.commons.CommonsApplication;
13-
import fr.free.nrw.commons.data.DBOpenHelper;
1413
import timber.log.Timber;
1514

1615
public class ModificationsContentProvider extends ContentProvider{
@@ -33,10 +32,9 @@ public static Uri uriForId(int id) {
3332
return Uri.parse(BASE_URI.toString() + "/" + id);
3433
}
3534

36-
private DBOpenHelper dbOpenHelper;
35+
3736
@Override
3837
public boolean onCreate() {
39-
dbOpenHelper = CommonsApplication.getInstance().getDBOpenHelper();
4038
return false;
4139
}
4240

@@ -54,7 +52,7 @@ public Cursor query(Uri uri, String[] projection, String selection, String[] sel
5452
throw new IllegalArgumentException("Unknown URI" + uri);
5553
}
5654

57-
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
55+
SQLiteDatabase db = CommonsApplication.getInstance().getDBOpenHelper().getReadableDatabase();
5856

5957
Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
6058
cursor.setNotificationUri(getContext().getContentResolver(), uri);
@@ -70,7 +68,7 @@ public String getType(Uri uri) {
7068
@Override
7169
public Uri insert(Uri uri, ContentValues contentValues) {
7270
int uriType = uriMatcher.match(uri);
73-
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
71+
SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
7472
long id = 0;
7573
switch (uriType) {
7674
case MODIFICATIONS:
@@ -86,7 +84,7 @@ public Uri insert(Uri uri, ContentValues contentValues) {
8684
@Override
8785
public int delete(Uri uri, String s, String[] strings) {
8886
int uriType = uriMatcher.match(uri);
89-
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
87+
SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
9088
switch (uriType) {
9189
case MODIFICATIONS_ID:
9290
String id = uri.getLastPathSegment();
@@ -104,7 +102,7 @@ public int delete(Uri uri, String s, String[] strings) {
104102
public int bulkInsert(Uri uri, ContentValues[] values) {
105103
Timber.d("Hello, bulk insert! (ModificationsContentProvider)");
106104
int uriType = uriMatcher.match(uri);
107-
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
105+
SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
108106
sqlDB.beginTransaction();
109107
switch (uriType) {
110108
case MODIFICATIONS:
@@ -132,7 +130,7 @@ public int update(Uri uri, ContentValues contentValues, String selection, String
132130
In here, the only concat created argument is for id. It is cast to an int, and will error out otherwise.
133131
*/
134132
int uriType = uriMatcher.match(uri);
135-
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
133+
SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase();
136134
int rowsUpdated = 0;
137135
switch (uriType) {
138136
case MODIFICATIONS:

0 commit comments

Comments
 (0)