Merge pull request #1176 from hismaeel/1119

Fixed Hard Coded Column issue. #1119
This commit is contained in:
neslihanturan 2018-03-16 11:09:47 +02:00 committed by GitHub
commit eaba96b509
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 23 deletions

View file

@ -108,10 +108,10 @@ public class CategoryDao {
Category fromCursor(Cursor cursor) { Category fromCursor(Cursor cursor) {
// Hardcoding column positions! // Hardcoding column positions!
return new Category( return new Category(
CategoryContentProvider.uriForId(cursor.getInt(0)), CategoryContentProvider.uriForId(cursor.getInt(cursor.getColumnIndex(Table.COLUMN_ID))),
cursor.getString(1), cursor.getString(cursor.getColumnIndex(Table.COLUMN_NAME)),
new Date(cursor.getLong(2)), new Date(cursor.getLong(cursor.getColumnIndex(Table.COLUMN_LAST_USED))),
cursor.getInt(3) cursor.getInt(cursor.getColumnIndex(Table.COLUMN_TIMES_USED))
); );
} }

View file

@ -8,6 +8,7 @@ import android.net.Uri;
import android.os.RemoteException; import android.os.RemoteException;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import java.util.Date; import java.util.Date;
@ -115,23 +116,30 @@ public class ContributionDao {
// 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) {
int index;
if (cursor.getColumnIndex(Table.COLUMN_LICENSE) == -1){
index = 15;
} else {
index = cursor.getColumnIndex(Table.COLUMN_LICENSE);
}
return new Contribution( return new Contribution(
uriForId(cursor.getInt(0)), uriForId(cursor.getInt(cursor.getColumnIndex(Table.COLUMN_ID))),
cursor.getString(1), cursor.getString(cursor.getColumnIndex(Table.COLUMN_FILENAME)),
parseUri(cursor.getString(2)), parseUri(cursor.getString(cursor.getColumnIndex(Table.COLUMN_LOCAL_URI))),
cursor.getString(3), cursor.getString(cursor.getColumnIndex(Table.COLUMN_IMAGE_URL)),
parseTimestamp(cursor.getLong(4)), parseTimestamp(cursor.getLong(cursor.getColumnIndex(Table.COLUMN_TIMESTAMP))),
cursor.getInt(5), cursor.getInt(cursor.getColumnIndex(Table.COLUMN_STATE)),
cursor.getLong(6), cursor.getLong(cursor.getColumnIndex(Table.COLUMN_LENGTH)),
parseTimestamp(cursor.getLong(7)), parseTimestamp(cursor.getLong(cursor.getColumnIndex(Table.COLUMN_UPLOADED))),
cursor.getLong(8), cursor.getLong(cursor.getColumnIndex(Table.COLUMN_TRANSFERRED)),
cursor.getString(9), cursor.getString(cursor.getColumnIndex(Table.COLUMN_SOURCE)),
cursor.getString(10), cursor.getString(cursor.getColumnIndex(Table.COLUMN_DESCRIPTION)),
cursor.getString(11), cursor.getString(cursor.getColumnIndex(Table.COLUMN_CREATOR)),
cursor.getInt(12) == 1, cursor.getInt(cursor.getColumnIndex(Table.COLUMN_MULTIPLE)) == 1,
cursor.getInt(13), cursor.getInt(cursor.getColumnIndex(Table.COLUMN_WIDTH)),
cursor.getInt(14), cursor.getInt(cursor.getColumnIndex(Table.COLUMN_HEIGHT)),
cursor.getString(15)); cursor.getString(index)
);
} }
return null; return null;

View file

@ -54,12 +54,12 @@ public class ModifierSequenceDao {
// Hardcoding column positions! // Hardcoding column positions!
ModifierSequence ms; ModifierSequence ms;
try { try {
ms = new ModifierSequence(Uri.parse(cursor.getString(1)), ms = new ModifierSequence(Uri.parse(cursor.getString(cursor.getColumnIndex(Table.COLUMN_MEDIA_URI))),
new JSONObject(cursor.getString(2))); new JSONObject(cursor.getString(cursor.getColumnIndex(Table.COLUMN_DATA))));
} catch (JSONException e) { } catch (JSONException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
ms.setContentUri( ModificationsContentProvider.uriForId(cursor.getInt(0))); ms.setContentUri( ModificationsContentProvider.uriForId(cursor.getInt(cursor.getColumnIndex(Table.COLUMN_ID))));
return ms; return ms;
} }