Search in sources :

Example 1 with PebbleHealthActivityOverlayDao

use of nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao in project Gadgetbridge by Freeyourgadget.

the class DatalogSessionHealthOverlayData method store.

private void store(OverlayRecord[] overlayRecords) {
    try (DBHandler dbHandler = GBApplication.acquireDB()) {
        DaoSession session = dbHandler.getDaoSession();
        Long userId = DBHelper.getUser(session).getId();
        Long deviceId = DBHelper.getDevice(getDevice(), session).getId();
        PebbleHealthActivityOverlayDao overlayDao = session.getPebbleHealthActivityOverlayDao();
        List<PebbleHealthActivityOverlay> overlayList = new ArrayList<>();
        for (OverlayRecord overlayRecord : overlayRecords) {
            overlayList.add(new PebbleHealthActivityOverlay(overlayRecord.timestampStart, overlayRecord.timestampStart + overlayRecord.durationSeconds, overlayRecord.type, deviceId, userId, overlayRecord.getRawData()));
        }
        overlayDao.insertOrReplaceInTx(overlayList);
    } catch (Exception ex) {
        LOG.debug(ex.getMessage());
    }
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) ArrayList(java.util.ArrayList) PebbleHealthActivityOverlayDao(nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao) PebbleHealthActivityOverlay(nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)

Example 2 with PebbleHealthActivityOverlayDao

use of nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao in project Gadgetbridge by Freeyourgadget.

the class DatalogSessionHealthSleep method store.

private void store(SleepRecord[] sleepRecords) {
    try (DBHandler dbHandler = GBApplication.acquireDB()) {
        DaoSession session = dbHandler.getDaoSession();
        Long userId = DBHelper.getUser(session).getId();
        Long deviceId = DBHelper.getDevice(getDevice(), session).getId();
        PebbleHealthActivityOverlayDao overlayDao = session.getPebbleHealthActivityOverlayDao();
        List<PebbleHealthActivityOverlay> overlayList = new ArrayList<>();
        for (SleepRecord sleepRecord : sleepRecords) {
            //TODO: check the firmware version and don't use the sleep record if overlay is available?
            overlayList.add(new PebbleHealthActivityOverlay(sleepRecord.bedTimeStart, sleepRecord.bedTimeEnd, sleepRecord.type, deviceId, userId, sleepRecord.getRawData()));
        }
        overlayDao.insertOrReplaceInTx(overlayList);
    } catch (Exception ex) {
        LOG.debug(ex.getMessage());
    }
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) ArrayList(java.util.ArrayList) PebbleHealthActivityOverlayDao(nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao) PebbleHealthActivityOverlay(nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)

Aggregations

ArrayList (java.util.ArrayList)2 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)2 DaoSession (nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)2 PebbleHealthActivityOverlay (nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay)2 PebbleHealthActivityOverlayDao (nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao)2