Search in sources :

Example 1 with SingleMessageTaskRunner

use of sugar.free.sightparser.handling.SingleMessageTaskRunner in project SightRemote by TebbeUbben.

the class AlertService method onStatusChange.

@Override
public void onStatusChange(Status status) {
    if (status == Status.CONNECTED) {
        if (fetchTimer != null)
            return;
        fetchTimer = new Timer(false);
        fetchTimer.schedule(new TimerTask() {

            @Override
            public void run() {
                new SingleMessageTaskRunner(serviceConnector, new ActiveAlertMessage()).fetch(AlertService.this);
            }
        }, 0, 2000);
    } else {
        if (alertActivity != null)
            alertActivity.finish();
        if (fetchTimer != null) {
            fetchTimer.cancel();
            fetchTimer = null;
        }
        serviceConnector.disconnect();
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) ActiveAlertMessage(sugar.free.sightparser.applayer.messages.status.ActiveAlertMessage) SingleMessageTaskRunner(sugar.free.sightparser.handling.SingleMessageTaskRunner)

Example 2 with SingleMessageTaskRunner

use of sugar.free.sightparser.handling.SingleMessageTaskRunner 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 3 with SingleMessageTaskRunner

use of sugar.free.sightparser.handling.SingleMessageTaskRunner in project SightRemote by TebbeUbben.

the class StatusActivity method onClick.

@Override
public void onClick(View v) {
    if (StatusActivity.this.taskRunner != null)
        StatusActivity.this.taskRunner.cancel();
    handler.removeCallbacks(taskRunnerRunnable);
    AppLayerMessage message = null;
    if (v == tbrCancel) {
        tbrCancel.setVisibility(View.GONE);
        message = new CancelTBRMessage();
        Answers.getInstance().logCustom(new CustomEvent("TBR Cancelled"));
    } else if (v == bolus1Cancel) {
        bolus1Cancel.setVisibility(View.INVISIBLE);
        CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
        cancelBolusMessage.setBolusId(statusResult.getActiveBolusesMessage().getBolus1().getBolusID());
        message = cancelBolusMessage;
        Answers.getInstance().logCustom(new CustomEvent("Bolus Cancelled"));
    } else if (v == bolus2Cancel) {
        bolus2Cancel.setVisibility(View.INVISIBLE);
        CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
        cancelBolusMessage.setBolusId(statusResult.getActiveBolusesMessage().getBolus2().getBolusID());
        message = cancelBolusMessage;
        Answers.getInstance().logCustom(new CustomEvent("Bolus Cancelled"));
    } else if (v == bolus3Cancel) {
        bolus3Cancel.setVisibility(View.INVISIBLE);
        CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
        cancelBolusMessage.setBolusId(statusResult.getActiveBolusesMessage().getBolus3().getBolusID());
        message = cancelBolusMessage;
        Answers.getInstance().logCustom(new CustomEvent("Bolus Cancelled"));
    }
    SingleMessageTaskRunner taskRunner = new SingleMessageTaskRunner(getServiceConnector(), message);
    taskRunner.fetch(errorToastResultCallback);
    handler.postDelayed(taskRunnerRunnable, 500);
}
Also used : CustomEvent(com.crashlytics.android.answers.CustomEvent) AppLayerMessage(sugar.free.sightparser.applayer.messages.AppLayerMessage) CancelTBRMessage(sugar.free.sightparser.applayer.messages.remote_control.CancelTBRMessage) CancelBolusMessage(sugar.free.sightparser.applayer.messages.remote_control.CancelBolusMessage) SingleMessageTaskRunner(sugar.free.sightparser.handling.SingleMessageTaskRunner)

Example 4 with SingleMessageTaskRunner

use of sugar.free.sightparser.handling.SingleMessageTaskRunner in project SightRemote by TebbeUbben.

the class StatusActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item == startPump) {
        if (getServiceConnector().getStatus() == Status.CONNECTED) {
            SetPumpStatusMessage message = new SetPumpStatusMessage();
            message.setPumpStatus(PumpStatus.STARTED);
            SingleMessageTaskRunner taskRunner = new SingleMessageTaskRunner(getServiceConnector(), message);
            (confirmationDialog = new ConfirmationDialog(this, HTMLUtil.getHTML(R.string.start_pump_confirmation), () -> {
                startPump.setVisible(false);
                if (StatusActivity.this.taskRunner != null)
                    StatusActivity.this.taskRunner.cancel();
                taskRunner.fetch(errorToastResultCallback);
                handler.removeCallbacks(taskRunnerRunnable);
                handler.postDelayed(taskRunnerRunnable, 500);
            })).show();
        }
        return true;
    } else if (item == stopPump) {
        if (getServiceConnector().getStatus() == Status.CONNECTED) {
            SetPumpStatusMessage message = new SetPumpStatusMessage();
            message.setPumpStatus(PumpStatus.STOPPED);
            SingleMessageTaskRunner taskRunner = new SingleMessageTaskRunner(getServiceConnector(), message);
            (confirmationDialog = new ConfirmationDialog(this, HTMLUtil.getHTML(R.string.stop_pump_confirmation), () -> {
                stopPump.setVisible(false);
                if (StatusActivity.this.taskRunner != null)
                    StatusActivity.this.taskRunner.cancel();
                taskRunner.fetch(errorToastResultCallback);
                handler.removeCallbacks(taskRunnerRunnable);
                handler.postDelayed(taskRunnerRunnable, 500);
            })).show();
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : SetPumpStatusMessage(sugar.free.sightparser.applayer.messages.remote_control.SetPumpStatusMessage) SingleMessageTaskRunner(sugar.free.sightparser.handling.SingleMessageTaskRunner) ConfirmationDialog(sugar.free.sightremote.dialogs.ConfirmationDialog)

Example 5 with SingleMessageTaskRunner

use of sugar.free.sightparser.handling.SingleMessageTaskRunner in project SightRemote by TebbeUbben.

the class TemporaryBasalRateActivity method statusChanged.

@Override
protected void statusChanged(Status status) {
    if (status == Status.CONNECTED) {
        new SingleMessageTaskRunner(getServiceConnector(), new PumpStatusMessage()).fetch(this);
        showLoadingIndicator();
        hideManualOverlay();
    } else {
        if (confirmationDialog != null)
            confirmationDialog.hide();
        showManualOverlay();
        hideLoadingIndicator();
    }
}
Also used : PumpStatusMessage(sugar.free.sightparser.applayer.messages.status.PumpStatusMessage) SingleMessageTaskRunner(sugar.free.sightparser.handling.SingleMessageTaskRunner)

Aggregations

SingleMessageTaskRunner (sugar.free.sightparser.handling.SingleMessageTaskRunner)12 ConfirmationDialog (sugar.free.sightremote.dialogs.ConfirmationDialog)4 CustomEvent (com.crashlytics.android.answers.CustomEvent)3 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 ReadDateTimeMessage (sugar.free.sightparser.applayer.messages.status.ReadDateTimeMessage)2 ReadStatusParamBlockMessage (sugar.free.sightparser.applayer.messages.status_param.ReadStatusParamBlockMessage)2 HistorySendIntent (sugar.free.sightremote.utils.HistorySendIntent)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 AppLayerMessage (sugar.free.sightparser.applayer.messages.AppLayerMessage)1 CancelBolusMessage (sugar.free.sightparser.applayer.messages.remote_control.CancelBolusMessage)1 CancelTBRMessage (sugar.free.sightparser.applayer.messages.remote_control.CancelTBRMessage)1 DismissAlertMessage (sugar.free.sightparser.applayer.messages.remote_control.DismissAlertMessage)1 ExtendedBolusMessage (sugar.free.sightparser.applayer.messages.remote_control.ExtendedBolusMessage)1 MultiwaveBolusMessage (sugar.free.sightparser.applayer.messages.remote_control.MultiwaveBolusMessage)1 MuteAlertMessage (sugar.free.sightparser.applayer.messages.remote_control.MuteAlertMessage)1