1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 12:56:49 +01:00
This commit is contained in:
cpfeiffer 2016-05-08 23:41:34 +02:00
parent 9532fc879f
commit d0c8483d92
10 changed files with 34 additions and 20 deletions

View File

@ -5,6 +5,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import java.util.List; import java.util.List;
import de.greenrobot.dao.AbstractDao;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster; import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster;
@ -56,8 +57,10 @@ public class DaoHandler implements DBHandler {
} }
@Override @Override
public void addGBActivitySamples(ActivitySample[] activitySamples) { public void addGBActivitySamples(ActivitySample[] activitySamples, AbstractDao<ActivitySample,?> dao) {
for (ActivitySample sample : activitySamples) {
dao.insert(sample);
}
} }
@Override @Override

View File

@ -18,7 +18,7 @@ public abstract class AbstractSampleProvider<T extends ActivitySample> implement
mSession = session; mSession = session;
} }
public DaoSession getmSession() { public DaoSession getSession() {
return mSession; return mSession;
} }

View File

@ -5,7 +5,6 @@ import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample; import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySampleDao;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
public class MiBandSampleProvider extends AbstractSampleProvider<MiBandActivitySample> { public class MiBandSampleProvider extends AbstractSampleProvider<MiBandActivitySample> {
@ -27,7 +26,7 @@ public class MiBandSampleProvider extends AbstractSampleProvider<MiBandActivityS
// maybe this should be configurable 256 seems way off, though. // maybe this should be configurable 256 seems way off, though.
private final float movementDivisor = 180.0f; //256.0f; private final float movementDivisor = 180.0f; //256.0f;
protected MiBandSampleProvider(DaoSession session) { public MiBandSampleProvider(DaoSession session) {
super(session); super(session);
} }
@ -79,6 +78,6 @@ public class MiBandSampleProvider extends AbstractSampleProvider<MiBandActivityS
@Override @Override
protected AbstractDao<MiBandActivitySample, ?> getSampleDao() { protected AbstractDao<MiBandActivitySample, ?> getSampleDao() {
return getmSession().getMiBandActivitySampleDao(); return getSession().getMiBandActivitySampleDao();
} }
} }

View File

@ -14,7 +14,7 @@ public class HealthSampleProvider extends AbstractSampleProvider<PebbleActivityS
protected final float movementDivisor = 8000f; protected final float movementDivisor = 8000f;
protected HealthSampleProvider(DaoSession session) { public HealthSampleProvider(DaoSession session) {
super(session); super(session);
} }
@ -60,6 +60,6 @@ public class HealthSampleProvider extends AbstractSampleProvider<PebbleActivityS
@Override @Override
protected AbstractDao<PebbleActivitySample, ?> getSampleDao() { protected AbstractDao<PebbleActivitySample, ?> getSampleDao() {
return getmSession().getPebbleActivitySampleDao(); return getSession().getPebbleActivitySampleDao();
} }
} }

View File

@ -10,7 +10,7 @@ public class MisfitSampleProvider extends AbstractSampleProvider<PebbleActivityS
protected final float movementDivisor = 300f; protected final float movementDivisor = 300f;
protected MisfitSampleProvider(DaoSession session) { public MisfitSampleProvider(DaoSession session) {
super(session); super(session);
} }
@ -38,6 +38,6 @@ public class MisfitSampleProvider extends AbstractSampleProvider<PebbleActivityS
@Override @Override
protected AbstractDao<PebbleActivitySample, ?> getSampleDao() { protected AbstractDao<PebbleActivitySample, ?> getSampleDao() {
return getmSession().getPebbleActivitySampleDao(); return getSession().getPebbleActivitySampleDao();
} }
} }

View File

@ -62,6 +62,6 @@ public class MorpheuzSampleProvider extends AbstractSampleProvider<PebbleActivit
@Override @Override
protected AbstractDao<PebbleActivitySample, ?> getSampleDao() { protected AbstractDao<PebbleActivitySample, ?> getSampleDao() {
return getmSession().getPebbleActivitySampleDao(); return getSession().getPebbleActivitySampleDao();
} }
} }

View File

