Search in sources :

Example 1 with PineTimeActivitySampleProvider

use of nodomain.freeyourgadget.gadgetbridge.devices.pinetime.PineTimeActivitySampleProvider in project Gadgetbridge by Freeyourgadget.

the class PineTimeJFSupport method getStepsOnDay.

/**
 * @param timeStamp Time stamp (in seconds)  at some point during the requested day.
 */
private int getStepsOnDay(int timeStamp) {
    try (DBHandler dbHandler = GBApplication.acquireDB()) {
        Calendar dayStart = new GregorianCalendar();
        Calendar dayEnd = new GregorianCalendar();
        this.getDayStartEnd(timeStamp, dayStart, dayEnd);
        PineTimeActivitySampleProvider provider = new PineTimeActivitySampleProvider(this.getDevice(), dbHandler.getDaoSession());
        List<PineTimeActivitySample> samples = provider.getAllActivitySamples((int) (dayStart.getTimeInMillis() / 1000L), (int) (dayEnd.getTimeInMillis() / 1000L));
        int totalSteps = 0;
        for (PineTimeActivitySample sample : samples) {
            totalSteps += sample.getSteps();
        }
        return totalSteps;
    } catch (Exception ex) {
        LOG.error(ex.getMessage());
        return 0;
    }
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) PineTimeActivitySampleProvider(nodomain.freeyourgadget.gadgetbridge.devices.pinetime.PineTimeActivitySampleProvider) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) PineTimeActivitySample(nodomain.freeyourgadget.gadgetbridge.entities.PineTimeActivitySample)

Example 2 with PineTimeActivitySampleProvider

use of nodomain.freeyourgadget.gadgetbridge.devices.pinetime.PineTimeActivitySampleProvider in project Gadgetbridge by Freeyourgadget.

the class PineTimeJFSupport method addGBActivitySamples.

private void addGBActivitySamples(PineTimeActivitySample[] samples) {
    try (DBHandler dbHandler = GBApplication.acquireDB()) {
        User user = DBHelper.getUser(dbHandler.getDaoSession());
        Device device = DBHelper.getDevice(this.getDevice(), dbHandler.getDaoSession());
        PineTimeActivitySampleProvider provider = new PineTimeActivitySampleProvider(this.getDevice(), dbHandler.getDaoSession());
        for (PineTimeActivitySample sample : samples) {
            sample.setDevice(device);
            sample.setUser(user);
            sample.setProvider(provider);
            sample.setRawIntensity(ActivitySample.NOT_MEASURED);
            provider.addGBActivitySample(sample);
        }
    } catch (Exception ex) {
        GB.toast(getContext(), "Error saving samples: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
        GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
        LOG.error(ex.getMessage());
    }
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) PineTimeActivitySampleProvider(nodomain.freeyourgadget.gadgetbridge.devices.pinetime.PineTimeActivitySampleProvider) User(nodomain.freeyourgadget.gadgetbridge.entities.User) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) PineTimeActivitySample(nodomain.freeyourgadget.gadgetbridge.entities.PineTimeActivitySample)

Aggregations

DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)2 PineTimeActivitySampleProvider (nodomain.freeyourgadget.gadgetbridge.devices.pinetime.PineTimeActivitySampleProvider)2 PineTimeActivitySample (nodomain.freeyourgadget.gadgetbridge.entities.PineTimeActivitySample)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)1