Search in sources :

Example 11 with Device

use of nodomain.freeyourgadget.gadgetbridge.entities.Device in project Gadgetbridge by Freeyourgadget.

the class DBHelper method findDevice.

public static Device findDevice(GBDevice gbDevice, DaoSession session) {
    DeviceDao deviceDao = session.getDeviceDao();
    Query<Device> query = deviceDao.queryBuilder().where(DeviceDao.Properties.Identifier.eq(gbDevice.getAddress())).build();
    List<Device> devices = query.list();
    if (devices.size() > 0) {
        return devices.get(0);
    }
    return null;
}
Also used : Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) DeviceDao(nodomain.freeyourgadget.gadgetbridge.entities.DeviceDao)

Example 12 with Device

use of nodomain.freeyourgadget.gadgetbridge.entities.Device in project Gadgetbridge by Freeyourgadget.

the class DBHelper method getDevice.

/**
     * Looks up in the database the Device entity corresponding to the GBDevice. If a device
     * exists already, it will be updated with the current preferences values. If no device exists
     * yet, it will be created in the database.
     *
     * @param session
     * @return the device entity corresponding to the given GBDevice
     */
public static Device getDevice(GBDevice gbDevice, DaoSession session) {
    Device device = findDevice(gbDevice, session);
    if (device == null) {
        device = createDevice(gbDevice, session);
    } else {
        ensureDeviceUpToDate(device, gbDevice, session);
    }
    ensureDeviceAttributes(device, gbDevice, session);
    return device;
}
Also used : Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Example 13 with Device

use of nodomain.freeyourgadget.gadgetbridge.entities.Device in project Gadgetbridge by Freeyourgadget.

the class AbstractSampleProvider method getLatestActivitySample.

@Nullable
@Override
public T getLatestActivitySample() {
    QueryBuilder<T> qb = getSampleDao().queryBuilder();
    Device dbDevice = DBHelper.findDevice(getDevice(), getSession());
    if (dbDevice == null) {
        // no device, no sample
        return null;
    }
    Property deviceProperty = getDeviceIdentifierSampleProperty();
    qb.where(deviceProperty.eq(dbDevice.getId())).orderDesc(getTimestampSampleProperty()).limit(1);
    List<T> samples = qb.build().list();
    if (samples.isEmpty()) {
        return null;
    }
    T sample = samples.get(0);
    sample.setProvider(this);
    return sample;
}
Also used : GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) Property(de.greenrobot.dao.Property) Nullable(android.support.annotation.Nullable)

Example 14 with Device

use of nodomain.freeyourgadget.gadgetbridge.entities.Device in project Gadgetbridge by Freeyourgadget.

the class AbstractSampleProvider method getGBActivitySamples.

protected List<T> getGBActivitySamples(int timestamp_from, int timestamp_to, int activityType) {
    if (getRawKindSampleProperty() == null && activityType != ActivityKind.TYPE_ALL) {
        // if we do not have a raw kind property we cannot query anything else then TYPE_ALL
        return Collections.emptyList();
    }
    QueryBuilder<T> qb = getSampleDao().queryBuilder();
    Property timestampProperty = getTimestampSampleProperty();
    Device dbDevice = DBHelper.findDevice(getDevice(), 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));
    List<T> samples = qb.build().list();
    for (T sample : samples) {
        sample.setProvider(this);
    }
    detachFromSession();
    return samples;
}
Also used : GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) Property(de.greenrobot.dao.Property)

Aggregations

Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)14 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)12 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)4 MiBandSampleProvider (nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandSampleProvider)3 DaoSession (nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)3 MiBandActivitySample (nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample)3 User (nodomain.freeyourgadget.gadgetbridge.entities.User)3 Test (org.junit.Test)3 BluetoothDevice (android.bluetooth.BluetoothDevice)2 Property (de.greenrobot.dao.Property)2 IOException (java.io.IOException)2 GregorianCalendar (java.util.GregorianCalendar)2 DeviceAttributes (nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes)2 DeviceDao (nodomain.freeyourgadget.gadgetbridge.entities.DeviceDao)2 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 Calendar (java.util.Calendar)1 GBException (nodomain.freeyourgadget.gadgetbridge.GBException)1 HPlusHealthActivityOverlay (nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivityOverlay)1 HPlusHealthActivitySample (nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivitySample)1