Search in sources :

Example 1 with SetPumpStatusMessage

use of sugar.free.sightparser.applayer.messages.remote_control.SetPumpStatusMessage 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)

Aggregations

SetPumpStatusMessage (sugar.free.sightparser.applayer.messages.remote_control.SetPumpStatusMessage)1 SingleMessageTaskRunner (sugar.free.sightparser.handling.SingleMessageTaskRunner)1 ConfirmationDialog (sugar.free.sightremote.dialogs.ConfirmationDialog)1