Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strava fixes #1166

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/org/runnerup/export/StravaSynchronizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public Status upload(SQLiteDatabase db, final long mID) {
try {
TCX tcx = new TCX(db, simplifier);
StringWriter writer = new StringWriter();
tcx.export(mID, writer);
tcx.exportForStrava(mID, writer);
ActivityDbInfo dbInfo = getStravaType(db, mID);

HttpURLConnection conn = (HttpURLConnection) new URL(UPLOAD_URL).openConnection();
Expand Down
64 changes: 48 additions & 16 deletions app/src/main/org/runnerup/export/format/TCX.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ private String formatTime(long time) {
}

public String export(long activityId, Writer writer) throws IOException {
Pair<String,Sport> res = exportWithSport(activityId, writer);
Pair<String,Sport> res = exportWithSport(activityId, writer, false);
return res.first;
}

public String exportForStrava(long activityId, Writer writer) throws IOException {
Pair<String,Sport> res = exportWithSport(activityId, writer, true);
return res.first;
}

Expand All @@ -77,7 +82,7 @@ public String export(long activityId, Writer writer) throws IOException {
* @return TCX id
* @throws IOException
*/
public Pair<String,Sport> exportWithSport(long activityId, Writer writer) throws IOException {
public Pair<String,Sport> exportWithSport(long activityId, Writer writer, boolean isStrava) throws IOException {

String[] aColumns = {
DB.ACTIVITY.NAME, DB.ACTIVITY.COMMENT,
Expand Down Expand Up @@ -111,21 +116,31 @@ public Pair<String,Sport> exportWithSport(long activityId, Writer writer) throws
} else {
// TCX supports only these 3 sports...(cf http://www8.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd)
sport = Sport.valueOf(cursor.getInt(3));
if (sport.IsRunning()) {
mXML.attribute("", "Sport", "Running");
}
else if (sport.IsCycling()) {
mXML.attribute("", "Sport", "Biking");
}
else {
mXML.attribute("", "Sport", "Other");
if (isStrava) {
if (sport.IsCycling()) {
mXML.attribute("", "Sport", "Biking");
} else if (sport.IsWalking()) {
mXML.attribute("", "Sport", "Walking");
} else {
// Default (Swimming, Hiking is supported too)
mXML.attribute("", "Sport", "Running");
}

} else {
if (sport.IsRunning()) {
mXML.attribute("", "Sport", "Running");
} else if (sport.IsCycling()) {
mXML.attribute("", "Sport", "Biking");
} else {
mXML.attribute("", "Sport", "Other");
}
}
}
mXML.startTag("", "Id");
String id = formatTime(startTime * 1000);
mXML.text(id);
mXML.endTag("", "Id");
exportLaps(activityId, startTime * 1000, sport);
exportLaps(activityId, startTime * 1000, sport, isStrava);
if (!cursor.isNull(1)) {
notes = cursor.getString(1);
mXML.startTag("", "Notes");
Expand Down Expand Up @@ -231,7 +246,7 @@ private void exportLapHeartRate(long activityId, long lapId) throws IOException
c.close();
}

private void exportLaps(long activityId, long startTime, Sport sport) throws IOException {
private void exportLaps(long activityId, long startTime, Sport sport, boolean isStrava) throws IOException {
String[] lColumns = {
DB.LAP.LAP, DB.LAP.TIME, DB.LAP.DISTANCE, DB.LAP.INTENSITY
};
Expand Down Expand Up @@ -365,15 +380,28 @@ private void exportLaps(long activityId, long startTime, Sport sport) throws IOE
}
if (isRunCad) {
mXML.startTag("", "Extensions");
mXML.startTag("", "ns3:TPX");
if (isStrava) {
mXML.startTag("", "TPX");
mXML.attribute("", "xmlns", "\"http://www.garmin.com/xmlschemas/ActivityExtension/v2\"");
} else {
mXML.startTag("", "ns3:TPX");
}
//"standard" extensions: RunCadence, Speed, Watts
}
if (isRunCad) {
int val = cLocation.getInt(8);
mXML.startTag("", "ns3:RunCadence");
if (isStrava) {
mXML.startTag("", "RunCadence");
} else {
mXML.startTag("", "ns3:RunCadence");
}
String sval = Integer.toString(val);
mXML.text(sval);
mXML.endTag("", "ns3:RunCadence");
if (isStrava) {
mXML.endTag("", "RunCadence");
} else {
mXML.endTag("", "ns3:RunCadence");
}
// Not including "CadenceSensor Footpod" etc
}
//if (isTemp || isPres) {
Expand All @@ -393,7 +421,11 @@ private void exportLaps(long activityId, long startTime, Sport sport) throws IOE
// }
//}
if (isRunCad) {
mXML.endTag("", "ns3:TPX");
if (isStrava) {
mXML.endTag("", "TPX");
} else {
mXML.endTag("", "ns3:TPX");
}
mXML.endTag("", "Extensions");
}

Expand Down