From 455b25f893e676518d70f9bbe3255c7425ce3206 Mon Sep 17 00:00:00 2001 From: Siddharth Date: Fri, 19 Apr 2024 13:27:27 +0530 Subject: [PATCH] chore: adding date, time and id fields (#11) * chore: adding date, time and id fields * chore: using client time insted of UTC. --- .../com/blink/pos/companion/MainActivity.java | 60 ++++++++++++++----- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/blink/pos/companion/MainActivity.java b/app/src/main/java/com/blink/pos/companion/MainActivity.java index 3afe6f3..0dcdd52 100644 --- a/app/src/main/java/com/blink/pos/companion/MainActivity.java +++ b/app/src/main/java/com/blink/pos/companion/MainActivity.java @@ -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; } } @@ -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(); } @@ -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); @@ -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();