-
-
Save marcomorain/f76e440df3776efa85a8c6840edda524 to your computer and use it in GitHub Desktop.
Clover Printer NPE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.IInterface | |
import com.clover.sdk.v1.ServiceConnector | |
import android.accounts.Account | |
import android.app.Activity | |
import android.content.Context | |
import com.clover.sdk.util.CloverAccount | |
import com.clover.sdk.v1.Intents | |
import com.clover.sdk.v1.ResultStatus | |
import com.clover.sdk.v1.ServiceConnector | |
import com.clover.sdk.v1.printer.Category | |
import com.clover.sdk.v1.printer.PrinterConnector | |
import com.clover.sdk.v1.printer.ReceiptRegistrationConnector | |
import com.clover.sdk.v1.printer.job.StaticBillPrintJob | |
import com.clover.sdk.v3.order.OrderConnector | |
// This is a wrapper around the ServiceConnector that executes `body` in the | |
// context of a connected service and always ensures that the service is | |
// disconnected, even if `body` throws. | |
fun <T : ServiceConnector<Service>, Service: IInterface, Result> connectedTo(connector: T, body: (T) -> Result) : Result { | |
connector.connect() | |
try { | |
return body.invoke(connector) | |
} finally { | |
connector.disconnect() | |
} | |
} | |
fun printOrder(context: Context, account: Account, orderId: String) { | |
connectedTo(PrinterConnector(context, account, null)) { printerConnector -> | |
val printer = printerConnector.getPrinters(Category.RECEIPT).firstOrNull() | |
if (printer != null) { | |
connectedTo(OrderConnector(context, account, null)) { | |
val o = it.getOrder(orderId) | |
StaticBillPrintJob.Builder().order(o).build().print(context, account, printer) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment