Skip to content

Commit

Permalink
TCX Export Enhancement and fixes (#287)
Browse files Browse the repository at this point in the history
* Changes per code review

* Removing the harmless ResourceNotFoundException

* Putting it back

* We clear the browser session so that a user can log in with different
accounts

* Misc

* Useless

* Making the Strava upload asynchronous to speed up the upload

* Renaming the field per Wolfgang suggestion

* Putting fields, which belong together, into { ... }, for better
readability

* displaying the account user name in the upload dialog

* Misc

* Export Unit tests update and successful

* Unit tests

* Unit tests update after this fix
20bb310

* XML Unit 2.8.2

* Using OauthConstants

* Typo

* Unit tests update

* Dropbox Authentication modifications (Using external browser and PKCE implementation) (#38)

* Readme update

* Misc

* Adding the number of tours in the progress bar message

* Translation typos

* Trying to renew the token right before uploading the tours

* Default button is now at the bottom of the page

* Putting constructLocalExpireAtDateTime in TimeTools for reuse

* the icon is at the beginning of the line and the dots are removed

* removing the prefstore listener when closed

* 2021

* Removing the colons from the labels

* Misc

* Use a more random number for the port (4917) and displyaing an error
message if it's not available.

* Misc

* Changing the Dropbox Url

* Using the external browser for Strava as well

* Misc

* Misc

* Upper case for public fields

* Protected

* Misc improvements

* English typos

* Removing the code that is too context specific

* Expires At is now at the bottom

* V2 ?

* Per code review

* Removing slf4j warnings

* Adding the ability to upload manual tours to Strava (#40)

* Renaming

* No dot

* TCX Export Enhancement and fixes (#41)

* Readme update

* Misc

* Stopping the server when leaving the preference page

* SOnarLint

* Misc

* Date
  • Loading branch information
FJBDev committed Jan 13, 2021
1 parent 53b9fe7 commit 62a8c67
Show file tree
Hide file tree
Showing 18 changed files with 22,339 additions and 8,994 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ public void init(final IWorkbench workbench) {
//Not needed
}

@Override
public boolean okToLeave() {

if (_server != null) {
_server.stopCallBackServer();
}

return super.okToLeave();
}

/**
* When the user clicks on the "Authorize" button, a browser is opened
* so that the user can allow the MyTourbook Dropbox app to have access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ public void init(final IWorkbench workbench) {
//Not needed
}

@Override
public boolean okToLeave() {

if (_server != null) {
_server.stopCallBackServer();
}

return super.okToLeave();
}

/**
* When the user clicks on the "Authorize" button, a browser is opened
* so that the user can allow the MyTourbook Strava app to have access
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (C) 2021 Frédéric Bard
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*******************************************************************************/

package net.tourbook.common.util;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

import net.tourbook.common.UI;

public final class FilesUtils {

public static String readFileContentString(final String filePath) {

String fileContent = UI.EMPTY_STRING;
try {
fileContent = Files.readString(Paths.get(filePath), StandardCharsets.US_ASCII);
} catch (final IOException e) {
StatusUtil.log(e);
}
return fileContent;
}
}
2 changes: 1 addition & 1 deletion bundles/net.tourbook.export/format-templates/gpx-1.0.vm
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
<time>$dateformat.format($point.Date)</time>
#end
##
#if($point.hasValidExtention())
#if($point.hasValidExtension())
<extensions>
<gpxtpx:TrackPointExtension>
#if($point.hasValidTemperature())
Expand Down
79 changes: 61 additions & 18 deletions bundles/net.tourbook.export/format-templates/tcx-2.0.vm
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,48 @@
<TrainingCenterDatabase
xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 https://www8.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd">
xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 https://www8.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd http://www.garmin.com/xmlschemas/ActivityExtension/v2 https://www8.garmin.com/xmlschemas/ActivityExtensionv2.xsd">
#if($iscourses)
<Courses>
<Course>
<Name>$coursename</Name>
<Lap>
#else
<Activities>
<Activity Sport="$activityType">
#end
<Id>$dateformat.format($starttime)</Id>
<Lap StartTime="$dateformat.format($starttime)">
#end
<TotalTimeSeconds>$totaltime</TotalTimeSeconds>
<DistanceMeters>$nf3.format($totaldistance)</DistanceMeters>
#if(!$iscourses)
<Calories>$lap.getCalories()</Calories>
#end
#if($averageheartrate)
<AverageHeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<AverageHeartRateBpm>
<Value>$averageheartrate</Value>
</AverageHeartRateBpm>
#end
#if($maximumheartrate)
<MaximumHeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<MaximumHeartRateBpm>
<Value>$maximumheartrate</Value>
</MaximumHeartRateBpm>
#end
<Intensity>Active</Intensity>
#if($averagecadence)
<Cadence>$averagecadence</Cadence>
#end
#if(!$iscourses)
<TriggerMethod>Manual</TriggerMethod>
#end
#if(!$iscourses)
#foreach( $track in $tracks )
<Track>
#set ($points = $track.getWaypoints())
#foreach ($point in $points)
<Trackpoint>
#if($point.getDate())
<Time>$dateformat.format($point.getDate())</Time>
<Time>$dateformat.format($point.getDate())</Time>
#end
<Position>
<LatitudeDegrees>$nf8.format($point.Latitude)</LatitudeDegrees>
Expand All @@ -50,32 +56,69 @@
<DistanceMeters>$nf3.format($point.Distance)</DistanceMeters>
#end
#if($point.hasValidHeartrate())
<HeartRateBpm xsi:type="HeartRateInBeatsPerMinute_t">
<HeartRateBpm>
<Value>$point.Heartrate</Value>
</HeartRateBpm>
#end
#if($point.hasValidCadence())
<Cadence type="CadenceValue_t">$point.Cadence</Cadence>
<Cadence>$point.Cadence</Cadence>
#end
#if($point.hasValidPower() || $point.hasValidSpeed())
<Extensions>
<TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2">
#if($point.hasValidSpeed())
<Speed>$point.getSpeed()</Speed>
#end
#if($point.hasValidPower())
<Watts>$point.getPower()</Watts>
#end
</TPX>
</Extensions>
#end
</Trackpoint>
#end
</Track>
#end
</Lap>
#else
</Lap>
#foreach( $track in $tracks )
<Track>
#set ($points = $track.getWaypoints())
#foreach ($point in $points)
<Trackpoint>
#if($point.getDate())
<Time>$dateformat.format($point.getDate())</Time>
#end
<Position>
<LatitudeDegrees>$nf8.format($point.Latitude)</LatitudeDegrees>
<LongitudeDegrees>$nf8.format($point.Longitude)</LongitudeDegrees>
</Position>
#if($point.hasValidAltitude())
<AltitudeMeters>$nf3.format($point.Altitude)</AltitudeMeters>
#end
#if($point.hasValidDistance())
<DistanceMeters>$nf3.format($point.Distance)</DistanceMeters>
#end
</Trackpoint>
#end
</Track>
#end
#end
#if ($lap.hasNotes())
<Notes><![CDATA[$!lap.Notes]]></Notes>
#end
<Creator xsi:type="Device_t">
<Name>$creator</Name>
<UnitId>0</UnitId>
<ProductID>0</ProductID>
<Version>
<VersionMajor>$pluginMajorVersion</VersionMajor>
<VersionMinor>$pluginMinorVersion</VersionMinor>
<BuildMajor>$pluginMicroVersion</BuildMajor>
<BuildMinor>$pluginQualifierVersion</BuildMinor>
</Version>
</Creator>
<Creator xsi:type="Device_t">
<Name>$creator</Name>
<UnitId>0</UnitId>
<ProductID>0</ProductID>
<Version>
<VersionMajor>$pluginMajorVersion</VersionMajor>
<VersionMinor>$pluginMinorVersion</VersionMinor>
<BuildMajor>$pluginMicroVersion</BuildMajor>
<BuildMinor>$pluginQualifierVersion</BuildMinor>
</Version>
</Creator>
#if($iscourses)
</Course>
</Courses>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2005, 2015 Wolfgang Schramm and Contributors
* Copyright (C) 2005, 2021 Wolfgang Schramm and Contributors
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
Expand All @@ -20,72 +20,78 @@

public class GarminTrackpointAdapterExtended extends GarminTrackpointAdapter {

private double _temperature = Double.NaN;
private long gear;

public GarminTrackpointAdapterExtended(final GarminTrackpoint trackpoint) {
super(trackpoint);
}

public long getGear() {
return gear;
}

/**
* @return Returns temperature or {@link Double#NaN} when temperature is not set
*/
public double getTemperature() {
return _temperature;
}

public boolean hasValidExtention() {

if (hasValidTemperature()) {
return true;
}

if (hasValidHeartrate()) {
return true;
}

if (hasValidCadence()) {
return true;
}

if (hasValidDistance()) {
return true;
}

if (hasValidGear()) {
return true;
}

return false;
}

/**
* @return Returns <code>true</code> when valid gear is available.
*/
public boolean hasValidGear() {
return (gear != 0);
}

/**
* Returns <code>true</code> if the temperature of this waypoint is valid. This is equal to the
* expression <code>!Double.isNaN(getTemperature())</code>.
*
* @return Returns <code>true</code> if waypoint has valid temperature.
*/
public boolean hasValidTemperature() {
return (!Double.isNaN(_temperature));
}

public void setGear(final long gear) {
this.gear = gear;
}

public void setTemperature(final double temperature) {
_temperature = temperature;
}
private double _speed = Double.NaN;
private double _temperature = Double.NaN;
private short _power = Short.MIN_VALUE;
private long _gear;

public GarminTrackpointAdapterExtended(final GarminTrackpoint trackpoint) {
super(trackpoint);
}

public long getGear() {
return _gear;
}

public short getPower() {
return _power;
}

public double getSpeed() {
return _speed;
}

/**
* @return Returns temperature or {@link Double#NaN} when temperature is not set
*/
public double getTemperature() {
return _temperature;
}

public boolean hasValidExtension() {

return hasValidTemperature() || hasValidHeartrate() || hasValidCadence() || hasValidDistance() || hasValidGear();
}

/**
* @return Returns <code>true</code> when valid gear is available.
*/
public boolean hasValidGear() {
return _gear != 0;
}

public boolean hasValidPower() {
return Short.MIN_VALUE != _power;
}

public boolean hasValidSpeed() {
return !Double.isNaN(_speed);
}

/**
* Returns <code>true</code> if the temperature of this waypoint is valid. This is equal to the
* expression <code>!Double.isNaN(getTemperature())</code>.
*
* @return Returns <code>true</code> if waypoint has valid temperature.
*/
public boolean hasValidTemperature() {
return !Double.isNaN(_temperature);
}

public void setGear(final long gear) {
_gear = gear;
}

public void setPower(final short power) {
_power = power;
}

public void setSpeed(final double speed) {
_speed = speed;
}

public void setTemperature(final double temperature) {
_temperature = temperature;
}

}

0 comments on commit 62a8c67

Please sign in to comment.