Set sampleProvider to avoid NPEs

This commit is contained in:
cpfeiffer 2016-07-01 00:22:54 +02:00
parent 9eb768ace0
commit 8b24e098ea
5 changed files with 9 additions and 3 deletions

View File

@ -335,7 +335,7 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
userId, userId,
deviceId, deviceId,
heartrate & 0xff); heartrate & 0xff);
// samples[minutes].setProvider(dbHandler); samples[minutes].setProvider(provider);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("sample: " + samples[minutes]); LOG.debug("sample: " + samples[minutes]);

View File

@ -67,6 +67,7 @@ public class AppMessageHandlerGBPebble extends AppMessageHandler {
int intensity = ((sample & 0x1f80) >>> 7); int intensity = ((sample & 0x1f80) >>> 7);
int steps = (sample & 0x007f); int steps = (sample & 0x007f);
activitySamples[i++] = createSample(timestamp + offset_seconds, intensity, steps, type, user, device); activitySamples[i++] = createSample(timestamp + offset_seconds, intensity, steps, type, user, device);
activitySamples[i].setProvider(sampleProvider);
offset_seconds += 60; offset_seconds += 60;
} }
sampleProvider.addGBActivitySamples(activitySamples); sampleProvider.addGBActivitySamples(activitySamples);

View File

@ -82,6 +82,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
int totalSteps = 0; int totalSteps = 0;
PebbleActivitySample[] activitySamples = new PebbleActivitySample[samples]; PebbleActivitySample[] activitySamples = new PebbleActivitySample[samples];
try (DBHandler db = GBApplication.acquireDB()) { try (DBHandler db = GBApplication.acquireDB()) {
MisfitSampleProvider sampleProvider = new MisfitSampleProvider(device, db.getDaoSession());
Long userId = DBHelper.getUser(db.getDaoSession()).getId(); Long userId = DBHelper.getUser(db.getDaoSession()).getId();
Long deviceId = DBHelper.getDevice(getDevice(), db.getDaoSession()).getId(); Long deviceId = DBHelper.getDevice(getDevice(), db.getDaoSession()).getId();
for (int i = 0; i < samples; i++) { for (int i = 0; i < samples; i++) {
@ -115,10 +116,10 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
LOG.info("got steps for sample " + i + " : " + steps + "(" + Integer.toHexString(sample & 0xffff) + ")"); LOG.info("got steps for sample " + i + " : " + steps + "(" + Integer.toHexString(sample & 0xffff) + ")");
activitySamples[i] = new PebbleActivitySample(null, timestamp + i * 60, intensity, steps, activityKind, userId, deviceId); activitySamples[i] = new PebbleActivitySample(null, timestamp + i * 60, intensity, steps, activityKind, userId, deviceId);
activitySamples[i].setProvider(sampleProvider);
} }
LOG.info("total steps for above period: " + totalSteps); LOG.info("total steps for above period: " + totalSteps);
MisfitSampleProvider sampleProvider = new MisfitSampleProvider(device, db.getDaoSession());
sampleProvider.addGBActivitySamples(activitySamples); sampleProvider.addGBActivitySamples(activitySamples);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error acquiring database", e); LOG.error("Error acquiring database", e);

View File

@ -19,6 +19,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSleepMonit
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.MorpheuzSampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.pebble.MorpheuzSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.User; import nodomain.freeyourgadget.gadgetbridge.entities.User;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
@ -103,7 +104,9 @@ public class AppMessageHandlerMorpheuz extends AppMessageHandler {
User user = DBHelper.getUser(db.getDaoSession()); User user = DBHelper.getUser(db.getDaoSession());
Device device = DBHelper.getDevice(getDevice(), db.getDaoSession()); Device device = DBHelper.getDevice(getDevice(), db.getDaoSession());
MorpheuzSampleProvider sampleProvider = new MorpheuzSampleProvider(getDevice(), db.getDaoSession()); MorpheuzSampleProvider sampleProvider = new MorpheuzSampleProvider(getDevice(), db.getDaoSession());
sampleProvider.addGBActivitySample(createSample(recording_base_timestamp + index * 600, intensity, 0, type, user, device)); PebbleActivitySample sample = createSample(recording_base_timestamp + index * 600, intensity, 0, type, user, device);
sample.setProvider(sampleProvider);
sampleProvider.addGBActivitySample(sample);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error acquiring database", e); LOG.error("Error acquiring database", e);
} }

View File

@ -89,6 +89,7 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
stepsRecord.steps, stepsRecord.steps,
sampleProvider.toRawActivityKind(ActivityKind.TYPE_ACTIVITY), sampleProvider.toRawActivityKind(ActivityKind.TYPE_ACTIVITY),
userId, deviceId); userId, deviceId);
samples[j].setProvider(sampleProvider);
} }
sampleProvider.addGBActivitySamples(samples); sampleProvider.addGBActivitySamples(samples);