Bip: remember last time synced

This commit is contained in:
cpfeiffer 2017-11-02 00:18:48 +01:00
parent fd159b7603
commit c8b71677cd
4 changed files with 15 additions and 15 deletions

View File

@ -5,8 +5,8 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
public enum BipActivityType { public enum BipActivityType {
Outdoor(1), Outdoor(1),
Treadmill(2), Treadmill(2),
Cycling(3), Cycling(3), // should be Walking
Walking(4); Walking(4); // should be cycling
private final int code; private final int code;

View File

@ -186,7 +186,7 @@ public abstract class AbstractFetchOperation extends AbstractMiBand2Operation {
return calendar; return calendar;
} }
GregorianCalendar calendar = BLETypeConversions.createCalendar(); GregorianCalendar calendar = BLETypeConversions.createCalendar();
calendar.add(Calendar.DAY_OF_MONTH, -10); calendar.add(Calendar.DAY_OF_MONTH, - 100);
return calendar; return calendar;
} }
} }

View File

@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations; package nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations;
import android.support.annotation.NonNull;
import android.widget.Toast; import android.widget.Toast;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -51,13 +52,15 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class FetchSportsDetailsOperation extends AbstractFetchOperation { 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 BaseActivitySummary summary; private final BaseActivitySummary summary;
private final String lastSyncTimeKey;
private ByteArrayOutputStream buffer; private ByteArrayOutputStream buffer;
public FetchSportsDetailsOperation(BaseActivitySummary summary, MiBand2Support support) { public FetchSportsDetailsOperation(@NonNull BaseActivitySummary summary, @NonNull MiBand2Support support, @NonNull String lastSyncTimeKey) {
super(support); super(support);
setName("fetching sport details"); setName("fetching sport details");
this.summary = summary; this.summary = summary;
this.lastSyncTimeKey = lastSyncTimeKey;
} }
@Override @Override
@ -102,6 +105,9 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
summary.setGpxTrack(targetFile.getAbsolutePath()); summary.setGpxTrack(targetFile.getAbsolutePath());
dbHandler.getDaoSession().getBaseActivitySummaryDao().update(summary); dbHandler.getDaoSession().getBaseActivitySummaryDao().update(summary);
} }
GregorianCalendar endTime = BLETypeConversions.createCalendar();
endTime.setTime(summary.getEndTime());
saveLastSyncTimestamp(endTime);
} catch (Exception ex) { } catch (Exception ex) {
GB.toast(getContext(), "Error getting activity details: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, 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 @Override
protected String getLastSyncTimeKey() { protected String getLastSyncTimeKey() {
return getDevice().getAddress() + "_" + "lastSportsSummaryTimeMillis"; return lastSyncTimeKey;
} }
protected GregorianCalendar getLastSuccessfulSyncTime() { protected GregorianCalendar getLastSuccessfulSyncTime() {
// FIXME: remove this!
GregorianCalendar calendar = BLETypeConversions.createCalendar(); GregorianCalendar calendar = BLETypeConversions.createCalendar();
calendar.setTime(summary.getStartTime()); calendar.setTime(summary.getStartTime());
return calendar; return calendar;

View File

@ -68,6 +68,8 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
protected void startFetching(TransactionBuilder builder) { protected void startFetching(TransactionBuilder builder) {
LOG.info("start" + getName()); LOG.info("start" + getName());
GregorianCalendar sinceWhen = getLastSuccessfulSyncTime(); GregorianCalendar sinceWhen = getLastSuccessfulSyncTime();
builder.notify(characteristicActivityData, true);
builder.notify(characteristicFetch, true);
builder.write(characteristicFetch, BLETypeConversions.join(new byte[] { builder.write(characteristicFetch, BLETypeConversions.join(new byte[] {
MiBand2Service.COMMAND_ACTIVITY_DATA_START_DATE, MiBand2Service.COMMAND_ACTIVITY_DATA_START_DATE,
AmazfitBipService.COMMAND_ACTIVITY_DATA_TYPE_SPORTS_SUMMARIES}, AmazfitBipService.COMMAND_ACTIVITY_DATA_TYPE_SPORTS_SUMMARIES},
@ -109,7 +111,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
super.handleActivityFetchFinish(success); super.handleActivityFetchFinish(success);
if (summary != null) { if (summary != null) {
FetchSportsDetailsOperation nextOperation = new FetchSportsDetailsOperation(summary, getSupport()); FetchSportsDetailsOperation nextOperation = new FetchSportsDetailsOperation(summary, getSupport(), getLastSyncTimeKey());
try { try {
nextOperation.perform(); nextOperation.perform();
} catch (IOException ex) { } catch (IOException ex) {
@ -237,13 +239,6 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
@Override @Override
protected String getLastSyncTimeKey() { protected String getLastSyncTimeKey() {
return getDevice().getAddress() + "_" + "lastSportsSummaryTimeMillis"; return getDevice().getAddress() + "_" + "lastSportsActivityTimeMillis";
}
protected GregorianCalendar getLastSuccessfulSyncTime() {
// FIXME: remove this!
GregorianCalendar calendar = BLETypeConversions.createCalendar();
calendar.add(Calendar.DAY_OF_MONTH, -25);
return calendar;
} }
} }