@ -23,6 +23,10 @@ import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandDateConverter; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandDateConverter;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandSampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService;
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySampleDao;
import nodomain.freeyourgadget.gadgetbridge.impl.GBActivitySample; import nodomain.freeyourgadget.gadgetbridge.impl.GBActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
@ -316,8 +320,10 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
throw new IllegalStateException("Unexpected data, progress should be mutiple of " + bpm + ": " + activityStruct.activityDataHolderProgress); throw new IllegalStateException("Unexpected data, progress should be mutiple of " + bpm + ": " + activityStruct.activityDataHolderProgress);
} }
int numSamples = activityStruct.activityDataHolderProgress / bpm; int numSamples = activityStruct.activityDataHolderProgress / bpm;
ActivitySample[] samples = new ActivitySample[numSamples]; AbstractActivitySample[] samples = new AbstractActivitySample[numSamples];
SampleProvider sampleProvider = new MiBandSampleProvider(); DaoSession daoSession = GBApplication.getDaoSession();
SampleProvider sampleProvider = new MiBandSampleProvider(daoSession);
MiBandActivitySampleDao dao = daoSession.getMiBandActivitySampleDao();
for (int i = 0; i < activityStruct.activityDataHolderProgress; i += bpm) { for (int i = 0; i < activityStruct.activityDataHolderProgress; i += bpm) {
category = activityStruct.activityDataHolder[i]; category = activityStruct.activityDataHolder[i];
@ -328,19 +334,25 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
LOG.debug("heartrate received: " + (heartrate & 0xff)); LOG.debug("heartrate received: " + (heartrate & 0xff));
} }
samples[minutes] = new GBActivitySample( Long userId = null;
sampleProvider, Long deviceId = null;
samples[minutes] = new MiBandActivitySample(
null,
timestampInSeconds, timestampInSeconds,
intensity & 0xff, intensity & 0xff,
steps & 0xff, steps & 0xff,
category & 0xff, category & 0xff,
userId,
deviceId,
heartrate & 0xff); heartrate & 0xff);
samples[minutes].setProvider(sampleProvider);
// next minute // next minute
minutes++; minutes++;
timestampInSeconds += 60; timestampInSeconds += 60;
} }
dbHandler.addGBActivitySamples(samples); dbHandler.addGBActivitySamples(samples, dao);
} finally { } finally {
activityStruct.bufferFlushed(minutes); activityStruct.bufferFlushed(minutes);
} }

View File

@ -39,7 +39,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
super(uuid, pebbleProtocol); super(uuid, pebbleProtocol);
} }
private final MisfitSampleProvider sampleProvider = new MisfitSampleProvider(); private final MisfitSampleProvider sampleProvider = new MisfitSampleProvider(GBApplication.getDaoSession());
@Override @Override
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) { public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {

View File

@ -67,7 +67,7 @@ class DatalogSessionHealthSleep extends DatalogSession {
private boolean store84(SleepRecord84[] sleepRecords) { private boolean store84(SleepRecord84[] sleepRecords) {
DBHandler dbHandler = null; DBHandler dbHandler = null;
SampleProvider sampleProvider = new HealthSampleProvider(); SampleProvider sampleProvider = new HealthSampleProvider(GBApplication.getDaoSession());
try { try {
dbHandler = GBApplication.acquireDB(); dbHandler = GBApplication.acquireDB();
int latestTimestamp = dbHandler.fetchLatestTimestamp(sampleProvider); int latestTimestamp = dbHandler.fetchLatestTimestamp(sampleProvider);
@ -120,7 +120,7 @@ class DatalogSessionHealthSleep extends DatalogSession {
private boolean store83(SleepRecord83[] sleepRecords) { private boolean store83(SleepRecord83[] sleepRecords) {
DBHandler dbHandler = null; DBHandler dbHandler = null;
SampleProvider sampleProvider = new HealthSampleProvider(); SampleProvider sampleProvider = new HealthSampleProvider(GBApplication.getDaoSession());
GB.toast("Deep sleep is supported only from firmware 3.11 onwards.", Toast.LENGTH_LONG, GB.INFO); GB.toast("Deep sleep is supported only from firmware 3.11 onwards.", Toast.LENGTH_LONG, GB.INFO);
try { try {
dbHandler = GBApplication.acquireDB(); dbHandler = GBApplication.acquireDB();

View File

@ -71,7 +71,7 @@ public class DatalogSessionHealthSteps extends DatalogSession {
private void store(StepsRecord[] stepsRecords) { private void store(StepsRecord[] stepsRecords) {
DBHandler dbHandler = null; DBHandler dbHandler = null;
SampleProvider sampleProvider = new HealthSampleProvider(); SampleProvider sampleProvider = new HealthSampleProvider(GBApplication.getDaoSession());
ActivitySample[] samples = new ActivitySample[stepsRecords.length]; ActivitySample[] samples = new ActivitySample[stepsRecords.length];
for (int j = 0; j < stepsRecords.length; j++) { for (int j = 0; j < stepsRecords.length; j++) {