use of nodomain.freeyourgadget.gadgetbridge.export.ActivityTrackExporter in project Gadgetbridge by Freeyourgadget.
the class FetchSportsDetailsOperation method handleActivityFetchFinish.
@Override
protected void handleActivityFetchFinish(boolean success) {
LOG.info(getName() + " has finished round " + fetchCount);
if (success) {
HuamiActivityDetailsParser parser = new HuamiActivityDetailsParser(summary);
// is already stripped
parser.setSkipCounterByte(false);
try {
ActivityTrack track = parser.parse(buffer.toByteArray());
ActivityTrackExporter exporter = createExporter();
String trackType = "track";
switch(summary.getActivityKind()) {
case ActivityKind.TYPE_CYCLING:
trackType = getContext().getString(R.string.activity_type_biking);
break;
case ActivityKind.TYPE_RUNNING:
trackType = getContext().getString(R.string.activity_type_running);
break;
case ActivityKind.TYPE_WALKING:
trackType = getContext().getString(R.string.activity_type_walking);
break;
case ActivityKind.TYPE_HIKING:
trackType = getContext().getString(R.string.activity_type_hiking);
break;
case ActivityKind.TYPE_CLIMBING:
trackType = getContext().getString(R.string.activity_type_climbing);
break;
case ActivityKind.TYPE_SWIMMING:
trackType = getContext().getString(R.string.activity_type_swimming);
break;
}
String fileName = FileUtils.makeValidFileName("gadgetbridge-" + trackType.toLowerCase() + "-" + DateTimeUtils.formatIso8601(summary.getStartTime()) + ".gpx");
File targetFile = new File(FileUtils.getExternalFilesDir(), fileName);
try {
exporter.performExport(track, targetFile);
try (DBHandler dbHandler = GBApplication.acquireDB()) {
summary.setGpxTrack(targetFile.getAbsolutePath());
dbHandler.getDaoSession().getBaseActivitySummaryDao().update(summary);
}
} catch (ActivityTrackExporter.GPXTrackEmptyException ex) {
GB.toast(getContext(), "This activity does not contain GPX tracks.", Toast.LENGTH_LONG, GB.ERROR, ex);
}
GregorianCalendar endTime = BLETypeConversions.createCalendar();
endTime.setTime(summary.getEndTime());
saveLastSyncTimestamp(endTime);
} catch (Exception ex) {
GB.toast(getContext(), "Error getting activity details: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
}
}
super.handleActivityFetchFinish(success);
}
Aggregations