Merge remote-tracking branch 'origin/ecr' into ecr

# Conflicts:
#	baselib/src/main/java/com/utsmyanmar/baselib/viewModel/EmvBaseViewModel.java
This commit is contained in:
kizzy 2026-03-06 16:41:08 +07:00
commit e0906ab434
2 changed files with 67 additions and 76 deletions

View File

@ -13,112 +13,109 @@ import java.util.Objects;
public class InputAmountViewModel extends ViewModel {
private static final String TAG = InputAmountViewModel.class.getSimpleName();
public MutableLiveData<String> inputAmountView = new MutableLiveData<>();
public SingleLiveEvent<String> invalidAmountMsg = new SingleLiveEvent<>();
public SingleLiveEvent<String> availableAmount = new SingleLiveEvent<>();
private static final int MAX_INT_DIGITS = 10;
private static final int MAX_DECIMAL_DIGITS = 2;
public InputAmountViewModel() {
inputAmountView.setValue("0");
}
private int countDecimalDigits(double number) {
String numberStr = Double.toString(number);
int decimalIndex = numberStr.indexOf('.');
return decimalIndex >= 0 ? numberStr.length() - decimalIndex - 1 : 0;
private String formatInteger(String value) {
if (TextUtils.isEmpty(value)) return "0";
double amt = Double.parseDouble(value);
DecimalFormat formatter = new DecimalFormat("#,###");
return formatter.format(amt);
}
public NumberKeyboard.KeyClickCallback onKeyClick() {
return new NumberKeyboard.KeyClickCallback() {
@Override
public void onNumClick(int keyNum) {
if (inputAmountView.getValue().length() == 15) {
String current = inputAmountView.getValue();
if (current == null) return;
String raw = current.replace(",", "");
if (raw.contains(".")) {
String[] parts = raw.split("\\.");
String intPart = parts[0];
String decimalPart = parts.length > 1 ? parts[1] : "";
if (decimalPart.length() >= MAX_DECIMAL_DIGITS) {
return;
}
if (TextUtils.equals(inputAmountView.getValue(), "0")) {
inputAmountView.setValue(keyNum + "");
} else if (inputAmountView.getValue().contains(".")) {
StringBuilder inputAmount = new StringBuilder();
inputAmount.append(inputAmountView.getValue());
int dotIndex = inputAmount.indexOf(".");
if(inputAmount.substring(dotIndex).length() > 0 && inputAmount.substring(dotIndex+1).length() == 2) {
return;
}
if (inputAmountView.getValue().contains(",")) {
inputAmountView.setValue(inputAmountView.getValue().replace(",", ""));
}
double amt = Double.parseDouble(inputAmountView.getValue());
if (countDecimalDigits(amt) < 2) {
inputAmountView.setValue(inputAmountView.getValue() + keyNum);
}
raw = raw + keyNum;
} else {
if (inputAmountView.getValue().contains(",")) {
inputAmountView.setValue(inputAmountView.getValue().replace(",", ""));
if (raw.length() >= MAX_INT_DIGITS) {
return;
}
inputAmountView.setValue(inputAmountView.getValue() + keyNum);
double amt = Double.parseDouble(inputAmountView.getValue());
DecimalFormat formatter = new DecimalFormat("#,###");
inputAmountView.setValue(formatter.format(amt));
if (TextUtils.equals(raw, "0")) {
raw = String.valueOf(keyNum);
} else {
raw = raw + keyNum;
}
}
if (raw.contains(".")) {
String[] parts = raw.split("\\.");
String formattedInt = formatInteger(parts[0]);
String decimal = parts.length > 1 ? parts[1] : "";
inputAmountView.setValue(formattedInt + "." + decimal);
} else {
inputAmountView.setValue(formatInteger(raw));
}
}
@Override
public void onDelClick() {
if (Objects.requireNonNull(inputAmountView.getValue()).contains(".")) {
return;
}
if (inputAmountView.getValue().length() == 15) {
return;
}
if (TextUtils.equals(inputAmountView.getValue(), "0")) {
String current = inputAmountView.getValue();
if (current == null) return;
if (current.contains(".")) return;
if (TextUtils.equals(current, "0")) {
inputAmountView.setValue("0.");
} else {
inputAmountView.setValue(inputAmountView.getValue() + ".");
inputAmountView.setValue(current + ".");
}
}
@Override
public void onCleanClick() {
if (inputAmountView.getValue() != null) {
if (inputAmountView.getValue().contains(".")) {
StringBuilder inputAmount = new StringBuilder();
inputAmount.append(inputAmountView.getValue());
inputAmount.deleteCharAt(inputAmount.length() - 1);
inputAmountView.setValue(inputAmount.toString());
} else if (!inputAmountView.getValue().equals("0")) {
String currentValue = inputAmountView.getValue();
String rawNumber = currentValue.replace(",", "");
String current = inputAmountView.getValue();
if (current == null) return;
if (rawNumber.length() > 1) {
rawNumber = rawNumber.substring(0, rawNumber.length() - 1);
String raw = current.replace(",", "");
double amt = Double.parseDouble(rawNumber);
DecimalFormat formatter = new DecimalFormat("#,###");
inputAmountView.setValue(formatter.format(amt));
} else {
if (raw.length() <= 1) {
inputAmountView.setValue("0");
return;
}
}
raw = raw.substring(0, raw.length() - 1);
if (raw.contains(".")) {
String[] parts = raw.split("\\.");
String formattedInt = formatInteger(parts[0]);
String decimal = parts.length > 1 ? parts[1] : "";
inputAmountView.setValue(formattedInt + "." + decimal);
} else {
inputAmountView.setValue(formatInteger(raw));
}
}
};
}
}

View File

@ -153,8 +153,6 @@ public abstract class EmvBaseViewModel extends BaseViewModel {
protected static final int EMV_ONLINE_PROCESS = 11;
protected static final int EMV_ERROR = 12;
protected static final int EMV_TRY_AGAIN = 13;
protected static final int EMV_CARD_BLOCK = 23;
protected static final int EMV_CTLS_TRY_AGAIN = 13;
protected static final int EMV_CONFIRM_CODE_VERIFY = 14;
@ -676,11 +674,11 @@ public abstract class EmvBaseViewModel extends BaseViewModel {
}
} else {
//contact terminal capability ; if different card brand(depend on aid) have different terminal capability
// if (ByteUtils.byteArray2HexString(aid).toUpperCase().contains("A000000004")) {
// emvHandler.setTlv(new byte[]{(byte) 0x9F, (byte) 0x33}, new byte[]{(byte) 0xE0, (byte) 0x28, (byte) 0xC8});
// emvHandler.setTlv(new byte[]{(byte) 0x9F, (byte) 0x1D}, ByteUtils.hexString2ByteArray("6C00800000000000"));//terminal risk
//
// }
if (ByteUtils.byteArray2HexString(aid).toUpperCase().contains("A000000004")) {
emvHandler.setTlv(new byte[]{(byte) 0x9F, (byte) 0x33}, ByteUtil.hexStr2Bytes(terminalCapability));
emvHandler.setTlv(new byte[]{(byte) 0xE0, (byte) 0x1D}, ByteUtils.hexString2ByteArray("6C00800000000000"));//terminal risk
}
}
emvHandler.onSetTransInitBeforeGPOResponse(true);
@ -827,10 +825,6 @@ public abstract class EmvBaseViewModel extends BaseViewModel {
case SdkResult.Emv_Qpboc_Online://EMV Contactless: Online Process for union pay
//union pay online contactless--application should go online
break;
case SdkResult.Emv_Card_Block:
case SdkResult.Emv_App_Block:
mHandler.sendEmptyMessage(EMV_CARD_BLOCK);
break;
case SdkResult.Emv_Candidatelist_Empty:// Application have no aid list
case SdkResult.Emv_FallBack:// FallBack ,chip card reset failed