Search in sources :

Example 6 with DaoSession

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

the class PebblePairingActivity method getMatchingParentDeviceFromDB.

private GBDevice getMatchingParentDeviceFromDB(BluetoothDevice btDevice) {
    String expectedSuffix = btDevice.getName();
    expectedSuffix = expectedSuffix.replace("Pebble-LE ", "");
    expectedSuffix = expectedSuffix.replace("Pebble Time LE ", "");
    expectedSuffix = expectedSuffix.substring(0, 2) + ":" + expectedSuffix.substring(2);
    LOG.info("will try to find a Pebble with BT address suffix " + expectedSuffix);
    GBDevice gbDevice = null;
    try (DBHandler dbHandler = GBApplication.acquireDB()) {
        DaoSession session = dbHandler.getDaoSession();
        DeviceDao deviceDao = session.getDeviceDao();
        Query<Device> query = deviceDao.queryBuilder().where(DeviceDao.Properties.Type.eq(1), DeviceDao.Properties.Identifier.like("%" + expectedSuffix)).build();
        List<Device> devices = query.list();
        if (devices.size() == 0) {
            GB.toast("Please pair your non-LE Pebble before pairing the LE one", Toast.LENGTH_SHORT, GB.INFO);
            returnToPairingActivity();
            return null;
        } else if (devices.size() > 1) {
            GB.toast("Can not match this Pebble LE to a unique device", Toast.LENGTH_SHORT, GB.INFO);
            returnToPairingActivity();
            return null;
        }
        DeviceHelper deviceHelper = DeviceHelper.getInstance();
        gbDevice = deviceHelper.toGBDevice(devices.get(0));
        gbDevice.setVolatileAddress(btDevice.getAddress());
    } catch (Exception e) {
        GB.toast("Error retrieving devices from database", Toast.LENGTH_SHORT, GB.ERROR);
        returnToPairingActivity();
        return null;
    }
    return gbDevice;
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) BluetoothDevice(android.bluetooth.BluetoothDevice) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) DeviceHelper(nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper) DeviceDao(nodomain.freeyourgadget.gadgetbridge.entities.DeviceDao) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)

Example 7 with DaoSession

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

the class DBHelper method clearSession.

public static void clearSession() {
    try (DBHandler dbHandler = GBApplication.acquireDB()) {
        DaoSession session = dbHandler.getDaoSession();
        session.clear();
    } catch (Exception e) {
        LOG.warn("Unable to acquire database to clear the session", e);
    }
}
Also used : IOException(java.io.IOException) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)

Aggregations

DaoSession (nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)7 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)6 ArrayList (java.util.ArrayList)3 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)3 BluetoothDevice (android.bluetooth.BluetoothDevice)2 IOException (java.io.IOException)2 GBException (nodomain.freeyourgadget.gadgetbridge.GBException)2 PebbleHealthActivityOverlay (nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay)2 PebbleHealthActivityOverlayDao (nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao)2 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)2 GregorianCalendar (java.util.GregorianCalendar)1 HPlusHealthSampleProvider (nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusHealthSampleProvider)1 MiBandSampleProvider (nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandSampleProvider)1 DeviceDao (nodomain.freeyourgadget.gadgetbridge.entities.DeviceDao)1 HPlusHealthActivityOverlay (nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivityOverlay)1 HPlusHealthActivityOverlayDao (nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivityOverlayDao)1 HPlusHealthActivitySample (nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivitySample)1 MiBandActivitySample (nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1 DeviceHelper (nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper)1