mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 17:41:57 +01:00
Bip: remember last time synced
This commit is contained in:
parent
fd159b7603
commit
c8b71677cd
@ -5,8 +5,8 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
public enum BipActivityType {
|
||||
Outdoor(1),
|
||||
Treadmill(2),
|
||||
Cycling(3),
|
||||
Walking(4);
|
||||
Cycling(3), // should be Walking
|
||||
Walking(4); // should be cycling
|
||||
|
||||
private final int code;
|
||||
|
||||
|
@ -186,7 +186,7 @@ public abstract class AbstractFetchOperation extends AbstractMiBand2Operation {
|
||||
return calendar;
|
||||
}
|
||||
GregorianCalendar calendar = BLETypeConversions.createCalendar();
|
||||
calendar.add(Calendar.DAY_OF_MONTH, -10);
|
||||
calendar.add(Calendar.DAY_OF_MONTH, - 100);
|
||||
return calendar;
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -51,13 +52,15 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
public class FetchSportsDetailsOperation extends AbstractFetchOperation {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FetchSportsDetailsOperation.class);
|
||||
private final BaseActivitySummary summary;
|
||||
private final String lastSyncTimeKey;
|
||||
|
||||
private ByteArrayOutputStream buffer;
|
||||
|
||||
public FetchSportsDetailsOperation(BaseActivitySummary summary, MiBand2Support support) {
|
||||
public FetchSportsDetailsOperation(@NonNull BaseActivitySummary summary, @NonNull MiBand2Support support, @NonNull String lastSyncTimeKey) {
|
||||
super(support);
|
||||
setName("fetching sport details");
|
||||
this.summary = summary;
|
||||
this.lastSyncTimeKey = lastSyncTimeKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,6 +105,9 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
|
||||
summary.setGpxTrack(targetFile.getAbsolutePath());
|
||||
dbHandler.getDaoSession().getBaseActivitySummaryDao().update(summary);
|
||||
}
|
||||
GregorianCalendar endTime = BLETypeConversions.createCalendar();
|
||||
endTime.setTime(summary.getEndTime());
|
||||
saveLastSyncTimestamp(endTime);
|
||||
} catch (Exception ex) {
|
||||
GB.toast(getContext(), "Error getting activity details: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
|
||||
}
|
||||
@ -164,11 +170,10 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
|
||||
|
||||
@Override
|
||||
protected String getLastSyncTimeKey() {
|
||||
return getDevice().getAddress() + "_" + "lastSportsSummaryTimeMillis";
|
||||
return lastSyncTimeKey;
|
||||
}
|
||||
|
||||
protected GregorianCalendar getLastSuccessfulSyncTime() {
|
||||
// FIXME: remove this!
|
||||
GregorianCalendar calendar = BLETypeConversions.createCalendar();
|
||||
calendar.setTime(summary.getStartTime());
|
||||
return calendar;
|
||||
|
@ -68,6 +68,8 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
||||
protected void startFetching(TransactionBuilder builder) {
|
||||
LOG.info("start" + getName());
|
||||
GregorianCalendar sinceWhen = getLastSuccessfulSyncTime();
|
||||
builder.notify(characteristicActivityData, true);
|
||||
builder.notify(characteristicFetch, true);
|
||||
builder.write(characteristicFetch, BLETypeConversions.join(new byte[] {
|
||||
MiBand2Service.COMMAND_ACTIVITY_DATA_START_DATE,
|
||||
AmazfitBipService.COMMAND_ACTIVITY_DATA_TYPE_SPORTS_SUMMARIES},
|
||||
@ -109,7 +111,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
||||
super.handleActivityFetchFinish(success);
|
||||
|
||||
if (summary != null) {
|
||||
FetchSportsDetailsOperation nextOperation = new FetchSportsDetailsOperation(summary, getSupport());
|
||||
FetchSportsDetailsOperation nextOperation = new FetchSportsDetailsOperation(summary, getSupport(), getLastSyncTimeKey());
|
||||
try {
|
||||
nextOperation.perform();
|
||||
} catch (IOException ex) {
|
||||
@ -237,13 +239,6 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
||||
|
||||
@Override
|
||||
protected String getLastSyncTimeKey() {
|
||||
return getDevice().getAddress() + "_" + "lastSportsSummaryTimeMillis";
|
||||
}
|
||||
|
||||
protected GregorianCalendar getLastSuccessfulSyncTime() {
|
||||
// FIXME: remove this!
|
||||
GregorianCalendar calendar = BLETypeConversions.createCalendar();
|
||||
calendar.add(Calendar.DAY_OF_MONTH, -25);
|
||||
return calendar;
|
||||
return getDevice().getAddress() + "_" + "lastSportsActivityTimeMillis";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user