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

Suunto App Integration #299

Merged
merged 18 commits into from
Feb 6, 2021
3 changes: 3 additions & 0 deletions bundles/net.tourbook.cloud/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ Import-Package: com.fasterxml.jackson.core,
net.tourbook,
net.tourbook.application,
net.tourbook.data,
net.tourbook.database,
net.tourbook.export,
net.tourbook.ext.velocity,
net.tourbook.extension.download,
net.tourbook.extension.upload,
net.tourbook.importdata,
net.tourbook.tour,
net.tourbook.web,
org.apache.commons.io,
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 49 additions & 3 deletions bundles/net.tourbook.cloud/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,88 @@
<?eclipse version="4.14"?>
<plugin>

<!-- FILE SYSTEMS -->

<extension point="net.tourbook.fileSystem">
<fileSystem
id ="net.tourbook.cloud.DropboxFileSystem"
name ="Dropbox File System"
class ="net.tourbook.cloud.dropbox.DropboxFileSystem"
/>
</extension>

<!-- FILE SYSTEMS -->



<!-- CLOUD FILES DOWNLOADERS -->

<!-- Suunto -->
<extension point="net.tourbook.cloudDownloader">
<cloudDownloader
id ="net.tourbook.cloud.SuuntoCloudDownloader"
name ="Suunto Files Downloader"
class ="net.tourbook.cloud.suunto.SuuntoCloudDownloader"
/>
</extension>

<!-- CLOUD FILES DOWNLOADERS -->



<!-- CLOUD UPLOADERS -->

<extension point="net.tourbook.cloudUploader">
<cloudUploader
id ="net.tourbook.cloud.StravaUploader"
name ="Strava Uploader"
class ="net.tourbook.cloud.strava.StravaUploader"
/>
</extension>

<extension point="net.tourbook.cloudUploader">
<cloudUploader
id ="net.tourbook.cloud.SuuntoRoutesUploader"
name ="Suunto Routes Uploader"
class ="net.tourbook.cloud.suunto.SuuntoRoutesUploader"
/>
</extension>

<!-- CLOUD UPLOADERS -->



<!-- Dropbox -->
<extension point="org.eclipse.ui.preferencePages">
<page
category="net.tourbook.preferences.PrefPageCloudConnectivity"
category="net.tourbook.preferences.PrefPageCloud"
class="net.tourbook.cloud.dropbox.PrefPageDropbox"
id="net.tourbook.cloud.PrefPageDropbox"
name="Dropbox">
</page>
</extension>


<!-- Strava -->
<extension point="org.eclipse.ui.preferencePages">
<page
category="net.tourbook.preferences.PrefPageCloudConnectivity"
category="net.tourbook.preferences.PrefPageCloud"
class="net.tourbook.cloud.strava.PrefPageStrava"
id="net.tourbook.strava.PrefPageStrava"
id="net.tourbook.cloud.PrefPageStrava"
name="Strava">
</page>
</extension>

<!-- Suunto -->
<extension point="org.eclipse.ui.preferencePages">
<page
category="net.tourbook.preferences.PrefPageCloud"
class="net.tourbook.cloud.suunto.PrefPageSuunto"
id="net.tourbook.cloud.PrefPageSuunto"
name="Suunto">
</page>
</extension>

<extension point="org.eclipse.core.runtime.preferences">

<initializer
Expand Down
24 changes: 23 additions & 1 deletion bundles/net.tourbook.cloud/src/net/tourbook/cloud/Activator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2020 Frédéric Bard
* Copyright (C) 2020, 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
Expand All @@ -15,8 +15,14 @@
*******************************************************************************/
package net.tourbook.cloud;

import java.io.IOException;
import java.net.URL;
import java.util.Optional;

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

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ResourceLocator;
import org.eclipse.ui.plugin.AbstractUIPlugin;
Expand Down Expand Up @@ -49,6 +55,19 @@ public static Activator getDefault() {
return plugin;
}

public static String getImageAbsoluteFilePath(final String fileName) {

final Optional<URL> imageURL = ResourceLocator.locate(PLUGIN_ID, "icons/" + fileName); //$NON-NLS-1$

try {
return imageURL.isPresent() ? FileLocator.toFileURL(imageURL.get()).toString() : UI.EMPTY_STRING;
} catch (final IOException e) {
StatusUtil.log(e);
}

return UI.EMPTY_STRING;
}

