Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
anggastudio committed Oct 8, 2020
1 parent 560adb9 commit b572c0c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
14 changes: 8 additions & 6 deletions app/src/main/java/com/anggastudio/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ private void getSavedPrinter() {
BluetoothDevice connectedPrinter = Printama.with(this).getConnectedPrinter();
if (connectedPrinter != null) {
TextView connectedTo = findViewById(R.id.tv_printer_info);
connectedTo.setText("Connected to : " + connectedPrinter.getName());
String text = "Connected to : " + connectedPrinter.getName();
connectedTo.setText(text);
}
}

private void showPrinterList() {
Printama.showPrinterList(this, printerName -> {
Toast.makeText(this, printerName, Toast.LENGTH_SHORT).show();
TextView connectedTo = findViewById(R.id.tv_printer_info);
connectedTo.setText("Connected to : " + printerName);
String text = "Connected to : " + printerName;
connectedTo.setText(text);
if (!printerName.contains("failed")) {
findViewById(R.id.btn_printer_test).setVisibility(View.VISIBLE);
findViewById(R.id.btn_printer_test).setOnClickListener(v -> testPrinter());
Expand All @@ -81,7 +83,8 @@ private void printTextLeft() {
"------------------\n";
Printama.with(this).connect(printama -> {
printama.printText(Printama.LEFT, text);
// or simply printama.printText("some text") --> will be printed left aligned as default
// or simply
// printama.printText("some text") --> will be printed left aligned as default
printama.close();
});
}
Expand Down Expand Up @@ -241,9 +244,7 @@ private void printQrReceipt() {
PrintBody body = printModel.getPrintBody();
PrintFooter footer = printModel.getPrintFooter();
String date = "DATE: " + body.getDate();
String time = "PRINT TIME " + body.getTime();
String invoice = "INVOICE: " + body.getInvoice();
String midwareTimestamp = "CREATE TIME: " + body.getTimeStamp();

Printama.with(this).connect(printama -> {
printama.printImage(logo, 300);
Expand Down Expand Up @@ -288,7 +289,8 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
private void showResult(String printerName) {
showToast(printerName);
TextView connectedTo = findViewById(R.id.tv_printer_info);
connectedTo.setText("Connected to : " + printerName);
String text = "Connected to : " + printerName;
connectedTo.setText(text);
if (!printerName.contains("failed")) {
findViewById(R.id.btn_printer_test).setVisibility(View.VISIBLE);
findViewById(R.id.btn_printer_test).setOnClickListener(v -> testPrinter());
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/anggastudio/sample/model/PrintBody.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.anggastudio.sample.model;

import android.graphics.Bitmap;

public class PrintBody {
String invoice;
String date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public String getInitial() {
public void setInitial(String initial) {
this.initial = initial;
}

public String getPaymentBy() {
return paymentBy;
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/anggastudio/sample/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@

public class Util {

private Util() {

}

public static Bitmap decodeBase64(String base64) {
byte[] decodedByte = Base64.decode(base64, 0);
return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
}

public static Bitmap getQrCode(String qrCode) {
// please see the dependencies to create QRCode
// it's not included in Printama
return QRCode.from(qrCode).bitmap();
}

Expand Down

0 comments on commit b572c0c

Please sign in to comment.