1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-15 14:39:26 +01:00

Activity Summary: Draw fit file if available

This commit is contained in:
José Rebelo 2024-05-03 20:57:47 +01:00 committed by Daniele Gobbetti
parent 0b07f36817
commit a25d8eae30
2 changed files with 58 additions and 21 deletions

View File

@ -34,12 +34,18 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint;
import nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.FitFile;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.FitImporter;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.RecordData;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.messages.FitRecord;
import nodomain.freeyourgadget.gadgetbridge.util.gpx.GpxParseException;
import nodomain.freeyourgadget.gadgetbridge.util.gpx.GpxParser;
import nodomain.freeyourgadget.gadgetbridge.util.gpx.model.GpxFile;
@ -76,11 +82,11 @@ public class ActivitySummariesGpsFragment extends AbstractGBFragment {
new Thread(new Runnable() {
@Override
public void run() {
final GpxFile gpxFile;
final List<GPSCoordinate> points = new ArrayList<>();
if (inputFile.getName().endsWith(".gpx")) {
try (FileInputStream inputStream = new FileInputStream(inputFile)) {
final GpxParser gpxParser = new GpxParser(inputStream);
gpxFile = gpxParser.getGpxFile();
points.addAll(gpxParser.getGpxFile().getPoints());
} catch (final IOException e) {
LOG.error("Failed to open {}", inputFile, e);
return;
@ -88,9 +94,31 @@ public class ActivitySummariesGpsFragment extends AbstractGBFragment {
LOG.error("Failed to parse gpx file", e);
return;
}
} else if (inputFile.getName().endsWith(".fit")) {
try {
FitFile fitFile = FitFile.parseIncoming(inputFile);
for (final RecordData record : fitFile.getRecords()) {
if (record instanceof FitRecord) {
final ActivityPoint activityPoint = ((FitRecord) record).toActivityPoint();
if (activityPoint.getLocation() != null) {
points.add(activityPoint.getLocation());
}
}
}
} catch (final IOException e) {
LOG.error("Failed to open {}", inputFile, e);
return;
} catch (final Exception e) {
LOG.error("Failed to parse fit file", e);
return;
}
} else {
LOG.warn("Unknown file type {}", inputFile.getName());
return;
}
if (!gpxFile.getPoints().isEmpty()) {
drawTrack(canvas, gpxFile.getPoints());
if (!points.isEmpty()) {
drawTrack(canvas, points);
}
}
}).start();

View File

@ -184,9 +184,9 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
makeSummaryHeader(newItem);
makeSummaryContent(newItem);
activitySummariesChartFragment.setDateAndGetData(getGBDevice(currentItem.getDevice()), currentItem.getStartTime().getTime() / 1000, currentItem.getEndTime().getTime() / 1000);
if (get_gpx_file() != null) {
if (getTrackFile() != null) {
showCanvas();
activitySummariesGpsFragment.set_data(get_gpx_file());
activitySummariesGpsFragment.set_data(getTrackFile());
} else {
hideCanvas();
}
@ -206,9 +206,9 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
makeSummaryHeader(newItem);
makeSummaryContent(newItem);
activitySummariesChartFragment.setDateAndGetData(getGBDevice(currentItem.getDevice()), currentItem.getStartTime().getTime() / 1000, currentItem.getEndTime().getTime() / 1000);
if (get_gpx_file() != null) {
if (getTrackFile() != null) {
showCanvas();
activitySummariesGpsFragment.set_data(get_gpx_file());
activitySummariesGpsFragment.set_data(getTrackFile());
} else {
hideCanvas();
}
@ -227,9 +227,9 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
makeSummaryHeader(currentItem);
makeSummaryContent(currentItem);
activitySummariesChartFragment.setDateAndGetData(getGBDevice(currentItem.getDevice()), currentItem.getStartTime().getTime() / 1000, currentItem.getEndTime().getTime() / 1000);
if (get_gpx_file() != null) {
if (getTrackFile() != null) {
showCanvas();
activitySummariesGpsFragment.set_data(get_gpx_file());
activitySummariesGpsFragment.set_data(getTrackFile());
} else {
hideCanvas();
}
@ -320,9 +320,9 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
public void onClick(DialogInterface dialog, int which) {
currentItem.setGpxTrack(selectedGpxFile);
currentItem.update();
if (get_gpx_file() != null) {
if (getTrackFile() != null) {
showCanvas();
activitySummariesGpsFragment.set_data(get_gpx_file());
activitySummariesGpsFragment.set_data(getTrackFile());
} else {
hideCanvas();
}
@ -712,7 +712,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
gpsView.setLayoutParams(params);
}
private File get_gpx_file() {
private File getTrackFile() {
final String gpxTrack = currentItem.getGpxTrack();
if (gpxTrack != null) {
File file = new File(gpxTrack);
@ -722,6 +722,15 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
return null;
}
}
final String rawDetails = currentItem.getRawDetailsPath();
if (rawDetails != null && rawDetails.endsWith(".fit")) {
File file = new File(rawDetails);
if (file.exists()) {
return file;
} else {
return null;
}
}
return null;
}