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;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.documentfile.provider.DocumentFile;
|
||||
|
||||
@@ -30,21 +47,41 @@ import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
||||
public class AutoGpxExporter {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AutoGpxExporter.class);
|
||||
|
||||
public static void doExport(final Context context,
|
||||
final GBDevice gbDevice,
|
||||
@Nullable final BaseActivitySummary summary,
|
||||
final ActivityTrack activityTrack) {
|
||||
public static boolean isExportEnabled(@NonNull final GBDevice gbDevice) {
|
||||
return getExportDirectory(gbDevice) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getExportDirectory(@NonNull final GBDevice gbDevice) {
|
||||
final GBPrefs prefs = GBApplication.getPrefs();
|
||||
final boolean enabled = prefs.getBoolean(GBPrefs.AUTO_EXPORT_GPX_ENABLED, false);
|
||||
if (!enabled) {
|
||||
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 boolean allDevices = prefs.getBoolean(GBPrefs.AUTO_EXPORT_GPX_ALL_DEVICES, true);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -55,12 +92,6 @@ public class AutoGpxExporter {
|
||||
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;
|
||||
if (summary != null) {
|
||||
trackType = context.getString(ActivityKind.fromCode(summary.getActivityKind()).getLabel()).toLowerCase(Locale.ROOT);
|
||||
|
||||
+6
-4
@@ -701,10 +701,12 @@ public class FitImporter {
|
||||
}
|
||||
|
||||
// Export to gpx
|
||||
final FitActivityTrackProvider activityTrackProvider = new FitActivityTrackProvider();
|
||||
final ActivityTrack activityTrack = activityTrackProvider.getActivityTrack(summary);
|
||||
if (activityTrack != null) {
|
||||
AutoGpxExporter.doExport(context, gbDevice, summary, activityTrack);
|
||||
if (AutoGpxExporter.isExportEnabled(gbDevice)) {
|
||||
final FitActivityTrackProvider activityTrackProvider = new FitActivityTrackProvider();
|
||||
final ActivityTrack activityTrack = activityTrackProvider.getActivityTrack(summary);
|
||||
if (activityTrack != null) {
|
||||
AutoGpxExporter.doExport(context, gbDevice, summary, activityTrack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user