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