package com.uxxu.konashi.lib.action;

import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;

import java.util.UUID;

import info.izumin.android.bletia.BleErrorType;
import info.izumin.android.bletia.BletiaException;
import info.izumin.android.bletia.action.WriteCharacteristicAction;
import info.izumin.android.bletia.wrapper.BluetoothGattWrapper;

/**
 * Created by izumin on 9/17/15.
 */
public abstract class KonashiWriteCharacteristicAction extends WriteCharacteristicAction {

    protected KonashiWriteCharacteristicAction(BluetoothGattCharacteristic characteristic) {
        super(characteristic);
    }

    protected KonashiWriteCharacteristicAction(BluetoothGattService service, UUID uuid) {
        this(service.getCharacteristic(uuid));
    }

    @Override
    public void execute(BluetoothGattWrapper gattWrapper) {
        if (hasValidParams()) {
            setValue();
            super.execute(gattWrapper);
        } else {
            rejectIfParamsAreInvalid();
        }
    }

    protected void rejectIfParamsAreInvalid() {
        getDeferred().reject(new BletiaException(BleErrorType.INVALID_PARAMETER, getCharacteristic()));
    }

    protected abstract void setValue();
    protected abstract boolean hasValidParams();
}

@@ -133,16 +133,63 @@
 rvice;%0A%0A
+import com.uxxu.konashi.lib.KonashiErrorType;%0A%0A
 import j
@@ -930,28 +930,99 @@
     
-if (hasValidParams()
+KonashiErrorType errorType = validate();%0A        if (errorType == KonashiErrorType.NO_ERROR
 ) %7B%0A
@@ -1139,16 +1139,25 @@
 Invalid(
+errorType
 );%0A     
@@ -1212,16 +1212,42 @@
 Invalid(
+KonashiErrorType errorType
 ) %7B%0A    
@@ -1291,28 +1291,25 @@
 ception(
-BleE
+e
 rrorType
 .INVALID
@@ -1304,26 +1304,8 @@
 Type
-.INVALID_PARAMETER
 , ge
@@ -1399,30 +1399,33 @@
 act 
-boolean hasValidParams
+KonashiErrorType validate
 ();%0A

Change hasValidParams to validate