/**
* Returns an image descriptor for images in the plug-in path.
*
Expand All @@ -57,19 +76,22 @@ public static Activator getDefault() {
* @return the axisImage descriptor
*/
public static ImageDescriptor getImageDescriptor(final String path) {

final Optional<ImageDescriptor> imageDescriptor = ResourceLocator.imageDescriptorFromBundle(PLUGIN_ID, "icons/" + path); //$NON-NLS-1$

return imageDescriptor.isPresent() ? imageDescriptor.get() : null;
}

@Override
public void start(final BundleContext context) throws Exception {

super.start(context);
plugin = this;
}

@Override
public void stop(final BundleContext context) throws Exception {

plugin = null;
super.stop(context);
}
Expand Down
13 changes: 12 additions & 1 deletion bundles/net.tourbook.cloud/src/net/tourbook/cloud/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,20 @@ public class Messages extends NLS {

public static String Html_CloseBrowser_Text;

public static String Log_CloudAction_End;
public static String Log_CloudAction_InvalidTokens;

public static String Pref_CloudConnectivity_AccessToken_Label;
public static String Pref_CloudConnectivity_Authorize_Button;
public static String Pref_CloudConnectivity_CloudAccount_Group;
public static String Pref_CloudConnectivity_ExpiresAt_Label;
public static String Pref_CloudConnectivity_RefreshToken_Label;
public static String Pref_CloudConnectivity_UnavailablePort_Message;
public static String Pref_CloudConnectivity_UnavailablePort_Title;
public static String Pref_CloudConnectivity_CloudAccount_Group;
public static String Pref_CloudConnectivity_WebPage_Label;

public static String Icon_Check;
public static String Icon_Hourglass;

static {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2020 Frédéric Bard
* Copyright (C) 2020, 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
Expand Down Expand Up @@ -39,5 +39,16 @@ public void initializeDefaultPreferences() {
store.setDefault(Preferences.STRAVA_ACCESSTOKEN_EXPIRES_AT, 0);
store.setDefault(Preferences.STRAVA_ATHLETEID, UI.EMPTY_STRING);
store.setDefault(Preferences.STRAVA_ATHLETEFULLNAME, UI.EMPTY_STRING);

store.setDefault(Preferences.SUUNTO_ACCESSTOKEN, UI.EMPTY_STRING);
store.setDefault(Preferences.SUUNTO_REFRESHTOKEN, UI.EMPTY_STRING);
store.setDefault(Preferences.SUUNTO_ACCESSTOKEN_EXPIRES_IN, 0);
store.setDefault(Preferences.SUUNTO_ACCESSTOKEN_ISSUE_DATETIME, 0);
store.setDefault(Preferences.SUUNTO_WORKOUT_DOWNLOAD_FOLDER, UI.EMPTY_STRING);
store.setDefault(Preferences.SUUNTO_USE_WORKOUT_FILTER_SINCE_DATE, false);

//This is the date (01/26/2021) that Suunto forced the users to switch to Suunto App.
store.setDefault(Preferences.SUUNTO_WORKOUT_FILTER_SINCE_DATE, 1611619200000L);

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2020 Frédéric Bard
* Copyright (C) 2020, 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
Expand Down Expand Up @@ -33,4 +33,15 @@ public final class Preferences {
public static final String STRAVA_ACCESSTOKEN_EXPIRES_AT = "STRAVA_ACCESSTOKEN_EXPIRES_AT"; //$NON-NLS-1$
public static final String STRAVA_ATHLETEID = "STRAVA_ATHLETEID"; //$NON-NLS-1$
public static final String STRAVA_ATHLETEFULLNAME = "STRAVA_ATHLETEFULLNAME"; //$NON-NLS-1$

/*
* Suunto preferences
*/
public static final String SUUNTO_ACCESSTOKEN = "SUUNTO_ACCESSTOKEN"; //$NON-NLS-1$
public static final String SUUNTO_REFRESHTOKEN = "SUUNTO_REFRESHTOKEN"; //$NON-NLS-1$
public static final String SUUNTO_ACCESSTOKEN_EXPIRES_IN = "SUUNTO_ACCESSTOKEN_EXPIRES_IN"; //$NON-NLS-1$
public static final String SUUNTO_ACCESSTOKEN_ISSUE_DATETIME = "SUUNTO_ACCESSTOKEN_ISSUE_DATETIME"; //$NON-NLS-1$
public static final String SUUNTO_WORKOUT_DOWNLOAD_FOLDER = "SUUNTO_DOWNLOAD_FOLDER"; //$NON-NLS-1$
public static final String SUUNTO_USE_WORKOUT_FILTER_SINCE_DATE = "SUUNTO_USE_WORKOUT_FILTER_SINCE_DATE"; //$NON-NLS-1$
public static final String SUUNTO_WORKOUT_FILTER_SINCE_DATE = "SUUNTO_WORKOUT_FILTER_SINCE_DATE"; //$NON-NLS-1$
}
46 changes: 46 additions & 0 deletions bundles/net.tourbook.cloud/src/net/tourbook/cloud/TourUpload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* 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.cloud;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class TourUpload {

@JsonProperty("error")
private String _error;
@JsonProperty("tourDate")
private String _tourDate;

public TourUpload() {}

public String getError() {
return _error;
}

public String getTourDate() {
return _tourDate;
}

public void setError(final String error) {
_error = error;
}

public void setTourDate(final String tourDate) {
_tourDate = tourDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public static final String getValidTokens() {
final DropboxTokens newTokens = getTokens(UI.EMPTY_STRING, true, _prefStore.getString(Preferences.DROPBOX_REFRESHTOKEN), UI.EMPTY_STRING);

if (StringUtils.hasContent(newTokens.getAccess_token())) {

_prefStore.setValue(Preferences.DROPBOX_ACCESSTOKEN_EXPIRES_IN, newTokens.getExpires_in());
_prefStore.setValue(Preferences.DROPBOX_ACCESSTOKEN_ISSUE_DATETIME, System.currentTimeMillis());
_prefStore.setValue(Preferences.DROPBOX_ACCESSTOKEN, newTokens.getAccess_token());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,21 @@ protected void close() {
*/
public void closeDropboxFileSystem() {

if (_dropboxFileSystem != null) {
try {
_dropboxFileSystem.close();
_dropboxFileSystem = null;
} catch (final IOException e) {
StatusUtil.log(e);
}
if (_dropboxFileSystem == null) {
return;
}

try {
_dropboxFileSystem.close();
_dropboxFileSystem = null;
} catch (final IOException e) {
StatusUtil.log(e);
}
}

@Override
protected File copyFileLocally(final String dropboxFilePath) {

final Path localFilePath = DropboxClient.CopyLocally(dropboxFilePath);

return localFilePath != null ? localFilePath.toFile() : null;
Expand Down Expand Up @@ -142,12 +145,9 @@ public boolean createDropboxFileSystem() {
*/
@Override
public Iterable<FileStore> getFileStore() {
if (_dropboxFileSystem != null) {

if (_dropboxFileSystem != null || createDropboxFileSystem()) {
return _dropboxFileSystem.getFileStores();
} else {
if (createDropboxFileSystem()) {
return _dropboxFileSystem.getFileStores();
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public DropboxTokensRetrievalHandler(final String codeVerifier) {

@Override
public Tokens retrieveTokens(final String authorizationCode) {
final DropboxTokens newTokens = new DropboxTokens();

if (StringUtils.isNullOrEmpty(authorizationCode)) {
return newTokens;
return new DropboxTokens();
}

return DropboxClient.getTokens(authorizationCode, false, UI.EMPTY_STRING, _codeVerifier);
Expand All @@ -47,7 +47,7 @@ public Tokens retrieveTokens(final String authorizationCode) {
@Override
public void saveTokensInPreferences(final Tokens tokens) {

if (!(tokens instanceof DropboxTokens) || !StringUtils.hasContent(tokens.getAccess_token())) {
if (!(tokens instanceof DropboxTokens) || StringUtils.isNullOrEmpty(tokens.getAccess_token())) {

final String currentAccessToken = _prefStore.getString(Preferences.DROPBOX_ACCESSTOKEN);
_prefStore.firePropertyChangeEvent(Preferences.DROPBOX_ACCESSTOKEN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ public class Messages extends NLS {
public static String Image__Dropbox_Folder;
public static String Image__Dropbox_Parentfolder;
FJBDev marked this conversation as resolved.
Show resolved Hide resolved

public static String Pref_CloudConnectivity_Dropbox_AccessToken_Label;
public static String Pref_CloudConnectivity_Dropbox_AccessToken_Tooltip;
public static String Pref_CloudConnectivity_Dropbox_Button_Authorize;
public static String Pref_CloudConnectivity_Dropbox_RefreshToken_Label;
public static String Pref_CloudConnectivity_Dropbox_ExpiresAt_Label;
public static String Pref_CloudConnectivity_Dropbox_WebPage_Label;
public static String Pref_CloudConnectivity_Dropbox_WebPage_Link;

static {
Expand Down