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);
}
}
}
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();
}
Aggregations