1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-05 17:57:03 +01:00

Garmin: fix for watch staying in synchronizing state on first connection

Reported in issue 3269, https://codeberg.org/Freeyourgadget/Gadgetbridge/issues/3269#issuecomment-1845355

Also run refactor code on the whole file
This commit is contained in:
Daniele Gobbetti 2024-05-28 12:29:31 +02:00
parent e5d41e75ad
commit 537b0580b5

View File

@ -81,6 +81,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.Optional; import nodomain.freeyourgadget.gadgetbridge.util.Optional;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_ALLOW_HIGH_MTU; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_ALLOW_HIGH_MTU;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_GARMIN_DEFAULT_REPLY_SUFFIX; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_GARMIN_DEFAULT_REPLY_SUFFIX;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS;
@ -93,12 +94,13 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
private final FileTransferHandler fileTransferHandler; private final FileTransferHandler fileTransferHandler;
private final Queue<FileTransferHandler.DirectoryEntry> filesToDownload; private final Queue<FileTransferHandler.DirectoryEntry> filesToDownload;
private final List<MessageHandler> messageHandlers; private final List<MessageHandler> messageHandlers;
private final List<FileType> supportedFileTypeList = new ArrayList<>();
private final List<File> filesToProcess = new ArrayList<>();
private ICommunicator communicator; private ICommunicator communicator;
private MusicStateSpec musicStateSpec; private MusicStateSpec musicStateSpec;
private Timer musicStateTimer; private Timer musicStateTimer;
private boolean mFirstConnect = false;
private final List<FileType> supportedFileTypeList = new ArrayList<>(); private boolean isBusyFetching;
private final List<File> filesToProcess = new ArrayList<>();
public GarminSupport() { public GarminSupport() {
super(LOG); super(LOG);
@ -235,7 +237,6 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
} }
@Override @Override
public void onSetCallState(CallSpec callSpec) { public void onSetCallState(CallSpec callSpec) {
LOG.info("INCOMING CALLSPEC: {}", callSpec.command); LOG.info("INCOMING CALLSPEC: {}", callSpec.command);
@ -314,7 +315,6 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
sendOutgoingMessage("delete notification " + id, notificationsHandler.onDeleteNotification(id)); sendOutgoingMessage("delete notification " + id, notificationsHandler.onDeleteNotification(id));
} }
@Override @Override
public void onSendWeather(final ArrayList<WeatherSpec> weatherSpecs) { //todo: find the closest one relative to the requested lat/long public void onSendWeather(final ArrayList<WeatherSpec> weatherSpecs) { //todo: find the closest one relative to the requested lat/long
sendWeatherConditions(weatherSpecs.get(0)); sendWeatherConditions(weatherSpecs.get(0));
@ -444,6 +444,11 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
sendOutgoingMessage("request supported file types", new SupportedFileTypesMessage()); sendOutgoingMessage("request supported file types", new SupportedFileTypesMessage());
sendOutgoingMessage("toggle default reply suffix", toggleDefaultReplySuffix(getDevicePrefs().getBoolean(PREF_GARMIN_DEFAULT_REPLY_SUFFIX, true))); sendOutgoingMessage("toggle default reply suffix", toggleDefaultReplySuffix(getDevicePrefs().getBoolean(PREF_GARMIN_DEFAULT_REPLY_SUFFIX, true)));
if (mFirstConnect) {
sendOutgoingMessage("set sync complete", new SystemEventMessage(SystemEventMessage.GarminSystemEventType.SYNC_COMPLETE, 0));
this.mFirstConnect = false;
}
} }
private ProtobufMessage toggleDefaultReplySuffix(boolean value) { private ProtobufMessage toggleDefaultReplySuffix(boolean value) {
@ -473,8 +478,6 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
} }
} }
private boolean isBusyFetching;
private void processDownloadQueue() { private void processDownloadQueue() {
if (!filesToDownload.isEmpty() && !fileTransferHandler.isDownloading()) { if (!filesToDownload.isEmpty() && !fileTransferHandler.isDownloading()) {
if (!gbDevice.isBusy()) { if (!gbDevice.isBusy()) {
@ -517,7 +520,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
// Keep the device marked as busy while we process the files asynchronously // Keep the device marked as busy while we process the files asynchronously
final FitAsyncProcessor fitAsyncProcessor = new FitAsyncProcessor(getContext(), getDevice()); final FitAsyncProcessor fitAsyncProcessor = new FitAsyncProcessor(getContext(), getDevice());
final List <File> filesToProcessClone = new ArrayList<>(filesToProcess); final List<File> filesToProcessClone = new ArrayList<>(filesToProcess);
filesToProcess.clear(); filesToProcess.clear();
final long[] lastNotificationUpdateTs = new long[]{System.currentTimeMillis()}; final long[] lastNotificationUpdateTs = new long[]{System.currentTimeMillis()};
fitAsyncProcessor.process(filesToProcessClone, new FitAsyncProcessor.Callback() { fitAsyncProcessor.process(filesToProcessClone, new FitAsyncProcessor.Callback() {
@ -735,6 +738,12 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
return (GarminCoordinator) getDevice().getDeviceCoordinator(); return (GarminCoordinator) getDevice().getDeviceCoordinator();
} }
@Override
public boolean connectFirstTime() {
mFirstConnect = true;
return super.connect();
}
@Override @Override
public void onTestNewFunction() { public void onTestNewFunction() {
parseAllFitFilesFromStorage(); parseAllFitFilesFromStorage();