Search in sources :

Example 1 with ReadDateTimeMessage

use of sugar.free.sightparser.applayer.messages.status.ReadDateTimeMessage in project SightRemote by TebbeUbben.

the class HistorySyncService method onResult.

@Override
public void onResult(Object result) {
    if (result instanceof ReadStatusParamBlockMessage) {
        pumpSerialNumber = ((SystemIdentificationBlock) ((ReadStatusParamBlockMessage) result).getStatusBlock()).getSerialNumber();
        new SingleMessageTaskRunner(connector, new ReadDateTimeMessage()).fetch(this);
    } else if (result instanceof ReadHistoryTaskRunner.HistoryResult) {
        ReadHistoryTaskRunner.HistoryResult historyResult = (ReadHistoryTaskRunner.HistoryResult) result;
        List<HistoryFrame> historyFrames = historyResult.getHistoryFrames();
        if (historyResult.getLatestEventNumber() > 0)
            Offset.setOffset(getDatabaseHelper(), pumpSerialNumber, HistoryType.ALL, historyResult.getLatestEventNumber());
        connector.disconnect();
        connector.disconnectFromService();
        processHistoryFrames(historyFrames);
        syncing = false;
        sendBroadcast(new Intent(HistoryBroadcast.ACTION_SYNC_FINISHED));
        if (wakeLock.isHeld())
            wakeLock.release();
    } else if (result instanceof ReadDateTimeMessage) {
        ReadDateTimeMessage dateTimeMessage = (ReadDateTimeMessage) result;
        Date pumpDate = parseDateTime(dateTimeMessage.getYear(), dateTimeMessage.getMonth(), dateTimeMessage.getDay(), dateTimeMessage.getHour(), dateTimeMessage.getMinute(), dateTimeMessage.getSecond());
        dateTimeOffset = new Date().getTime() - pumpDate.getTime();
        new ReadHistoryTaskRunner(connector, createOpenMessage(HistoryType.ALL), Offset.getOffset(getDatabaseHelper(), pumpSerialNumber, HistoryType.ALL) == -1 ? 20 : Integer.MAX_VALUE).fetch(this);
    }
}
Also used : ReadDateTimeMessage(sugar.free.sightparser.applayer.messages.status.ReadDateTimeMessage) ReadStatusParamBlockMessage(sugar.free.sightparser.applayer.messages.status_param.ReadStatusParamBlockMessage) List(java.util.List) ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) HistorySendIntent(sugar.free.sightremote.utils.HistorySendIntent) SingleMessageTaskRunner(sugar.free.sightparser.handling.SingleMessageTaskRunner) Date(java.util.Date) ReadHistoryTaskRunner(sugar.free.sightparser.handling.taskrunners.ReadHistoryTaskRunner)

Example 2 with ReadDateTimeMessage

use of sugar.free.sightparser.applayer.messages.status.ReadDateTimeMessage in project SightRemote by TebbeUbben.

the class TimeSynchronizationService method onStatusChange.

@Override
public void onStatusChange(Status status) {
    if (status == Status.CONNECTED) {
        serviceConnector.connect();
        new SingleMessageTaskRunner(serviceConnector, new ReadDateTimeMessage()).fetch(this);
    } else
        serviceConnector.disconnect();
}
Also used : ReadDateTimeMessage(sugar.free.sightparser.applayer.messages.status.ReadDateTimeMessage) SingleMessageTaskRunner(sugar.free.sightparser.handling.SingleMessageTaskRunner)

Aggregations

ReadDateTimeMessage (sugar.free.sightparser.applayer.messages.status.ReadDateTimeMessage)2 SingleMessageTaskRunner (sugar.free.sightparser.handling.SingleMessageTaskRunner)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 ReadStatusParamBlockMessage (sugar.free.sightparser.applayer.messages.status_param.ReadStatusParamBlockMessage)1 ReadHistoryTaskRunner (sugar.free.sightparser.handling.taskrunners.ReadHistoryTaskRunner)1 HistorySendIntent (sugar.free.sightremote.utils.HistorySendIntent)1