mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-13 04:07:50 +01:00
Keep the db open while adding samples
This commit is contained in:
parent
e78e79a9a9
commit
d0b9914770
@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge.miband;
|
|||||||
import android.bluetooth.BluetoothGatt;
|
import android.bluetooth.BluetoothGatt;
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.btle.AbstractBTLEDeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.btle.AbstractBTLEDeviceSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.btle.SetDeviceBusyAction;
|
import nodomain.freeyourgadget.gadgetbridge.btle.SetDeviceBusyAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.btle.TransactionBuilder;
|
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_COLOUR;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_FLASH_COUNT;
|
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.DEFAULT_VALUE_FLASH_COUNT;
|
||||||
@ -519,12 +521,14 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
GregorianCalendar timestamp = this.activityDataTimestampProgress;
|
GregorianCalendar timestamp = this.activityDataTimestampProgress;
|
||||||
byte category, intensity, steps;
|
byte category, intensity, steps;
|
||||||
|
|
||||||
|
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
|
for (int i=0; i<this.activityDataHolderProgress; i+=3) { //TODO: check if multiple of 3, if not something is wrong
|
||||||
category = this.activityDataHolder[i];
|
category = this.activityDataHolder[i];
|
||||||
intensity = this.activityDataHolder[i+1];
|
intensity = this.activityDataHolder[i+1];
|
||||||
steps = this.activityDataHolder[i+2];
|
steps = this.activityDataHolder[i+2];
|
||||||
|
|
||||||
GBApplication.getActivityDatabaseHandler().addGBActivitySample(
|
dbHandler.addGBActivitySample(
|
||||||
(int) (timestamp.getTimeInMillis() / 1000),
|
(int) (timestamp.getTimeInMillis() / 1000),
|
||||||
GBActivitySample.PROVIDER_MIBAND,
|
GBActivitySample.PROVIDER_MIBAND,
|
||||||
intensity,
|
intensity,
|
||||||
@ -539,6 +543,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
);
|
);
|
||||||
timestamp.add(Calendar.MINUTE, 1);
|
timestamp.add(Calendar.MINUTE, 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.activityDataHolderProgress = 0;
|
this.activityDataHolderProgress = 0;
|
||||||
this.activityDataTimestampProgress = timestamp;
|
this.activityDataTimestampProgress = timestamp;
|
||||||
|
Loading…
Reference in New Issue
Block a user