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;
}
}
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());
}
}
Aggregations