Search in sources :

Example 1 with HuamiActivitySummaryParser

use of nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiActivitySummaryParser in project Gadgetbridge by Freeyourgadget.

the class FetchSportsSummaryOperation method handleActivityFetchFinish.

@Override
protected void handleActivityFetchFinish(boolean success) {
    LOG.info(getName() + " has finished round " + fetchCount);
    // GregorianCalendar lastSyncTimestamp = saveSamples();
    // if (lastSyncTimestamp != null && needsAnotherFetch(lastSyncTimestamp)) {
    // try {
    // startFetching();
    // return;
    // } catch (IOException ex) {
    // LOG.error("Error starting another round of fetching activity data", ex);
    // }
    // }
    BaseActivitySummary summary = null;
    if (success) {
        summary = new BaseActivitySummary();
        // due to a bug this has to be set
        summary.setStartTime(getLastStartTimestamp().getTime());
        summary.setRawSummaryData(buffer.toByteArray());
        HuamiActivitySummaryParser parser = new HuamiActivitySummaryParser();
        summary = parser.parseBinaryData(summary);
        if (summary != null) {
            // remove json before saving to database,
            summary.setSummaryData(null);
            try (DBHandler dbHandler = GBApplication.acquireDB()) {
                DaoSession session = dbHandler.getDaoSession();
                Device device = DBHelper.getDevice(getDevice(), session);
                User user = DBHelper.getUser(session);
                summary.setDevice(device);
                summary.setUser(user);
                summary.setRawSummaryData(buffer.toByteArray());
                session.getBaseActivitySummaryDao().insertOrReplace(summary);
            } catch (Exception ex) {
                GB.toast(getContext(), "Error saving activity summary", Toast.LENGTH_LONG, GB.ERROR, ex);
            }
        }
    }
    super.handleActivityFetchFinish(success);
    if (summary != null) {
        FetchSportsDetailsOperation nextOperation = new FetchSportsDetailsOperation(summary, getSupport(), getLastSyncTimeKey());
        try {
            nextOperation.perform();
        } catch (IOException ex) {
            GB.toast(getContext(), "Unable to fetch activity details: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
        }
    }
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) User(nodomain.freeyourgadget.gadgetbridge.entities.User) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) BaseActivitySummary(nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary) HuamiActivitySummaryParser(nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiActivitySummaryParser) IOException(java.io.IOException) IOException(java.io.IOException) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)

Example 2 with HuamiActivitySummaryParser

use of nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiActivitySummaryParser in project Gadgetbridge by Freeyourgadget.

the class ActivitySummaryJsonSummary method getCorrectSummary.

private String getCorrectSummary(BaseActivitySummary item) {
    if (item.getRawSummaryData() != null) {
        // FIXME: if something else than huami supports that make sure to have the right parser
        ActivitySummaryParser parser = new HuamiActivitySummaryParser();
        item = parser.parseBinaryData(item);
    }
    return item.getSummaryData();
}
Also used : HuamiActivitySummaryParser(nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiActivitySummaryParser) HuamiActivitySummaryParser(nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiActivitySummaryParser)

Aggregations

HuamiActivitySummaryParser (nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiActivitySummaryParser)2 IOException (java.io.IOException)1 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)1 BaseActivitySummary (nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary)1 DaoSession (nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)1 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1