mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-09 07:46:37 +02:00
Garmin: Fetch activity on demand
This commit is contained in:
parent
0d230ce0a5
commit
5c57392b85
@ -42,6 +42,11 @@ public abstract class GarminCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
return deviceSpecificSettings;
|
return deviceSpecificSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsActivityDataFetching() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsFindDevice() {
|
public boolean supportsFindDevice() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -23,6 +23,7 @@ import java.util.Timer;
|
|||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||||
@ -55,6 +56,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SetD
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SupportedFileTypesMessage;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SupportedFileTypesMessage;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SystemEventMessage;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SystemEventMessage;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
@ -68,7 +70,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
|
|||||||
private ICommunicator communicator;
|
private ICommunicator communicator;
|
||||||
private MusicStateSpec musicStateSpec;
|
private MusicStateSpec musicStateSpec;
|
||||||
private Timer musicStateTimer;
|
private Timer musicStateTimer;
|
||||||
private List<FileType> supportedFileTypeList;
|
private final List<FileType> supportedFileTypeList = new ArrayList<>();
|
||||||
|
|
||||||
public GarminSupport() {
|
public GarminSupport() {
|
||||||
super(LOG);
|
super(LOG);
|
||||||
@ -218,13 +220,25 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
|
|||||||
notificationsHandler.setEnabled(enable);
|
notificationsHandler.setEnabled(enable);
|
||||||
LOG.info("NOTIFICATIONS ARE NOW {}", enable ? "ON" : "OFF");
|
LOG.info("NOTIFICATIONS ARE NOW {}", enable ? "ON" : "OFF");
|
||||||
} else if (deviceEvent instanceof SupportedFileTypesDeviceEvent) {
|
} else if (deviceEvent instanceof SupportedFileTypesDeviceEvent) {
|
||||||
this.supportedFileTypeList = ((SupportedFileTypesDeviceEvent) deviceEvent).getSupportedFileTypes();
|
this.supportedFileTypeList.clear();
|
||||||
sendOutgoingMessage(fileTransferHandler.initiateDownload());
|
this.supportedFileTypeList.addAll(((SupportedFileTypesDeviceEvent) deviceEvent).getSupportedFileTypes());
|
||||||
}
|
}
|
||||||
|
|
||||||
super.evaluateGBDeviceEvent(deviceEvent);
|
super.evaluateGBDeviceEvent(deviceEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFetchRecordedData(final int dataTypes) {
|
||||||
|
if (this.supportedFileTypeList.isEmpty()) {
|
||||||
|
LOG.warn("No known supported file types");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME respect dataTypes?
|
||||||
|
|
||||||
|
sendOutgoingMessage(fileTransferHandler.initiateDownload());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNotification(NotificationSpec notificationSpec) {
|
public void onNotification(NotificationSpec notificationSpec) {
|
||||||
sendOutgoingMessage(notificationsHandler.onNotification(notificationSpec));
|
sendOutgoingMessage(notificationsHandler.onNotification(notificationSpec));
|
||||||
@ -346,6 +360,12 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
|
|||||||
|
|
||||||
private void processDownloadQueue() {
|
private void processDownloadQueue() {
|
||||||
if (!filesToDownload.isEmpty() && !fileTransferHandler.isDownloading()) {
|
if (!filesToDownload.isEmpty() && !fileTransferHandler.isDownloading()) {
|
||||||
|
if (!gbDevice.isBusy()) {
|
||||||
|
GB.updateTransferNotification(getContext().getString(R.string.busy_task_fetch_activity_data), "", true, 0, getContext());
|
||||||
|
getDevice().setBusyTask(getContext().getString(R.string.busy_task_fetch_activity_data));
|
||||||
|
getDevice().sendDeviceUpdateIntent(getContext());
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileTransferHandler.DirectoryEntry directoryEntry = filesToDownload.remove();
|
FileTransferHandler.DirectoryEntry directoryEntry = filesToDownload.remove();
|
||||||
while (checkFileExists(directoryEntry.getFileName())) {
|
while (checkFileExists(directoryEntry.getFileName())) {
|
||||||
@ -359,7 +379,19 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
|
|||||||
LOG.debug("File: {} already downloaded, not downloading again, from inside.", directoryEntry.getFileName());
|
LOG.debug("File: {} already downloaded, not downloading again, from inside.", directoryEntry.getFileName());
|
||||||
}
|
}
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
//ignore
|
// we ran out of files to download
|
||||||
|
// FIXME this is ugly
|
||||||
|
if (gbDevice.isBusy() && gbDevice.getBusyTask().equals(getContext().getString(R.string.busy_task_fetch_activity_data))) {
|
||||||
|
getDevice().unsetBusyTask();
|
||||||
|
GB.updateTransferNotification(null, "", false, 100, getContext());
|
||||||
|
getDevice().sendDeviceUpdateIntent(getContext());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (filesToDownload.isEmpty() && !fileTransferHandler.isDownloading()) {
|
||||||
|
if (gbDevice.isBusy() && gbDevice.getBusyTask().equals(getContext().getString(R.string.busy_task_fetch_activity_data))) {
|
||||||
|
getDevice().unsetBusyTask();
|
||||||
|
GB.updateTransferNotification(null, "", false, 100, getContext());
|
||||||
|
getDevice().sendDeviceUpdateIntent(getContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user