Skip to content

Commit

Permalink
chore: adding date, time and id fields (#11)
Browse files Browse the repository at this point in the history
* chore: adding date, time and id fields

* chore: using client time insted of UTC.
  • Loading branch information
siddhart1o1 authored Apr 19, 2024
1 parent 46fa463 commit 455b25f
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions app/src/main/java/com/blink/pos/companion/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void onServiceConnected(ComponentName name, IBinder service) {
printerService = IPrinterService.Stub.asInterface(service);
isPrinterServiceBound = true;
if (pendingPrintData != null) {
PrintReceipt(pendingPrintData[0], pendingPrintData[1], pendingPrintData[2]);
PrintReceipt(pendingPrintData[0], pendingPrintData[1], pendingPrintData[2], pendingPrintData[3], pendingPrintData[4], pendingPrintData[5]);
pendingPrintData = null;
}
}
Expand Down Expand Up @@ -64,10 +64,13 @@ private void handleSendText(Intent intent) {
String username = data.getQueryParameter("username");
String amount = data.getQueryParameter("amount");
String paymentHash = data.getQueryParameter("paymentHash");
String transactionId = data.getQueryParameter("id");
String date = data.getQueryParameter("date");
String time = data.getQueryParameter("time");
if (isPrinterServiceBound) {
PrintReceipt(username, amount, paymentHash);
PrintReceipt(username, amount, paymentHash, transactionId, date , time );
} else {
pendingPrintData = new String[]{username, amount, paymentHash};
pendingPrintData = new String[]{username, amount, paymentHash, transactionId, date ,time};
}
finish();
}
Expand All @@ -91,11 +94,10 @@ private void paperOut() {
});
}

private void PrintReceipt(String username, String amount, String paymentHash) {
private void PrintReceipt(String username, String amount, String paymentHash, String transactionId, String date, String time) {
singleThreadExecutor.submit(() -> {
try {
PrintTextFormat dashedFormat = new PrintTextFormat();

dashedFormat.setStyle(0);
dashedFormat.setTextSize(27);
dashedFormat.setAli(1);
Expand All @@ -104,38 +106,64 @@ private void PrintReceipt(String username, String amount, String paymentHash) {

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
timeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

dateFormat.setTimeZone(TimeZone.getDefault());
timeFormat.setTimeZone(TimeZone.getDefault());
String currentDate = dateFormat.format(new Date());
String currentTime = timeFormat.format(new Date());

String dashedLine = new String(new char[32]).replace("\0", "-");

//Blink Logo
Bitmap originalBitmap = BitmapFactory.decodeStream(getAssets().open("blink-logo.png"));
int maxWidthPixels = 200;
double aspectRatio = (double) originalBitmap.getWidth() / originalBitmap.getHeight();
int newHeight = (int) (maxWidthPixels / aspectRatio);
Bitmap resizedBitmap = Bitmap.createScaledBitmap(originalBitmap, maxWidthPixels, newHeight, true);

printerService.printBitmap(resizedBitmap, 1, 1);


//dashed line
String dashedLine = new String(new char[32]).replace("\0", "-");
printerService.printText( dashedLine, dashedFormat);


//transaction data
printDynamicKeyValue("Username:" ," ", username);
printDynamicKeyValue("Amount:"," ", amount);
printDynamicKeyValue("Date:"," ", currentDate);
printDynamicKeyValue("Time:"," ", currentTime);
if (date != null && !date.isEmpty()) {
printDynamicKeyValue("Date:"," ", date);
} else {
printDynamicKeyValue("Date:"," ", currentDate);
}
if (time != null && !time.isEmpty()) {
printDynamicKeyValue("Time:"," ", time);
}else{
printDynamicKeyValue("Time:"," ", currentTime);
}


//dashed line
printerService.printText( dashedLine , dashedFormat);


//transaction hash
PrintTextFormat formatTxid = new PrintTextFormat();
formatTxid.setAli(1);
formatTxid.setTextSize(23);
formatTxid.setStyle(1);
printerService.printText("Payment Hash", formatTxid);
printerService.printText(paymentHash, formatTxid);
printerService.printText("\n", formatTxid);

if (transactionId != null && !transactionId.isEmpty()) {
printerService.printText("Blink Internal Id", formatTxid);
printerService.printText(transactionId, formatTxid);
printerService.printText("\n", formatTxid);
}

if (paymentHash != null && !paymentHash.isEmpty()) {
printerService.printText("Payment Hash", formatTxid);
printerService.printText(paymentHash, formatTxid);
printerService.printText("\n", formatTxid);
}


//stop printing
paperOut();
} catch (RemoteException e) {
e.printStackTrace();
Expand Down

0 comments on commit 455b25f

Please sign in to comment.