mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 19:36:50 +01:00
Huami: Add queued fetch operations
This commit is contained in:
parent
23e9a3deb1
commit
3f87bfadd4
@ -23,6 +23,8 @@ public class RecordedDataTypes {
|
||||
public static final int TYPE_GPS_TRACKS = 0x00000004;
|
||||
public static final int TYPE_TEMPERATURE = 0x00000008;
|
||||
public static final int TYPE_DEBUGLOGS = 0x00000010;
|
||||
public static final int TYPE_SPO2 = 0x00000020;
|
||||
public static final int TYPE_STRESS = 0x00000040;
|
||||
|
||||
public static final int TYPE_ALL = (int)0xffffffff;
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.content.Context;
|
||||
@ -57,9 +56,11 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.SimpleTimeZone;
|
||||
import java.util.TimeZone;
|
||||
@ -115,9 +116,12 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.AbstractFetchOperation;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSpo2NormalOperation;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSportsSummaryOperation;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchStressAutoOperation;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchStressManualOperation;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.HuamiFetchDebugLogsOperation;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.services.ZeppOsCannedMessagesService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.calendar.CalendarEvent;
|
||||
@ -326,6 +330,8 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
protected Huami2021ChunkedEncoder huami2021ChunkedEncoder;
|
||||
protected Huami2021ChunkedDecoder huami2021ChunkedDecoder;
|
||||
|
||||
private final Queue<AbstractFetchOperation> fetchOperationQueue = new LinkedList<>();
|
||||
|
||||
public HuamiSupport() {
|
||||
this(LOG);
|
||||
}
|
||||
@ -1645,20 +1651,39 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
public void onFetchRecordedData(int dataTypes) {
|
||||
final HuamiCoordinator coordinator = getCoordinator();
|
||||
|
||||
try {
|
||||
// FIXME: currently only one data type supported, these are meant to be flags
|
||||
if (dataTypes == RecordedDataTypes.TYPE_ACTIVITY) {
|
||||
new FetchActivityOperation(this).perform();
|
||||
} else if (dataTypes == RecordedDataTypes.TYPE_GPS_TRACKS && coordinator.supportsActivityTracks()) {
|
||||
new FetchSportsSummaryOperation(this, 1).perform();
|
||||
} else if (dataTypes == RecordedDataTypes.TYPE_DEBUGLOGS && coordinator.supportsDebugLogs()) {
|
||||
new HuamiFetchDebugLogsOperation(this).perform();
|
||||
} else {
|
||||
LOG.warn("fetching multiple data types at once is not supported yet");
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
LOG.error("Unable to fetch recorded data types" + dataTypes, ex);
|
||||
if ((dataTypes & RecordedDataTypes.TYPE_ACTIVITY) != 0) {
|
||||
this.fetchOperationQueue.add(new FetchActivityOperation(this));
|
||||
}
|
||||
|
||||
if ((dataTypes & RecordedDataTypes.TYPE_GPS_TRACKS) != 0 && coordinator.supportsActivityTracks()) {
|
||||
this.fetchOperationQueue.add(new FetchSportsSummaryOperation(this, 1));
|
||||
}
|
||||
|
||||
if ((dataTypes & RecordedDataTypes.TYPE_DEBUGLOGS) != 0 && coordinator.supportsDebugLogs()) {
|
||||
this.fetchOperationQueue.add(new HuamiFetchDebugLogsOperation(this));
|
||||
}
|
||||
|
||||
if ((dataTypes & RecordedDataTypes.TYPE_SPO2) != 0 && coordinator.supportsSpo2()) {
|
||||
this.fetchOperationQueue.add(new FetchSpo2NormalOperation(this));
|
||||
}
|
||||
|
||||
if ((dataTypes & RecordedDataTypes.TYPE_STRESS) != 0 && coordinator.supportsStressMeasurement()) {
|
||||
this.fetchOperationQueue.add(new FetchStressAutoOperation(this));
|
||||
this.fetchOperationQueue.add(new FetchStressManualOperation(this));
|
||||
}
|
||||
|
||||
final AbstractFetchOperation nextOperation = this.fetchOperationQueue.poll();
|
||||
if (nextOperation != null) {
|
||||
try {
|
||||
nextOperation.perform();
|
||||
} catch (final IOException e) {
|
||||
LOG.error("Unable to fetch recorded data", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AbstractFetchOperation getNextFetchOperation() {
|
||||
return fetchOperationQueue.poll();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,6 +130,24 @@ public abstract class AbstractFetchOperation extends AbstractHuamiOperation {
|
||||
*/
|
||||
@CallSuper
|
||||
protected boolean handleActivityFetchFinish(boolean success) {
|
||||
final AbstractFetchOperation nextFetchOperation = getSupport().getNextFetchOperation();
|
||||
if (nextFetchOperation != null) {
|
||||
LOG.debug("Performing next operation {}", nextFetchOperation.getName());
|
||||
try {
|
||||
nextFetchOperation.perform();
|
||||
return true;
|
||||
} catch (final IOException e) {
|
||||
GB.toast(
|
||||
getContext(),
|
||||
"Failed to run next fetch operation",
|
||||
Toast.LENGTH_SHORT,
|
||||
GB.ERROR, e
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
GB.updateTransferNotification(null, "", false, 100, getContext());
|
||||
operationFinished();
|
||||
unsetBusy();
|
||||
|
Loading…
Reference in New Issue
Block a user