mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Garmin: check if GPX export is enabled before generating the export ActivityTrack
This commit is contained in:
+43
-12
@@ -1,8 +1,25 @@
|
|||||||
|
/* Copyright (C) 2026 José Rebelo, Thomas Kuehne
|
||||||
|
|
||||||
|
This file is part of Gadgetbridge.
|
||||||
|
|
||||||
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Gadgetbridge 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 Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.export;
|
package nodomain.freeyourgadget.gadgetbridge.export;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.documentfile.provider.DocumentFile;
|
import androidx.documentfile.provider.DocumentFile;
|
||||||
|
|
||||||
@@ -30,21 +47,41 @@ import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
|||||||
public class AutoGpxExporter {
|
public class AutoGpxExporter {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AutoGpxExporter.class);
|
private static final Logger LOG = LoggerFactory.getLogger(AutoGpxExporter.class);
|
||||||
|
|
||||||
public static void doExport(final Context context,
|
public static boolean isExportEnabled(@NonNull final GBDevice gbDevice) {
|
||||||
final GBDevice gbDevice,
|
return getExportDirectory(gbDevice) != null;
|
||||||
@Nullable final BaseActivitySummary summary,
|
}
|
||||||
final ActivityTrack activityTrack) {
|
|
||||||
|
@Nullable
|
||||||
|
public static String getExportDirectory(@NonNull final GBDevice gbDevice) {
|
||||||
final GBPrefs prefs = GBApplication.getPrefs();
|
final GBPrefs prefs = GBApplication.getPrefs();
|
||||||
final boolean enabled = prefs.getBoolean(GBPrefs.AUTO_EXPORT_GPX_ENABLED, false);
|
final boolean enabled = prefs.getBoolean(GBPrefs.AUTO_EXPORT_GPX_ENABLED, false);
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
LOG.debug("Auto gpx export is disabled");
|
LOG.debug("Auto gpx export is disabled");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Set<String> selectedDevices = prefs.getStringSet(GBPrefs.AUTO_EXPORT_GPX_SELECTED_DEVICES, Collections.emptySet());
|
final Set<String> selectedDevices = prefs.getStringSet(GBPrefs.AUTO_EXPORT_GPX_SELECTED_DEVICES, Collections.emptySet());
|
||||||
final boolean allDevices = prefs.getBoolean(GBPrefs.AUTO_EXPORT_GPX_ALL_DEVICES, true);
|
final boolean allDevices = prefs.getBoolean(GBPrefs.AUTO_EXPORT_GPX_ALL_DEVICES, true);
|
||||||
if (!allDevices && !selectedDevices.contains(gbDevice.getAddress())) {
|
if (!allDevices && !selectedDevices.contains(gbDevice.getAddress())) {
|
||||||
LOG.debug("Skipping auto gpx export - not enabled for {}", gbDevice);
|
LOG.debug("Auto gpx export is not enabled for {}", gbDevice);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String directory = prefs.getString(GBPrefs.AUTO_EXPORT_GPX_DIRECTORY, "");
|
||||||
|
if (directory.isBlank()) {
|
||||||
|
LOG.warn("No auto gpx export directory specified");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void doExport(final Context context,
|
||||||
|
final GBDevice gbDevice,
|
||||||
|
@Nullable final BaseActivitySummary summary,
|
||||||
|
final ActivityTrack activityTrack) {
|
||||||
|
final String directory = getExportDirectory(gbDevice);
|
||||||
|
if (directory == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,12 +92,6 @@ public class AutoGpxExporter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String directory = prefs.getString(GBPrefs.AUTO_EXPORT_GPX_DIRECTORY, "");
|
|
||||||
if (directory.isBlank()) {
|
|
||||||
LOG.warn("Not auto-exporting gpx, no directory specified");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String trackType;
|
final String trackType;
|
||||||
if (summary != null) {
|
if (summary != null) {
|
||||||
trackType = context.getString(ActivityKind.fromCode(summary.getActivityKind()).getLabel()).toLowerCase(Locale.ROOT);
|
trackType = context.getString(ActivityKind.fromCode(summary.getActivityKind()).getLabel()).toLowerCase(Locale.ROOT);
|
||||||
|
|||||||
+6
-4
@@ -701,10 +701,12 @@ public class FitImporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Export to gpx
|
// Export to gpx
|
||||||
final FitActivityTrackProvider activityTrackProvider = new FitActivityTrackProvider();
|
if (AutoGpxExporter.isExportEnabled(gbDevice)) {
|
||||||
final ActivityTrack activityTrack = activityTrackProvider.getActivityTrack(summary);
|
final FitActivityTrackProvider activityTrackProvider = new FitActivityTrackProvider();
|
||||||
if (activityTrack != null) {
|
final ActivityTrack activityTrack = activityTrackProvider.getActivityTrack(summary);
|
||||||
AutoGpxExporter.doExport(context, gbDevice, summary, activityTrack);
|
if (activityTrack != null) {
|
||||||
|
AutoGpxExporter.doExport(context, gbDevice, summary, activityTrack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user