Skip to content

Commit

Permalink
New features and unit tests enhancements (#289)
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

* TCX Export Enhancement and fixes (#287)

* 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

* Missed commiting that file

* Adding the possibility to configure a User Agent for each map provider (#42)

* Added the possibility to export the current map view to an image file (jpg, png or bmp)

* Activating the FitLog and FitLogEx unit tests (#45)

* Renaming the action text and adding a tooltip

* Improvements after more testing

* Adding the action to export the map view in the clipboard

* No image

* 2 in 1

* Adding source

* French translation

* Indentation

* Code improvement

* Revert

* Fixed a bug where the authentication would not work if the browser's
response was too long (in french for example). Fixed the browser's
response for languages with accents

* Using the Http Constant

* Using the Http Constant

* Code improvements

* putting the export actions into a submenu action

* Found code to polish when I inspired myself for the export map submenu

* Adding tooltip for the searchtourbylocation
  • Loading branch information
FJBDev committed Jan 20, 2021
1 parent fa95e70 commit ed2b014
Show file tree
Hide file tree
Showing 54 changed files with 24,683 additions and 19,948 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,22 +230,19 @@ public void update(final ViewerCell cell) {

final Metadata entry = ((Metadata) cell.getElement());

String entryName = null;
Image entryImage = null;

entryName = entry.getName();
String imageName = UI.EMPTY_STRING;

if (entry instanceof FolderMetadata) {

entryImage =
Activator.getImageDescriptor(Messages.Image__Dropbox_Folder).createImage();
imageName = Messages.Image__Dropbox_Folder;
} else if (entry instanceof FileMetadata) {

entryImage =
Activator.getImageDescriptor(Messages.Image__Dropbox_File).createImage();
imageName = Messages.Image__Dropbox_File;
}

cell.setText(entryName);
final Image entryImage = StringUtils.hasContent(imageName) ? Activator.getImageDescriptor(imageName).createImage() : null;

cell.setText(entry.getName());
cell.setImage(entryImage);
}
});
Expand Down
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 @@ -20,14 +20,14 @@

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Optional;

import net.tourbook.cloud.Messages;
import net.tourbook.common.UI;
import net.tourbook.common.util.StatusUtil;

import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
Expand Down Expand Up @@ -71,17 +71,20 @@ private Tokens handleGetRequest(final HttpExchange httpExchange) {

private void handleResponse(final HttpExchange httpExchange) throws IOException {

final OutputStream outputStream = httpExchange.getResponseBody();

final StringBuilder htmlBuilder = new StringBuilder();
htmlBuilder.append("<html><body><h1>" + Messages.Html_CloseBrowser_Text + "</h1></body></html>"); //$NON-NLS-1$ //$NON-NLS-2$
htmlBuilder.append("<html><head><meta charset=\"UTF-8\"></head><body><h1>" + Messages.Html_CloseBrowser_Text + "</h1></body></html>"); //$NON-NLS-1$ //$NON-NLS-2$

final byte[] response = htmlBuilder.toString().getBytes(StandardCharsets.UTF_8);

// this line is a must
httpExchange.sendResponseHeaders(200, htmlBuilder.length());
httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.length);

try (OutputStream outputStream = httpExchange.getResponseBody()) {

try (Writer writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) {
writer.write(htmlBuilder.toString());
outputStream.write(response);
outputStream.flush();
} catch (final Exception e) {
StatusUtil.log(e);
}
}

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
Expand Up @@ -146,9 +146,7 @@ public static StravaTokens getTokens(final String authorizationCode, final boole
if (isRefreshToken) {
body.append("{\"" + OAuth2Constants.PARAM_REFRESH_TOKEN + "\" : \"" + refreshToken); //$NON-NLS-1$ //$NON-NLS-2$
grantType = OAuth2Constants.PARAM_REFRESH_TOKEN;
} else

{
} else {
body.append("{\"" + OAuth2Constants.PARAM_CODE + "\" : \"" + authorizationCode);//$NON-NLS-1$ //$NON-NLS-2$
grantType = OAuth2Constants.PARAM_AUTHORIZATION_CODE;
}
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

0 comments on commit ed2b014

Please sign in to comment.