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

Fix the logic regarding the last sample of a run. Remove the unneded try-catch block and reuse the current DB session instead.

This commit is contained in:
Daniele Gobbetti 2016-08-21 17:38:07 +02:00
parent 5a3a0495c9
commit b617ba7264

View File

@ -454,13 +454,15 @@ public class DBHelper {
}
if (currentTypeRun != previousTypeRun) {
//we used not to store the last sample, now we do the opposite and we need to round up
currentTypeEndTimeStamp = currentTimeStamp;
//if the Type has changed, the run has ended. Only store light and deep sleep data
if (previousTypeRun == 4) {
overlayList.add(new PebbleHealthActivityOverlay(currentTypeStartTimeStamp, currentTypeEndTimeStamp, sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP), deviceId, userId, null));
} else if (previousTypeRun == 5) {
overlayList.add(new PebbleHealthActivityOverlay(currentTypeStartTimeStamp, currentTypeEndTimeStamp, sampleProvider.toRawActivityKind(ActivityKind.TYPE_DEEP_SLEEP), deviceId, userId, null));
}
currentTypeStartTimeStamp = currentTypeEndTimeStamp = currentTimeStamp;
currentTypeStartTimeStamp = currentTimeStamp;
previousTypeRun = currentTypeRun;
} else {
//just expand the run
@ -488,14 +490,8 @@ public class DBHelper {
}
// store the overlay records
if (!overlayList.isEmpty()) {
try (DBHandler dbHandler = GBApplication.acquireDB()) {
DaoSession session = dbHandler.getDaoSession();
PebbleHealthActivityOverlayDao overlayDao = session.getPebbleHealthActivityOverlayDao();
PebbleHealthActivityOverlayDao overlayDao = targetSession.getPebbleHealthActivityOverlayDao();
overlayDao.insertOrReplaceInTx(overlayList);
} catch (Exception ex) {
//FIXME: this whole try catch is probably in the wrong place.
}
}
}
}