Don't retrieve the column index again and again in a long loop
Also: fix weird iteration logic
This commit is contained in:
parent
2da50e27c2
commit
87023ebdb3
|
@ -221,17 +221,20 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl
|
||||||
try (SQLiteDatabase db = this.getReadableDatabase()) {
|
try (SQLiteDatabase db = this.getReadableDatabase()) {
|
||||||
try (Cursor cursor = db.query(TABLE_GBACTIVITYSAMPLES, null, where, null, null, null, order)) {
|
try (Cursor cursor = db.query(TABLE_GBACTIVITYSAMPLES, null, where, null, null, null, order)) {
|
||||||
LOG.info("Activity query result: " + cursor.getCount() + " samples");
|
LOG.info("Activity query result: " + cursor.getCount() + " samples");
|
||||||
if (cursor.moveToFirst()) {
|
int colTimeStamp = cursor.getColumnIndex(KEY_TIMESTAMP);
|
||||||
do {
|
int colIntensity = cursor.getColumnIndex(KEY_INTENSITY);
|
||||||
|
int colSteps = cursor.getColumnIndex(KEY_STEPS);
|
||||||
|
int colType = cursor.getColumnIndex(KEY_TYPE);
|
||||||
|
int colCustomShort = cursor.getColumnIndex(KEY_CUSTOM_SHORT);
|
||||||
|
while (cursor.moveToFirst()) {
|
||||||
GBActivitySample sample = new GBActivitySample(
|
GBActivitySample sample = new GBActivitySample(
|
||||||
provider,
|
provider,
|
||||||
cursor.getInt(cursor.getColumnIndex(KEY_TIMESTAMP)),
|
cursor.getInt(colTimeStamp),
|
||||||
cursor.getInt(cursor.getColumnIndex(KEY_INTENSITY)),
|
cursor.getInt(colIntensity),
|
||||||
cursor.getInt(cursor.getColumnIndex(KEY_STEPS)),
|
cursor.getInt(colSteps),
|
||||||
cursor.getInt(cursor.getColumnIndex(KEY_TYPE)),
|
cursor.getInt(colType),
|
||||||
cursor.getInt(cursor.getColumnIndex(KEY_CUSTOM_SHORT)));
|
cursor.getInt(colCustomShort));
|
||||||
samples.add(sample);
|
samples.add(sample);
|
||||||
} while (cursor.moveToNext());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,7 @@ public class K9Receiver extends BroadcastReceiver {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
c.moveToFirst();
|
while (c.moveToFirst()) {
|
||||||
do {
|
|
||||||
String uri = c.getString(c.getColumnIndex("uri"));
|
String uri = c.getString(c.getColumnIndex("uri"));
|
||||||
if (uri.equals(uriWanted)) {
|
if (uri.equals(uriWanted)) {
|
||||||
notificationSpec.sender = c.getString(c.getColumnIndex("senderAddress"));
|
notificationSpec.sender = c.getString(c.getColumnIndex("senderAddress"));
|
||||||
|
@ -76,7 +75,7 @@ public class K9Receiver extends BroadcastReceiver {
|
||||||
notificationSpec.body = c.getString(c.getColumnIndex("preview"));
|
notificationSpec.body = c.getString(c.getColumnIndex("preview"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (c.moveToNext());
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
|
|
Loading…
Reference in New Issue