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();
}
}
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);
}
}
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);
}
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);
}
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();
}
}
Aggregations