mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 12:56:49 +01:00
More WIP
This commit is contained in:
parent
9532fc879f
commit
d0c8483d92
@ -5,6 +5,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.dao.AbstractDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster;
|
||||
@ -56,8 +57,10 @@ public class DaoHandler implements DBHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGBActivitySamples(ActivitySample[] activitySamples) {
|
||||
|
||||
public void addGBActivitySamples(ActivitySample[] activitySamples, AbstractDao<ActivitySample,?> dao) {
|
||||
for (ActivitySample sample : activitySamples) {
|
||||
dao.insert(sample);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,7 +18,7 @@ public abstract class AbstractSampleProvider<T extends ActivitySample> implement
|
||||
mSession = session;
|
||||
}
|
||||
|
||||
public DaoSession getmSession() {
|
||||
public DaoSession getSession() {
|
||||
return mSession;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
|
||||
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.
|
||||
private final float movementDivisor = 180.0f; //256.0f;
|
||||
|
||||
protected MiBandSampleProvider(DaoSession session) {
|
||||
public MiBandSampleProvider(DaoSession session) {
|
||||
super(session);
|
||||
}
|
||||
|
||||
@ -79,6 +78,6 @@ public class MiBandSampleProvider extends AbstractSampleProvider<MiBandActivityS
|
||||
|
||||
@Override
|
||||
protected AbstractDao<MiBandActivitySample, ?> getSampleDao() {
|
||||
return getmSession().getMiBandActivitySampleDao();
|
||||
return getSession().getMiBandActivitySampleDao();
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class HealthSampleProvider extends AbstractSampleProvider<PebbleActivityS
|
||||
|
||||
protected final float movementDivisor = 8000f;
|
||||
|
||||
protected HealthSampleProvider(DaoSession session) {
|
||||
public HealthSampleProvider(DaoSession session) {
|
||||
super(session);
|
||||
}
|
||||
|
||||
@ -60,6 +60,6 @@ public class HealthSampleProvider extends AbstractSampleProvider<PebbleActivityS
|
||||
|
||||
@Override
|
||||
protected AbstractDao<PebbleActivitySample, ?> getSampleDao() {
|
||||
return getmSession().getPebbleActivitySampleDao();
|
||||
return getSession().getPebbleActivitySampleDao();
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public class MisfitSampleProvider extends AbstractSampleProvider<PebbleActivityS
|
||||
|
||||
protected final float movementDivisor = 300f;
|
||||
|
||||
protected MisfitSampleProvider(DaoSession session) {
|
||||
public MisfitSampleProvider(DaoSession session) {
|
||||
super(session);
|
||||
}
|
||||
|
||||
@ -38,6 +38,6 @@ public class MisfitSampleProvider extends AbstractSampleProvider<PebbleActivityS
|
||||
|
||||
@Override
|
||||
protected AbstractDao<PebbleActivitySample, ?> getSampleDao() {
|
||||
return getmSession().getPebbleActivitySampleDao();
|
||||
return getSession().getPebbleActivitySampleDao();
|
||||
}
|
||||
}
|
||||
|
@ -62,6 +62,6 @@ public class MorpheuzSampleProvider extends AbstractSampleProvider<PebbleActivit
|
||||
|
||||
@Override
|
||||
protected AbstractDao<PebbleActivitySample, ?> getSampleDao() {
|
||||
return getmSession().getPebbleActivitySampleDao();
|
||||
return getSession().getPebbleActivitySampleDao();
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,10 @@ import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandDateConverter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandSampleProvider;
|
||||
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.model.ActivitySample;
|
||||
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);
|
||||
}
|
||||
int numSamples = activityStruct.activityDataHolderProgress / bpm;
|
||||
ActivitySample[] samples = new ActivitySample[numSamples];
|
||||
SampleProvider sampleProvider = new MiBandSampleProvider();
|
||||
AbstractActivitySample[] samples = new AbstractActivitySample[numSamples];
|
||||
DaoSession daoSession = GBApplication.getDaoSession();
|
||||
SampleProvider sampleProvider = new MiBandSampleProvider(daoSession);
|
||||
MiBandActivitySampleDao dao = daoSession.getMiBandActivitySampleDao();
|
||||
|
||||
for (int i = 0; i < activityStruct.activityDataHolderProgress; i += bpm) {
|
||||
category = activityStruct.activityDataHolder[i];
|
||||
@ -328,19 +334,25 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
|
||||
LOG.debug("heartrate received: " + (heartrate & 0xff));
|
||||
}
|
||||
|
||||
samples[minutes] = new GBActivitySample(
|
||||
sampleProvider,
|
||||
Long userId = null;
|
||||
Long deviceId = null;
|
||||
|
||||
samples[minutes] = new MiBandActivitySample(
|
||||
null,
|
||||
timestampInSeconds,
|
||||
intensity & 0xff,
|
||||
steps & 0xff,
|
||||
category & 0xff,
|
||||
userId,
|
||||
deviceId,
|
||||
heartrate & 0xff);
|
||||
samples[minutes].setProvider(sampleProvider);
|
||||
|
||||
// next minute
|
||||
minutes++;
|
||||
timestampInSeconds += 60;
|
||||
}
|
||||
dbHandler.addGBActivitySamples(samples);
|
||||
dbHandler.addGBActivitySamples(samples, dao);
|
||||
} finally {
|
||||
activityStruct.bufferFlushed(minutes);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
|
||||
super(uuid, pebbleProtocol);
|
||||
}
|
||||
|
||||
private final MisfitSampleProvider sampleProvider = new MisfitSampleProvider();
|
||||
private final MisfitSampleProvider sampleProvider = new MisfitSampleProvider(GBApplication.getDaoSession());
|
||||
|
||||
@Override
|
||||
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
|
||||
|
@ -67,7 +67,7 @@ class DatalogSessionHealthSleep extends DatalogSession {
|
||||
|
||||
private boolean store84(SleepRecord84[] sleepRecords) {
|
||||
DBHandler dbHandler = null;
|
||||
SampleProvider sampleProvider = new HealthSampleProvider();
|
||||
SampleProvider sampleProvider = new HealthSampleProvider(GBApplication.getDaoSession());
|
||||
try {
|
||||
dbHandler = GBApplication.acquireDB();
|
||||
int latestTimestamp = dbHandler.fetchLatestTimestamp(sampleProvider);
|
||||
@ -120,7 +120,7 @@ class DatalogSessionHealthSleep extends DatalogSession {
|
||||
|
||||
private boolean store83(SleepRecord83[] sleepRecords) {
|
||||
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);
|
||||
try {
|
||||
dbHandler = GBApplication.acquireDB();
|
||||
|
@ -71,7 +71,7 @@ public class DatalogSessionHealthSteps extends DatalogSession {
|
||||
private void store(StepsRecord[] stepsRecords) {
|
||||
|
||||
DBHandler dbHandler = null;
|
||||
SampleProvider sampleProvider = new HealthSampleProvider();
|
||||
SampleProvider sampleProvider = new HealthSampleProvider(GBApplication.getDaoSession());
|
||||
|
||||
ActivitySample[] samples = new ActivitySample[stepsRecords.length];
|
||||
for (int j = 0; j < stepsRecords.length; j++) {
|
||||
|
Loading…
Reference in New Issue
Block a user