1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-22 00:27:48 +01:00

Don't retrieve the column index again and again in a long loop

Also: fix weird iteration logic
This commit is contained in:
cpfeiffer 2016-03-08 21:26:55 +01:00
parent 2da50e27c2
commit 87023ebdb3
2 changed files with 16 additions and 14 deletions

View File

@ -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);
GBActivitySample sample = new GBActivitySample( int colSteps = cursor.getColumnIndex(KEY_STEPS);
provider, int colType = cursor.getColumnIndex(KEY_TYPE);
cursor.getInt(cursor.getColumnIndex(KEY_TIMESTAMP)), int colCustomShort = cursor.getColumnIndex(KEY_CUSTOM_SHORT);
cursor.getInt(cursor.getColumnIndex(KEY_INTENSITY)), while (cursor.moveToFirst()) {
cursor.getInt(cursor.getColumnIndex(KEY_STEPS)), GBActivitySample sample = new GBActivitySample(
cursor.getInt(cursor.getColumnIndex(KEY_TYPE)), provider,
cursor.getInt(cursor.getColumnIndex(KEY_CUSTOM_SHORT))); cursor.getInt(colTimeStamp),
samples.add(sample); cursor.getInt(colIntensity),
} while (cursor.moveToNext()); cursor.getInt(colSteps),
cursor.getInt(colType),
cursor.getInt(colCustomShort));
samples.add(sample);
} }
} }
} }

View File

@ -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) {