Search in sources :

Example 1 with FitProSampleProvider

use of nodomain.freeyourgadget.gadgetbridge.devices.fitpro.FitProSampleProvider in project Gadgetbridge by Freeyourgadget.

the class FitProDeviceSupport method getStepsOnDay.

private int getStepsOnDay(Calendar dayStart, Calendar dayEnd) {
    // this is for day data values, not used in Gb, handleStepData uses 5min data which is better
    try (DBHandler dbHandler = GBApplication.acquireDB()) {
        FitProSampleProvider provider = new FitProSampleProvider(this.getDevice(), dbHandler.getDaoSession());
        List<FitProActivitySample> samples = provider.getActivitySamples((int) (dayStart.getTimeInMillis() / 1000L), (int) (dayEnd.getTimeInMillis() / 1000L));
        int totalSteps = 0;
        for (FitProActivitySample sample : samples) {
            totalSteps += sample.getSteps();
        }
        return totalSteps;
    } catch (Exception ex) {
        LOG.error(ex.getMessage());
        return 0;
    }
}
Also used : FitProActivitySample(nodomain.freeyourgadget.gadgetbridge.entities.FitProActivitySample) DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) FitProSampleProvider(nodomain.freeyourgadget.gadgetbridge.devices.fitpro.FitProSampleProvider) IOException(java.io.IOException) ParseException(java.text.ParseException) GBException(nodomain.freeyourgadget.gadgetbridge.GBException)

Example 2 with FitProSampleProvider

use of nodomain.freeyourgadget.gadgetbridge.devices.fitpro.FitProSampleProvider in project Gadgetbridge by Freeyourgadget.

the class FitProDeviceSupport method addGBActivitySamples.

private boolean addGBActivitySamples(List<FitProActivitySample> samples) {
    try (DBHandler dbHandler = GBApplication.acquireDB()) {
        User user = DBHelper.getUser(dbHandler.getDaoSession());
        Device device = DBHelper.getDevice(this.getDevice(), dbHandler.getDaoSession());
        FitProSampleProvider provider = new FitProSampleProvider(this.getDevice(), dbHandler.getDaoSession());
        for (FitProActivitySample sample : samples) {
            sample.setDevice(device);
            sample.setUser(user);
            sample.setProvider(provider);
            provider.addGBActivitySample(sample);
        }
    } catch (Exception ex) {
        LOG.error("Error saving samples: " + ex);
        GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
        return false;
    }
    return true;
}
Also used : FitProActivitySample(nodomain.freeyourgadget.gadgetbridge.entities.FitProActivitySample) DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) User(nodomain.freeyourgadget.gadgetbridge.entities.User) ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser) FitProSampleProvider(nodomain.freeyourgadget.gadgetbridge.devices.fitpro.FitProSampleProvider) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) IOException(java.io.IOException) ParseException(java.text.ParseException) GBException(nodomain.freeyourgadget.gadgetbridge.GBException)

Aggregations

IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 GBException (nodomain.freeyourgadget.gadgetbridge.GBException)2 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)2 FitProSampleProvider (nodomain.freeyourgadget.gadgetbridge.devices.fitpro.FitProSampleProvider)2 FitProActivitySample (nodomain.freeyourgadget.gadgetbridge.entities.FitProActivitySample)2 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)1 ActivityUser (nodomain.freeyourgadget.gadgetbridge.model.ActivityUser)1