1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-21 08:07:46 +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 (Cursor cursor = db.query(TABLE_GBACTIVITYSAMPLES, null, where, null, null, null, order)) {
LOG.info("Activity query result: " + cursor.getCount() + " samples");
if (cursor.moveToFirst()) {
do {
GBActivitySample sample = new GBActivitySample(
provider,
cursor.getInt(cursor.getColumnIndex(KEY_TIMESTAMP)),
cursor.getInt(cursor.getColumnIndex(KEY_INTENSITY)),
cursor.getInt(cursor.getColumnIndex(KEY_STEPS)),
cursor.getInt(cursor.getColumnIndex(KEY_TYPE)),
cursor.getInt(cursor.getColumnIndex(KEY_CUSTOM_SHORT)));
samples.add(sample);
} while (cursor.moveToNext());
int colTimeStamp = cursor.getColumnIndex(KEY_TIMESTAMP);
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(
provider,
cursor.getInt(colTimeStamp),
cursor.getInt(colIntensity),
cursor.getInt(colSteps),
cursor.getInt(colType),
cursor.getInt(colCustomShort));
samples.add(sample);
}
}
}

View File

@ -67,8 +67,7 @@ public class K9Receiver extends BroadcastReceiver {
try {
if (c != null) {
c.moveToFirst();
do {
while (c.moveToFirst()) {
String uri = c.getString(c.getColumnIndex("uri"));
if (uri.equals(uriWanted)) {
notificationSpec.sender = c.getString(c.getColumnIndex("senderAddress"));
@ -76,7 +75,7 @@ public class K9Receiver extends BroadcastReceiver {
notificationSpec.body = c.getString(c.getColumnIndex("preview"));
break;
}
} while (c.moveToNext());
}
}
} finally {
if (c != null) {