mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-24 01:25:50 +01:00
Huami: Use activity summary timezone for details fetching (#3592)
It looks like some watches will reply with a fetch timestamp in a different timezone than the request. When this happens, when we fetch the activity details, the watch will reply with the details from the wrong activity. Use the same timezone in the activity details request as the watch replies in the activity summary.
This commit is contained in:
parent
42277fceb9
commit
4bfb7d4621
@ -196,7 +196,9 @@ public abstract class AbstractFetchOperation extends AbstractHuamiOperation {
|
|||||||
buffer.write(value, 1, value.length - 1); // skip the counter
|
buffer.write(value, 1, value.length - 1); // skip the counter
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startFetching(final TransactionBuilder builder, final byte fetchType, final GregorianCalendar sinceWhen) {
|
protected void startFetching(final TransactionBuilder builder, final byte fetchType, final Calendar sinceWhen) {
|
||||||
|
LOG.debug("Requesting {} since {}", getName(), sinceWhen.getTime());
|
||||||
|
|
||||||
final HuamiSupport support = getSupport();
|
final HuamiSupport support = getSupport();
|
||||||
byte[] fetchBytes = BLETypeConversions.join(new byte[]{
|
byte[] fetchBytes = BLETypeConversions.join(new byte[]{
|
||||||
HuamiService.COMMAND_ACTIVITY_DATA_START_DATE,
|
HuamiService.COMMAND_ACTIVITY_DATA_START_DATE,
|
||||||
|
@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -55,17 +56,20 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
|
|||||||
private static final Logger LOG = LoggerFactory.getLogger(FetchSportsDetailsOperation.class);
|
private static final Logger LOG = LoggerFactory.getLogger(FetchSportsDetailsOperation.class);
|
||||||
private final AbstractHuamiActivityDetailsParser detailsParser;
|
private final AbstractHuamiActivityDetailsParser detailsParser;
|
||||||
private final BaseActivitySummary summary;
|
private final BaseActivitySummary summary;
|
||||||
|
private final Calendar summarySyncTime;
|
||||||
private final String lastSyncTimeKey;
|
private final String lastSyncTimeKey;
|
||||||
|
|
||||||
FetchSportsDetailsOperation(@NonNull BaseActivitySummary summary,
|
FetchSportsDetailsOperation(@NonNull BaseActivitySummary summary,
|
||||||
@NonNull AbstractHuamiActivityDetailsParser detailsParser,
|
@NonNull AbstractHuamiActivityDetailsParser detailsParser,
|
||||||
@NonNull HuamiSupport support,
|
@NonNull HuamiSupport support,
|
||||||
|
@NonNull Calendar summarySyncTime,
|
||||||
@NonNull String lastSyncTimeKey,
|
@NonNull String lastSyncTimeKey,
|
||||||
int fetchCount) {
|
int fetchCount) {
|
||||||
super(support);
|
super(support);
|
||||||
setName("fetching sport details");
|
setName("fetching sport details");
|
||||||
this.summary = summary;
|
this.summary = summary;
|
||||||
this.detailsParser = detailsParser;
|
this.detailsParser = detailsParser;
|
||||||
|
this.summarySyncTime = summarySyncTime;
|
||||||
this.lastSyncTimeKey = lastSyncTimeKey;
|
this.lastSyncTimeKey = lastSyncTimeKey;
|
||||||
this.fetchCount = fetchCount;
|
this.fetchCount = fetchCount;
|
||||||
}
|
}
|
||||||
@ -77,9 +81,9 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startFetching(TransactionBuilder builder) {
|
protected void startFetching(TransactionBuilder builder) {
|
||||||
LOG.info("start " + getName());
|
LOG.info("start {}", getName());
|
||||||
final GregorianCalendar sinceWhen = getLastSuccessfulSyncTime();
|
// Use the actual last time, including tz - #3592
|
||||||
startFetching(builder, HuamiFetchDataType.SPORTS_DETAILS.getCode(), sinceWhen);
|
startFetching(builder, HuamiFetchDataType.SPORTS_DETAILS.getCode(), summarySyncTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -191,7 +195,7 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
|
|||||||
@Override
|
@Override
|
||||||
protected GregorianCalendar getLastSuccessfulSyncTime() {
|
protected GregorianCalendar getLastSuccessfulSyncTime() {
|
||||||
final GregorianCalendar calendar = BLETypeConversions.createCalendar();
|
final GregorianCalendar calendar = BLETypeConversions.createCalendar();
|
||||||
calendar.setTime(summary.getStartTime());
|
calendar.setTime(summarySyncTime.getTime());
|
||||||
return calendar;
|
return calendar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startFetching(TransactionBuilder builder) {
|
protected void startFetching(TransactionBuilder builder) {
|
||||||
LOG.info("start" + getName());
|
LOG.info("start {}", getName());
|
||||||
final GregorianCalendar sinceWhen = getLastSuccessfulSyncTime();
|
final GregorianCalendar sinceWhen = getLastSuccessfulSyncTime();
|
||||||
startFetching(builder, HuamiFetchDataType.SPORTS_SUMMARIES.getCode(), sinceWhen);
|
startFetching(builder, HuamiFetchDataType.SPORTS_SUMMARIES.getCode(), sinceWhen);
|
||||||
}
|
}
|
||||||
@ -106,7 +106,14 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final AbstractHuamiActivityDetailsParser detailsParser = ((HuamiActivitySummaryParser) summaryParser).getDetailsParser(summary);
|
final AbstractHuamiActivityDetailsParser detailsParser = ((HuamiActivitySummaryParser) summaryParser).getDetailsParser(summary);
|
||||||
final FetchSportsDetailsOperation nextOperation = new FetchSportsDetailsOperation(summary, detailsParser, getSupport(), getLastSyncTimeKey(), fetchCount);
|
final FetchSportsDetailsOperation nextOperation = new FetchSportsDetailsOperation(
|
||||||
|
summary,
|
||||||
|
detailsParser,
|
||||||
|
getSupport(),
|
||||||
|
getLastStartTimestamp(), // we need the actual start timestamp, including tz - #3592
|
||||||
|
getLastSyncTimeKey(),
|
||||||
|
fetchCount
|
||||||
|
);
|
||||||
getSupport().getFetchOperationQueue().add(0, nextOperation);
|
getSupport().getFetchOperationQueue().add(0, nextOperation);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user