mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 10:35:50 +01:00
sampleproviders now return device specific data #206
This commit is contained in:
parent
358cd6df5e
commit
e70a2290c3
@ -296,7 +296,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
|
|
||||||
protected SampleProvider<? extends AbstractActivitySample> getProvider(DBHandler db, GBDevice device) {
|
protected SampleProvider<? extends AbstractActivitySample> getProvider(DBHandler db, GBDevice device) {
|
||||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
||||||
return coordinator.getSampleProvider(db.getDaoSession());
|
return coordinator.getSampleProvider(device, db.getDaoSession());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -260,15 +260,20 @@ public class DBHelper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Device getDevice(GBDevice gbDevice, DaoSession session) {
|
public static Device findDevice(GBDevice gbDevice, DaoSession session) {
|
||||||
DeviceDao deviceDao = session.getDeviceDao();
|
DeviceDao deviceDao = session.getDeviceDao();
|
||||||
Query<Device> query = deviceDao.queryBuilder().where(DeviceDao.Properties.Identifier.eq(gbDevice.getAddress())).build();
|
Query<Device> query = deviceDao.queryBuilder().where(DeviceDao.Properties.Identifier.eq(gbDevice.getAddress())).build();
|
||||||
List<Device> devices = query.list();
|
List<Device> devices = query.list();
|
||||||
Device device;
|
if (devices.size() > 0) {
|
||||||
if (devices.isEmpty()) {
|
return devices.get(0);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Device getDevice(GBDevice gbDevice, DaoSession session) {
|
||||||
|
Device device = findDevice(gbDevice, session);
|
||||||
|
if (device == null) {
|
||||||
device = createDevice(session, gbDevice);
|
device = createDevice(session, gbDevice);
|
||||||
} else {
|
|
||||||
device = devices.get(0);
|
|
||||||
}
|
}
|
||||||
ensureDeviceAttributes(device, gbDevice, session);
|
ensureDeviceAttributes(device, gbDevice, session);
|
||||||
|
|
||||||
@ -348,7 +353,7 @@ public class DBHelper {
|
|||||||
try (SQLiteDatabase oldDB = oldDbHandler.getReadableDatabase()) {
|
try (SQLiteDatabase oldDB = oldDbHandler.getReadableDatabase()) {
|
||||||
User user = DBHelper.getUser(session);
|
User user = DBHelper.getUser(session);
|
||||||
for (DeviceCoordinator coordinator : DeviceHelper.getInstance().getAllCoordinators()) {
|
for (DeviceCoordinator coordinator : DeviceHelper.getInstance().getAllCoordinators()) {
|
||||||
AbstractSampleProvider<? extends AbstractActivitySample> sampleProvider = (AbstractSampleProvider<? extends AbstractActivitySample>) coordinator.getSampleProvider(session);
|
AbstractSampleProvider<? extends AbstractActivitySample> sampleProvider = (AbstractSampleProvider<? extends AbstractActivitySample>) coordinator.getSampleProvider(targetDevice, session);
|
||||||
importActivitySamples(oldDB, targetDevice, session, sampleProvider, user);
|
importActivitySamples(oldDB, targetDevice, session, sampleProvider, user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.devices;
|
package nodomain.freeyourgadget.gadgetbridge.devices;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.greenrobot.dao.AbstractDao;
|
import de.greenrobot.dao.AbstractDao;
|
||||||
import de.greenrobot.dao.Property;
|
import de.greenrobot.dao.Property;
|
||||||
import de.greenrobot.dao.query.QueryBuilder;
|
import de.greenrobot.dao.query.QueryBuilder;
|
||||||
import de.greenrobot.dao.query.WhereCondition;
|
import de.greenrobot.dao.query.WhereCondition;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,11 +22,17 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
|||||||
public abstract class AbstractSampleProvider<T extends AbstractActivitySample> implements SampleProvider<T> {
|
public abstract class AbstractSampleProvider<T extends AbstractActivitySample> implements SampleProvider<T> {
|
||||||
private static final WhereCondition[] NO_CONDITIONS = new WhereCondition[0];
|
private static final WhereCondition[] NO_CONDITIONS = new WhereCondition[0];
|
||||||
private final DaoSession mSession;
|
private final DaoSession mSession;
|
||||||
|
private final GBDevice mDevice;
|
||||||
|
|
||||||
protected AbstractSampleProvider(DaoSession session) {
|
protected AbstractSampleProvider(GBDevice device, DaoSession session) {
|
||||||
|
mDevice = device;
|
||||||
mSession = session;
|
mSession = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GBDevice getmDevice() {
|
||||||
|
return mDevice;
|
||||||
|
}
|
||||||
|
|
||||||
public DaoSession getSession() {
|
public DaoSession getSession() {
|
||||||
return mSession;
|
return mSession;
|
||||||
}
|
}
|
||||||
@ -83,7 +93,13 @@ public abstract class AbstractSampleProvider<T extends AbstractActivitySample> i
|
|||||||
protected List<T> getGBActivitySamples(int timestamp_from, int timestamp_to, int activityType) {
|
protected List<T> getGBActivitySamples(int timestamp_from, int timestamp_to, int activityType) {
|
||||||
QueryBuilder<T> qb = getSampleDao().queryBuilder();
|
QueryBuilder<T> qb = getSampleDao().queryBuilder();
|
||||||
Property timestampProperty = getTimestampSampleProperty();
|
Property timestampProperty = getTimestampSampleProperty();
|
||||||
qb.where(timestampProperty.ge(timestamp_from))
|
Device dbDevice = DBHelper.findDevice(getmDevice(), getSession());
|
||||||
|
if (dbDevice == null) {
|
||||||
|
// no device, no samples
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
Property deviceProperty = getDeviceIdentifierSampleProperty();
|
||||||
|
qb.where(deviceProperty.eq(dbDevice.getId()), timestampProperty.ge(timestamp_from))
|
||||||
.where(timestampProperty.le(timestamp_to), getClauseForActivityType(qb, activityType));
|
.where(timestampProperty.le(timestamp_to), getClauseForActivityType(qb, activityType));
|
||||||
List<T> samples = qb.build().list();
|
List<T> samples = qb.build().list();
|
||||||
for (T sample : samples) {
|
for (T sample : samples) {
|
||||||
@ -131,4 +147,5 @@ public abstract class AbstractSampleProvider<T extends AbstractActivitySample> i
|
|||||||
|
|
||||||
protected abstract Property getRawKindSampleProperty();
|
protected abstract Property getRawKindSampleProperty();
|
||||||
protected abstract Property getTimestampSampleProperty();
|
protected abstract Property getTimestampSampleProperty();
|
||||||
|
protected abstract Property getDeviceIdentifierSampleProperty();
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ public interface DeviceCoordinator {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
SampleProvider<? extends ActivitySample> getSampleProvider(DaoSession session);
|
SampleProvider<? extends ActivitySample> getSampleProvider(GBDevice device, DaoSession session);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds an install handler for the given uri that can install the given
|
* Finds an install handler for the given uri that can install the given
|
||||||
|
@ -111,7 +111,7 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SampleProvider<?> getSampleProvider(DaoSession session) {
|
public SampleProvider<?> getSampleProvider(GBDevice device, DaoSession session) {
|
||||||
return new UnknownSampleProvider();
|
return new UnknownSampleProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,8 +56,8 @@ public class MiBandCoordinator extends AbstractDeviceCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SampleProvider<? extends AbstractActivitySample> getSampleProvider(DaoSession session) {
|
public SampleProvider<? extends AbstractActivitySample> getSampleProvider(GBDevice device, DaoSession session) {
|
||||||
return new MiBandSampleProvider(session);
|
return new MiBandSampleProvider(device, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,6 +7,7 @@ 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.entities.MiBandActivitySampleDao;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
|
|
||||||
public class MiBandSampleProvider extends AbstractSampleProvider<MiBandActivitySample> {
|
public class MiBandSampleProvider extends AbstractSampleProvider<MiBandActivitySample> {
|
||||||
@ -28,8 +29,8 @@ 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;
|
||||||
|
|
||||||
public MiBandSampleProvider(DaoSession session) {
|
public MiBandSampleProvider(GBDevice device, DaoSession session) {
|
||||||
super(session);
|
super(device, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -88,6 +89,11 @@ public class MiBandSampleProvider extends AbstractSampleProvider<MiBandActivityS
|
|||||||
return MiBandActivitySampleDao.Properties.Timestamp;
|
return MiBandActivitySampleDao.Properties.Timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Property getDeviceIdentifierSampleProperty() {
|
||||||
|
return MiBandActivitySampleDao.Properties.DeviceId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Property getRawKindSampleProperty() {
|
protected Property getRawKindSampleProperty() {
|
||||||
return MiBandActivitySampleDao.Properties.RawKind;
|
return MiBandActivitySampleDao.Properties.RawKind;
|
||||||
|
@ -4,12 +4,14 @@ import de.greenrobot.dao.AbstractDao;
|
|||||||
import de.greenrobot.dao.Property;
|
import de.greenrobot.dao.Property;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySampleDao;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySampleDao;
|
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySampleDao;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
|
||||||
public abstract class AbstractPebbleSampleProvider extends AbstractSampleProvider<PebbleActivitySample> {
|
public abstract class AbstractPebbleSampleProvider extends AbstractSampleProvider<PebbleActivitySample> {
|
||||||
protected AbstractPebbleSampleProvider(DaoSession session) {
|
protected AbstractPebbleSampleProvider(GBDevice device, DaoSession session) {
|
||||||
super(session);
|
super(device, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -27,6 +29,11 @@ public abstract class AbstractPebbleSampleProvider extends AbstractSampleProvide
|
|||||||
return PebbleActivitySampleDao.Properties.RawKind;
|
return PebbleActivitySampleDao.Properties.RawKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Property getDeviceIdentifierSampleProperty() {
|
||||||
|
return PebbleActivitySampleDao.Properties.DeviceId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PebbleActivitySample createActivitySample() {
|
public PebbleActivitySample createActivitySample() {
|
||||||
return new PebbleActivitySample();
|
return new PebbleActivitySample();
|
||||||
|
@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
|||||||
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.PebbleActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
|
|
||||||
public class HealthSampleProvider extends AbstractPebbleSampleProvider {
|
public class HealthSampleProvider extends AbstractPebbleSampleProvider {
|
||||||
@ -12,8 +13,8 @@ public class HealthSampleProvider extends AbstractPebbleSampleProvider {
|
|||||||
|
|
||||||
protected final float movementDivisor = 8000f;
|
protected final float movementDivisor = 8000f;
|
||||||
|
|
||||||
public HealthSampleProvider(DaoSession session) {
|
public HealthSampleProvider(GBDevice device, DaoSession session) {
|
||||||
super(session);
|
super(device, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,13 +2,14 @@ package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
|||||||
|
|
||||||
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.impl.GBDevice;
|
||||||
|
|
||||||
public class MisfitSampleProvider extends AbstractPebbleSampleProvider {
|
public class MisfitSampleProvider extends AbstractPebbleSampleProvider {
|
||||||
|
|
||||||
protected final float movementDivisor = 300f;
|
protected final float movementDivisor = 300f;
|
||||||
|
|
||||||
public MisfitSampleProvider(DaoSession session) {
|
public MisfitSampleProvider(GBDevice device, DaoSession session) {
|
||||||
super(session);
|
super(device, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
|||||||
|
|
||||||
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.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
|
|
||||||
public class MorpheuzSampleProvider extends AbstractPebbleSampleProvider {
|
public class MorpheuzSampleProvider extends AbstractPebbleSampleProvider {
|
||||||
@ -13,8 +14,8 @@ public class MorpheuzSampleProvider extends AbstractPebbleSampleProvider {
|
|||||||
|
|
||||||
protected float movementDivisor = 5000f;
|
protected float movementDivisor = 5000f;
|
||||||
|
|
||||||
public MorpheuzSampleProvider(DaoSession session) {
|
public MorpheuzSampleProvider(GBDevice device, DaoSession session) {
|
||||||
super(session);
|
super(device, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,20 +46,20 @@ public class PebbleCoordinator extends AbstractDeviceCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SampleProvider<? extends AbstractActivitySample> getSampleProvider(DaoSession session) {
|
public SampleProvider<? extends AbstractActivitySample> getSampleProvider(GBDevice device, DaoSession session) {
|
||||||
Prefs prefs = GBApplication.getPrefs();
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
int activityTracker = prefs.getInt("pebble_activitytracker", SampleProvider.PROVIDER_PEBBLE_HEALTH);
|
int activityTracker = prefs.getInt("pebble_activitytracker", SampleProvider.PROVIDER_PEBBLE_HEALTH);
|
||||||
switch (activityTracker) {
|
switch (activityTracker) {
|
||||||
case SampleProvider.PROVIDER_PEBBLE_HEALTH:
|
case SampleProvider.PROVIDER_PEBBLE_HEALTH:
|
||||||
return new HealthSampleProvider(session);
|
return new HealthSampleProvider(device, session);
|
||||||
case SampleProvider.PROVIDER_PEBBLE_MISFIT:
|
case SampleProvider.PROVIDER_PEBBLE_MISFIT:
|
||||||
return new MisfitSampleProvider(session);
|
return new MisfitSampleProvider(device, session);
|
||||||
case SampleProvider.PROVIDER_PEBBLE_MORPHEUZ:
|
case SampleProvider.PROVIDER_PEBBLE_MORPHEUZ:
|
||||||
return new MorpheuzSampleProvider(session);
|
return new MorpheuzSampleProvider(device, session);
|
||||||
case SampleProvider.PROVIDER_PEBBLE_GADGETBRIDGE:
|
case SampleProvider.PROVIDER_PEBBLE_GADGETBRIDGE:
|
||||||
return new PebbleGadgetBridgeSampleProvider(session);
|
return new PebbleGadgetBridgeSampleProvider(device, session);
|
||||||
default:
|
default:
|
||||||
return new HealthSampleProvider(session);
|
return new HealthSampleProvider(device, session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,11 @@ package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
|||||||
|
|
||||||
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.impl.GBDevice;
|
||||||
|
|
||||||
public class PebbleGadgetBridgeSampleProvider extends MorpheuzSampleProvider {
|
public class PebbleGadgetBridgeSampleProvider extends MorpheuzSampleProvider {
|
||||||
public PebbleGadgetBridgeSampleProvider(DaoSession session) {
|
public PebbleGadgetBridgeSampleProvider(GBDevice device, DaoSession session) {
|
||||||
super(session);
|
super(device, session);
|
||||||
movementDivisor = 63.0f;
|
movementDivisor = 63.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +305,7 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
|
|||||||
byte category, intensity, steps, heartrate = 0;
|
byte category, intensity, steps, heartrate = 0;
|
||||||
|
|
||||||
try (DBHandler dbHandler = GBApplication.acquireDB()){
|
try (DBHandler dbHandler = GBApplication.acquireDB()){
|
||||||
MiBandSampleProvider provider = new MiBandSampleProvider(dbHandler.getDaoSession());
|
MiBandSampleProvider provider = new MiBandSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||||
Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
|
Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
|
||||||
Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId();
|
Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId();
|
||||||
int minutes = 0;
|
int minutes = 0;
|
||||||
|
@ -58,7 +58,7 @@ public class AppMessageHandlerGBPebble extends AppMessageHandler {
|
|||||||
try (DBHandler db = GBApplication.acquireDB()) {
|
try (DBHandler db = GBApplication.acquireDB()) {
|
||||||
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());
|
||||||
PebbleGadgetBridgeSampleProvider sampleProvider = new PebbleGadgetBridgeSampleProvider(db.getDaoSession());
|
PebbleGadgetBridgeSampleProvider sampleProvider = new PebbleGadgetBridgeSampleProvider(getDevice(), db.getDaoSession());
|
||||||
PebbleActivitySample[] activitySamples = new PebbleActivitySample[samples_remaining];
|
PebbleActivitySample[] activitySamples = new PebbleActivitySample[samples_remaining];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (samples_remaining-- > 0) {
|
while (samples_remaining-- > 0) {
|
||||||
|
@ -22,6 +22,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.pebble.MisfitSampleProvider;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBActivitySample;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
|
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
|
||||||
|
GBDevice device = getDevice();
|
||||||
for (Pair<Integer, Object> pair : pairs) {
|
for (Pair<Integer, Object> pair : pairs) {
|
||||||
switch (pair.first) {
|
switch (pair.first) {
|
||||||
case KEY_INCOMING_DATA_BEGIN:
|
case KEY_INCOMING_DATA_BEGIN:
|
||||||
@ -116,7 +118,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
|
|||||||
}
|
}
|
||||||
LOG.info("total steps for above period: " + totalSteps);
|
LOG.info("total steps for above period: " + totalSteps);
|
||||||
|
|
||||||
MisfitSampleProvider sampleProvider = new MisfitSampleProvider(db.getDaoSession());
|
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);
|
||||||
|
@ -102,7 +102,7 @@ public class AppMessageHandlerMorpheuz extends AppMessageHandler {
|
|||||||
try (DBHandler db = GBApplication.acquireDB()) {
|
try (DBHandler db = GBApplication.acquireDB()) {
|
||||||
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(db.getDaoSession());
|
MorpheuzSampleProvider sampleProvider = new MorpheuzSampleProvider(getDevice(), db.getDaoSession());
|
||||||
sampleProvider.addGBActivitySample(createSample(recording_base_timestamp + index * 600, intensity, 0, type, user, device));
|
sampleProvider.addGBActivitySample(createSample(recording_base_timestamp + index * 600, intensity, 0, type, user, device));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error acquiring database", e);
|
LOG.error("Error acquiring database", e);
|
||||||
|
@ -10,6 +10,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.HealthSampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.HealthSampleProvider;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
@ -17,8 +18,8 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
|
|||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(DatalogSessionHealthOverlayData.class);
|
private static final Logger LOG = LoggerFactory.getLogger(DatalogSessionHealthOverlayData.class);
|
||||||
|
|
||||||
public DatalogSessionHealthOverlayData(byte id, UUID uuid, int tag, byte item_type, short item_size) {
|
public DatalogSessionHealthOverlayData(byte id, UUID uuid, int tag, byte item_type, short item_size, GBDevice device) {
|
||||||
super(id, uuid, tag, item_type, item_size);
|
super(id, uuid, tag, item_type, item_size, device);
|
||||||
taginfo = "(health - overlay data " + tag + " )";
|
taginfo = "(health - overlay data " + tag + " )";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
|
|||||||
|
|
||||||
private boolean store(OverlayRecord[] overlayRecords) {
|
private boolean store(OverlayRecord[] overlayRecords) {
|
||||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||||
SampleProvider sampleProvider = new HealthSampleProvider(dbHandler.getDaoSession());
|
SampleProvider sampleProvider = new HealthSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||||
int latestTimestamp = sampleProvider.fetchLatestTimestamp();
|
int latestTimestamp = sampleProvider.fetchLatestTimestamp();
|
||||||
for (OverlayRecord overlayRecord : overlayRecords) {
|
for (OverlayRecord overlayRecord : overlayRecords) {
|
||||||
if (latestTimestamp < (overlayRecord.timestampStart + overlayRecord.durationSeconds))
|
if (latestTimestamp < (overlayRecord.timestampStart + overlayRecord.durationSeconds))
|
||||||
|
@ -10,6 +10,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.HealthSampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.HealthSampleProvider;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
@ -17,8 +18,8 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
|
|||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(DatalogSessionHealthSleep.class);
|
private static final Logger LOG = LoggerFactory.getLogger(DatalogSessionHealthSleep.class);
|
||||||
|
|
||||||
public DatalogSessionHealthSleep(byte id, UUID uuid, int tag, byte item_type, short item_size) {
|
public DatalogSessionHealthSleep(byte id, UUID uuid, int tag, byte item_type, short item_size, GBDevice device) {
|
||||||
super(id, uuid, tag, item_type, item_size);
|
super(id, uuid, tag, item_type, item_size, device);
|
||||||
taginfo = "(health - sleep " + tag + " )";
|
taginfo = "(health - sleep " + tag + " )";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
|
|||||||
|
|
||||||
private boolean store(SleepRecord[] sleepRecords) {
|
private boolean store(SleepRecord[] sleepRecords) {
|
||||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||||
SampleProvider sampleProvider = new HealthSampleProvider(dbHandler.getDaoSession());
|
SampleProvider sampleProvider = new HealthSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||||
int latestTimestamp = sampleProvider.fetchLatestTimestamp();
|
int latestTimestamp = sampleProvider.fetchLatestTimestamp();
|
||||||
for (SleepRecord sleepRecord : sleepRecords) {
|
for (SleepRecord sleepRecord : sleepRecords) {
|
||||||
if (latestTimestamp < sleepRecord.bedTimeEnd)
|
if (latestTimestamp < sleepRecord.bedTimeEnd)
|
||||||
|
@ -10,25 +10,19 @@ import java.util.UUID;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.HealthSampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.HealthSampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBActivitySample;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(DatalogSessionHealthSteps.class);
|
private static final Logger LOG = LoggerFactory.getLogger(DatalogSessionHealthSteps.class);
|
||||||
private final GBDevice device;
|
|
||||||
|
|
||||||
public DatalogSessionHealthSteps(byte id, UUID uuid, int tag, byte item_type, short item_size, GBDevice device) {
|
public DatalogSessionHealthSteps(byte id, UUID uuid, int tag, byte item_type, short item_size, GBDevice device) {
|
||||||
super(id, uuid, tag, item_type, item_size);
|
super(id, uuid, tag, item_type, item_size, device);
|
||||||
taginfo = "(health - steps)";
|
taginfo = "(health - steps)";
|
||||||
this.device = device;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -81,11 +75,11 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
|||||||
private void store(StepsRecord[] stepsRecords) {
|
private void store(StepsRecord[] stepsRecords) {
|
||||||
|
|
||||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||||
HealthSampleProvider sampleProvider = new HealthSampleProvider(dbHandler.getDaoSession());
|
HealthSampleProvider sampleProvider = new HealthSampleProvider(getDevice(), dbHandler.getDaoSession());
|
||||||
PebbleActivitySample[] samples = new PebbleActivitySample[stepsRecords.length];
|
PebbleActivitySample[] samples = new PebbleActivitySample[stepsRecords.length];
|
||||||
// TODO: user and device
|
// TODO: user and device
|
||||||
Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
|
Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
|
||||||
Long deviceId = DBHelper.getDevice(device, dbHandler.getDaoSession()).getId();
|
Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId();
|
||||||
for (int j = 0; j < stepsRecords.length; j++) {
|
for (int j = 0; j < stepsRecords.length; j++) {
|
||||||
StepsRecord stepsRecord = stepsRecords[j];
|
StepsRecord stepsRecord = stepsRecords[j];
|
||||||
samples[j] = new PebbleActivitySample(
|
samples[j] = new PebbleActivitySample(
|
||||||
|
@ -3,12 +3,20 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
abstract class DatalogSessionPebbleHealth extends DatalogSession {
|
abstract class DatalogSessionPebbleHealth extends DatalogSession {
|
||||||
|
|
||||||
DatalogSessionPebbleHealth(byte id, UUID uuid, int tag, byte itemType, short itemSize) {
|
private final GBDevice mDevice;
|
||||||
|
|
||||||
|
DatalogSessionPebbleHealth(byte id, UUID uuid, int tag, byte itemType, short itemSize, GBDevice device) {
|
||||||
super(id, uuid, tag, itemType, itemSize);
|
super(id, uuid, tag, itemType, itemSize);
|
||||||
|
mDevice = device;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GBDevice getDevice() {
|
||||||
|
return mDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isPebbleHealthEnabled() {
|
protected boolean isPebbleHealthEnabled() {
|
||||||
|
@ -1999,9 +1999,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
if (uuid.equals(UUID_ZERO) && log_tag == 81) {
|
if (uuid.equals(UUID_ZERO) && log_tag == 81) {
|
||||||
mDatalogSessions.put(id, new DatalogSessionHealthSteps(id, uuid, log_tag, item_type, item_size, getDevice()));
|
mDatalogSessions.put(id, new DatalogSessionHealthSteps(id, uuid, log_tag, item_type, item_size, getDevice()));
|
||||||
} else if (uuid.equals(UUID_ZERO) && log_tag == 83) {
|
} else if (uuid.equals(UUID_ZERO) && log_tag == 83) {
|
||||||
mDatalogSessions.put(id, new DatalogSessionHealthSleep(id, uuid, log_tag, item_type, item_size));
|
mDatalogSessions.put(id, new DatalogSessionHealthSleep(id, uuid, log_tag, item_type, item_size, getDevice()));
|
||||||
} else if (uuid.equals(UUID_ZERO) && log_tag == 84) {
|
} else if (uuid.equals(UUID_ZERO) && log_tag == 84) {
|
||||||
mDatalogSessions.put(id, new DatalogSessionHealthOverlayData(id, uuid, log_tag, item_type, item_size));
|
mDatalogSessions.put(id, new DatalogSessionHealthOverlayData(id, uuid, log_tag, item_type, item_size, getDevice()));
|
||||||
} else {
|
} else {
|
||||||
mDatalogSessions.put(id, new DatalogSession(id, uuid, log_tag, item_type, item_size));
|
mDatalogSessions.put(id, new DatalogSession(id, uuid, log_tag, item_type, item_size));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user