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

Keep the db open while adding samples

This commit is contained in:
cpfeiffer 2015-06-09 21:05:44 +02:00
parent e78e79a9a9
commit d0b9914770

View File

@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge.miband;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.preference.PreferenceManager;
@ -24,6 +25,7 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.btle.AbstractBTLEDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.btle.SetDeviceBusyAction;
import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.database.ActivityDatabaseHandler;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_FLASH_COLOUR;
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_FLASH_COUNT;
@ -519,25 +521,28 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
GregorianCalendar timestamp = this.activityDataTimestampProgress;
byte category, intensity, steps;
for (int i=0; i<this.activityDataHolderProgress; i+=3) { //TODO: check if multiple of 3, if not something is wrong
category = this.activityDataHolder[i];
intensity = this.activityDataHolder[i+1];
steps = this.activityDataHolder[i+2];
ActivityDatabaseHandler dbHandler = GBApplication.getActivityDatabaseHandler();
try (SQLiteDatabase db = dbHandler.getWritableDatabase()) { // explicitly keep the db open while looping over the samples
for (int i=0; i<this.activityDataHolderProgress; i+=3) { //TODO: check if multiple of 3, if not something is wrong
category = this.activityDataHolder[i];
intensity = this.activityDataHolder[i+1];
steps = this.activityDataHolder[i+2];
GBApplication.getActivityDatabaseHandler().addGBActivitySample(
(int) (timestamp.getTimeInMillis() / 1000),
GBActivitySample.PROVIDER_MIBAND,
intensity,
steps,
category);
dbHandler.addGBActivitySample(
(int) (timestamp.getTimeInMillis() / 1000),
GBActivitySample.PROVIDER_MIBAND,
intensity,
steps,
category);
ACTIVITYLOG.info(
" timestamp:"+DateFormat.getDateTimeInstance().format(timestamp.getTime()).toString() +
" category:"+ category+
" intensity:"+intensity+
" steps:"+steps
);
timestamp.add(Calendar.MINUTE, 1);
ACTIVITYLOG.info(
" timestamp:"+DateFormat.getDateTimeInstance().format(timestamp.getTime()).toString() +
" category:"+ category+
" intensity:"+intensity+
" steps:"+steps
);
timestamp.add(Calendar.MINUTE, 1);
}
}
this.activityDataHolderProgress = 0;