Skip to content

Commit

Permalink
Fix SendLinePrint class
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrudu committed Sep 21, 2022
1 parent f234cab commit 864dd3a
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

public class SendLinePrintTask extends AsyncTask<Void, Boolean, Boolean> {

public enum SendCPCLTaskErrors
public enum SendLinePrintTaskErrors
{
NO_PRINTER,
EMPTY_CPCL_STRING,
EMPTY_LINEPRINT_STRING,
PRINTER_PAUSED,
HEAD_OPEN,
PAPER_OUT,
Expand All @@ -30,19 +30,19 @@ public enum SendCPCLTaskErrors
ERROR_CPCL_PRINTER
}

public interface SendCPCLTaskCallback
public interface SendLinePrintTaskCallback
{
void onError(SendCPCLTaskErrors error, String message);
void onError(SendLinePrintTaskErrors error, String message);
void onSuccess();
}


private static final String TAG = "SEND_LINEPRINT_TASK";
private DiscoveredPrinter printer;
private String lineprintString;
private SendCPCLTaskCallback callback = null;
private SendLinePrintTaskCallback callback = null;

public SendLinePrintTask(String lineprintString, DiscoveredPrinter printer, SendCPCLTaskCallback callback) {
public SendLinePrintTask(String lineprintString, DiscoveredPrinter printer, SendLinePrintTaskCallback callback) {
this.printer = printer;
this.lineprintString = lineprintString;
this.callback = callback;
Expand All @@ -61,7 +61,7 @@ private void sendPrint() {
{
if(callback != null)
{
callback.onError(SendCPCLTaskErrors.EMPTY_CPCL_STRING, "Empty lineprint string");
callback.onError(SendLinePrintTaskErrors.EMPTY_LINEPRINT_STRING, "Empty lineprint string");
}
return;
}
Expand All @@ -84,7 +84,7 @@ private void sendPrint() {
{
if(callback != null)
{
callback.onError(SendCPCLTaskErrors.NO_PRINTER, "No printer found");
callback.onError(SendLinePrintTaskErrors.NO_PRINTER, "No printer found");
}
return;
}
Expand All @@ -96,30 +96,30 @@ private void sendPrint() {
if (printerStatus.isPaused) {
if(callback != null)
{
callback.onError(SendCPCLTaskErrors.PRINTER_PAUSED, "Printer is paused");
callback.onError(SendLinePrintTaskErrors.PRINTER_PAUSED, "Printer is paused");
}
return;
}
else if (printerStatus.isHeadOpen)
{
if(callback != null)
{
callback.onError(SendCPCLTaskErrors.HEAD_OPEN, "Printer's head is open");
callback.onError(SendLinePrintTaskErrors.HEAD_OPEN, "Printer's head is open");
}
return;
} else if (printerStatus.isPaperOut)
{
if(callback != null)
{
callback.onError(SendCPCLTaskErrors.PAPER_OUT, "Paper is out");
callback.onError(SendLinePrintTaskErrors.PAPER_OUT, "Paper is out");
}
return;
}
else
{
if(callback != null)
{
callback.onError(SendCPCLTaskErrors.UNKNOWN_PRINTER_STATUS, "Unknown printer status");
callback.onError(SendLinePrintTaskErrors.UNKNOWN_PRINTER_STATUS, "Unknown printer status");
}
return;
}
Expand All @@ -129,7 +129,7 @@ else if (printerStatus.isHeadOpen)
if (pl != PrinterLanguage.LINE_PRINT) {
if(callback != null)
{
callback.onError(pl == PrinterLanguage.ZPL ? SendLinePrintTask.SendCPCLTaskErrors.ERROR_ZPL_PRINTER : SendLinePrintTask.SendCPCLTaskErrors.ERROR_CPCL_PRINTER, "Can't send lineprint content to a " + (pl == PrinterLanguage.ZPL ? "ZPL" : "CPCL") + " printer.");
callback.onError(pl == PrinterLanguage.ZPL ? SendLinePrintTask.SendLinePrintTaskErrors.ERROR_ZPL_PRINTER : SendLinePrintTask.SendLinePrintTaskErrors.ERROR_CPCL_PRINTER, "Can't send lineprint content to a " + (pl == PrinterLanguage.ZPL ? "ZPL" : "CPCL") + " printer.");
}
return;
}
Expand All @@ -140,13 +140,13 @@ else if (printerStatus.isHeadOpen)
e.printStackTrace();
if(callback != null)
{
callback.onError(SendCPCLTaskErrors.CONNECTION_ERROR, e.getLocalizedMessage());
callback.onError(SendLinePrintTaskErrors.CONNECTION_ERROR, e.getLocalizedMessage());
}
} catch (ZebraPrinterLanguageUnknownException e) {
e.printStackTrace();
if(callback != null)
{
callback.onError(SendCPCLTaskErrors.PRINTER_LANGUAGE_UNKNOWN, e.getLocalizedMessage());
callback.onError(SendLinePrintTaskErrors.PRINTER_LANGUAGE_UNKNOWN, e.getLocalizedMessage());
}
} finally {
try {
Expand Down

0 comments on commit 864dd3a

Please sign in to comment.