auto address fixex
This commit is contained in:
parent
eed5980cfa
commit
6669528fdb
BIN
.gitignore
vendored
BIN
.gitignore
vendored
Binary file not shown.
@ -43,14 +43,12 @@ public class HostConfigViewModel extends ViewModel {
|
||||
|
||||
public MutableLiveData<String> terminalName = new MutableLiveData<>();
|
||||
|
||||
|
||||
public void loadConfig() {
|
||||
SystemParamsOperation sp = SystemParamsOperation.getInstance();
|
||||
// Merchant Info
|
||||
merchantName.setValue(sp.getMerchantName());
|
||||
merchantPhone.setValue(sp.getMerchantPhoneNo());
|
||||
merchantAddress1.setValue(wrapForUi(sp.getMerchantAddress()));
|
||||
merchantAddress2.setValue(sp.getMerchantAddress2());
|
||||
merchantAddress1.setValue(wrapMerchantAddress(sp.getMerchantAddress()));
|
||||
terminalName.setValue(sp.getTerminalName());
|
||||
|
||||
// PRIMARY HOST
|
||||
@ -86,20 +84,20 @@ public class HostConfigViewModel extends ViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
public static String wrapForUi(String text) {
|
||||
if (text == null || text.isEmpty()) return "";
|
||||
private String wrapMerchantAddress(String address) {
|
||||
if (TextUtils.isEmpty(address)) return "";
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
String addr = address
|
||||
.replace("\\r\\n", "\n")
|
||||
.replace("\\n", "\n")
|
||||
.replace("\r\n", "\n")
|
||||
.trim();
|
||||
|
||||
String[] paragraphs = text.split("\\n");
|
||||
//
|
||||
List<String> lines = wrapAddressText(addr, 29);
|
||||
|
||||
for (String paragraph : paragraphs) {
|
||||
List<String> wrappedLines = wrapAddressText(paragraph.trim(), 29);
|
||||
|
||||
result.addAll(wrappedLines);
|
||||
}
|
||||
|
||||
return TextUtils.join("\n", result);
|
||||
//
|
||||
return TextUtils.join("\n", lines);
|
||||
}
|
||||
|
||||
private String[] split(String raw) {
|
||||
|
||||
@ -1004,25 +1004,26 @@ public abstract class BaseXPrint {
|
||||
|
||||
public static List<String> wrapAddressText(String text, int maxLen) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
String[] words = text.split("\\s+");
|
||||
String[] paragraphs = text.split("\\r?\\n");
|
||||
|
||||
StringBuilder currentLine = new StringBuilder();
|
||||
for (String paragraph : paragraphs) {
|
||||
String[] words = paragraph.split("\\s+");
|
||||
StringBuilder currentLine = new StringBuilder();
|
||||
|
||||
for (String word : words) {
|
||||
// +1 for space (if line is not empty)
|
||||
if (currentLine.length() + word.length() + 1 <= maxLen) {
|
||||
if (currentLine.length() > 0) {
|
||||
currentLine.append(" ");
|
||||
for (String word : words) {
|
||||
if (currentLine.length() == 0) {
|
||||
currentLine.append(word);
|
||||
} else if (currentLine.length() + word.length() + 1 <= maxLen) {
|
||||
currentLine.append(" ").append(word);
|
||||
} else {
|
||||
lines.add(currentLine.toString());
|
||||
currentLine = new StringBuilder(word);
|
||||
}
|
||||
currentLine.append(word);
|
||||
} else {
|
||||
lines.add(currentLine.toString());
|
||||
currentLine = new StringBuilder(word);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentLine.length() > 0) {
|
||||
lines.add(currentLine.toString());
|
||||
if (currentLine.length() > 0) {
|
||||
lines.add(currentLine.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return lines;
|
||||
@ -1032,29 +1033,36 @@ public abstract class BaseXPrint {
|
||||
String receiptHeader = "";
|
||||
String merchantName = "";
|
||||
String merchantAddress = "";
|
||||
String merchantAddress2 = "";
|
||||
String merchantAddress3 = "";
|
||||
String merchantPhoneNo = "";
|
||||
String terminalName = "";
|
||||
|
||||
merchantName = SystemParamsOperation.getInstance().getMerchantName();
|
||||
receiptHeader = SystemParamsOperation.getInstance().getReceiptHeader();
|
||||
merchantAddress = SystemParamsOperation.getInstance().getMerchantAddress();
|
||||
|
||||
if(merchantAddress != null){
|
||||
//this step is needed for manually line break with \n in the Address
|
||||
merchantAddress = merchantAddress.replace("\\n", "\n");
|
||||
}
|
||||
|
||||
terminalName = SystemParamsOperation.getInstance().getTerminalName();
|
||||
|
||||
assert merchantAddress != null;
|
||||
List<String> result = wrapAddressText(merchantAddress, 29);
|
||||
|
||||
if (receiptHeader == null || TextUtils.equals(receiptHeader, "") || receiptHeader.trim().isEmpty()) {
|
||||
receiptHeader = merchantName;
|
||||
}
|
||||
if (TextUtils.equals(merchantAddress, "") || merchantAddress == null) {
|
||||
if (TextUtils.equals(merchantAddress, "")) {
|
||||
merchantAddress = "";
|
||||
}
|
||||
if(TextUtils.equals(terminalName, "") || terminalName == null){
|
||||
terminalName = "";
|
||||
}
|
||||
|
||||
printer.appendPrnStr(terminalName, fontNormal, AlignEnum.CENTER, true);
|
||||
|
||||
for (String line : result) {
|
||||
//result get the List of text from auto/manually break the address
|
||||
printer.appendPrnStr(line, fontNormal, AlignEnum.CENTER, false);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user