duel currency select in sale
This commit is contained in:
parent
c251583f46
commit
df025bce34
@ -4,18 +4,25 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
|
import androidx.appcompat.widget.AppCompatButton;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import com.denzcoskun.imageslider.ImageSlider;
|
import com.denzcoskun.imageslider.ImageSlider;
|
||||||
import com.denzcoskun.imageslider.constants.ScaleTypes;
|
import com.denzcoskun.imageslider.constants.ScaleTypes;
|
||||||
@ -68,6 +75,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -97,6 +105,13 @@ public class MainFragment extends DataBindingFragment {
|
|||||||
private final ArrayList<SlideModel> imgList = new ArrayList<>();
|
private final ArrayList<SlideModel> imgList = new ArrayList<>();
|
||||||
private Observer<PayDetail> observeLastTrans;
|
private Observer<PayDetail> observeLastTrans;
|
||||||
private PayDetail lastPay;
|
private PayDetail lastPay;
|
||||||
|
private boolean cardPrimaryHostCached = false;
|
||||||
|
private String cardPrimaryHostName = "";
|
||||||
|
private String cardPrimaryTid = "";
|
||||||
|
private String cardPrimaryMid = "";
|
||||||
|
private String cardPrimaryIp = "";
|
||||||
|
private String cardPrimarySecIp = "";
|
||||||
|
private CurrencyType cardPrimaryCurrency = CurrencyType.MMK;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
EmvParamOperation emvParamOperation;
|
EmvParamOperation emvParamOperation;
|
||||||
@ -420,6 +435,200 @@ public class MainFragment extends DataBindingFragment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startCardSaleFlow() {
|
||||||
|
processBatch();
|
||||||
|
sharedViewModel.transactionsType.setValue(TransactionsType.SALE);
|
||||||
|
sharedViewModel.setTransMenu(TransMenu.SALE);
|
||||||
|
sharedViewModel.processCode.postValue(ProcessCode.SALE_PURCHASE + ProcessCode.SMART + ProcessCode.TO_ACCOUNT);
|
||||||
|
navigateToAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showCurrencyChooserForCardSale() {
|
||||||
|
List<String> currencies = getAvailableCardSaleCurrencies();
|
||||||
|
if (currencies.isEmpty()) {
|
||||||
|
applyCardCurrencyAndHost("MMK");
|
||||||
|
startCardSaleFlow();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currencies.size() == 1) {
|
||||||
|
applyCardCurrencyAndHost(currencies.get(0));
|
||||||
|
startCardSaleFlow();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
showCurrencyPickerDialog("Choose Currency", currencies, currency -> {
|
||||||
|
applyCardCurrencyAndHost(currency);
|
||||||
|
startCardSaleFlow();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getAvailableCardSaleCurrencies() {
|
||||||
|
cachePrimaryCardHostIfNeeded();
|
||||||
|
LinkedHashSet<String> values = new LinkedHashSet<>();
|
||||||
|
|
||||||
|
if (cardPrimaryCurrency != null && !TextUtils.isEmpty(cardPrimaryCurrency.name)) {
|
||||||
|
values.add(normalizeCurrency(cardPrimaryCurrency.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
String secondaryCurrency = normalizeCurrency(SystemParamsOperation.getInstance().getThirdHostCurrency());
|
||||||
|
if (!TextUtils.isEmpty(SystemParamsOperation.getInstance().getThirdHostName()) && !TextUtils.isEmpty(secondaryCurrency)) {
|
||||||
|
values.add(secondaryCurrency);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ArrayList<>(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyCardCurrencyAndHost(String selectedCurrency) {
|
||||||
|
cachePrimaryCardHostIfNeeded();
|
||||||
|
|
||||||
|
String selected = normalizeCurrency(selectedCurrency);
|
||||||
|
String secondaryCurrency = normalizeCurrency(SystemParamsOperation.getInstance().getThirdHostCurrency());
|
||||||
|
|
||||||
|
boolean useSecondaryCardHost = !TextUtils.isEmpty(SystemParamsOperation.getInstance().getThirdHostName())
|
||||||
|
&& !TextUtils.isEmpty(secondaryCurrency)
|
||||||
|
&& secondaryCurrency.equals(selected);
|
||||||
|
|
||||||
|
if (useSecondaryCardHost) {
|
||||||
|
SystemParamsOperation.getInstance().setHostName(SystemParamsOperation.getInstance().getThirdHostName());
|
||||||
|
SystemParamsOperation.getInstance().setTerminalId(SystemParamsOperation.getInstance().getThirdHostTerminalId());
|
||||||
|
SystemParamsOperation.getInstance().setMerchantId(SystemParamsOperation.getInstance().getThirdHostMerchantId());
|
||||||
|
SystemParamsOperation.getInstance().setIpAddress(SystemParamsOperation.getInstance().getThirdHostIpAddress());
|
||||||
|
SystemParamsOperation.getInstance().setSecIpAddress(SystemParamsOperation.getInstance().getThirdHostSecIpAddress());
|
||||||
|
} else {
|
||||||
|
SystemParamsOperation.getInstance().setHostName(cardPrimaryHostName);
|
||||||
|
SystemParamsOperation.getInstance().setTerminalId(cardPrimaryTid);
|
||||||
|
SystemParamsOperation.getInstance().setMerchantId(cardPrimaryMid);
|
||||||
|
SystemParamsOperation.getInstance().setIpAddress(cardPrimaryIp);
|
||||||
|
SystemParamsOperation.getInstance().setSecIpAddress(cardPrimarySecIp);
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrencyType currencyType = useSecondaryCardHost ? toCurrencyType(selected) : cardPrimaryCurrency;
|
||||||
|
SystemParamsOperation.getInstance().setCurrencyType(currencyType);
|
||||||
|
sharedViewModel.set_currencyText(currencyType.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cachePrimaryCardHostIfNeeded() {
|
||||||
|
if (cardPrimaryHostCached) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cardPrimaryHostName = SystemParamsOperation.getInstance().getHostName();
|
||||||
|
cardPrimaryTid = SystemParamsOperation.getInstance().getTerminalId();
|
||||||
|
cardPrimaryMid = SystemParamsOperation.getInstance().getMerchantId();
|
||||||
|
cardPrimaryIp = SystemParamsOperation.getInstance().getIpAddress();
|
||||||
|
cardPrimarySecIp = SystemParamsOperation.getInstance().getSecIpAddress();
|
||||||
|
CurrencyType activeCurrency = SystemParamsOperation.getInstance().getCurrencyType();
|
||||||
|
cardPrimaryCurrency = activeCurrency == null ? CurrencyType.MMK : activeCurrency;
|
||||||
|
cardPrimaryHostCached = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showCurrencyPickerDialog(String title, List<String> currencies, CurrencySelectCallback callback) {
|
||||||
|
LinearLayout root = new LinearLayout(requireContext());
|
||||||
|
root.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
root.setPadding(dp(20), dp(20), dp(20), dp(12));
|
||||||
|
|
||||||
|
TextView tvTitle = new TextView(requireContext());
|
||||||
|
tvTitle.setText(title);
|
||||||
|
tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
|
||||||
|
tvTitle.setTextColor(ContextCompat.getColor(requireContext(), R.color.colorTextTitle));
|
||||||
|
tvTitle.setPadding(0, 0, 0, dp(16));
|
||||||
|
root.addView(tvTitle);
|
||||||
|
|
||||||
|
final AlertDialog[] dialogHolder = new AlertDialog[1];
|
||||||
|
for (String currency : currencies) {
|
||||||
|
AppCompatButton button = new AppCompatButton(requireContext());
|
||||||
|
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
dp(56)
|
||||||
|
);
|
||||||
|
lp.bottomMargin = dp(10);
|
||||||
|
button.setLayoutParams(lp);
|
||||||
|
button.setAllCaps(false);
|
||||||
|
button.setText(currency);
|
||||||
|
button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
|
||||||
|
button.setGravity(Gravity.CENTER);
|
||||||
|
button.setBackgroundResource(R.drawable.bg_rounded_btn_cv);
|
||||||
|
button.setTextColor(ContextCompat.getColor(requireContext(), R.color.white));
|
||||||
|
button.setOnClickListener(v -> {
|
||||||
|
if (dialogHolder[0] != null) {
|
||||||
|
dialogHolder[0].dismiss();
|
||||||
|
}
|
||||||
|
callback.onSelected(currency);
|
||||||
|
});
|
||||||
|
root.addView(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
AppCompatButton cancel = new AppCompatButton(requireContext());
|
||||||
|
LinearLayout.LayoutParams cancelLp = new LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
dp(52)
|
||||||
|
);
|
||||||
|
cancel.setLayoutParams(cancelLp);
|
||||||
|
cancel.setAllCaps(false);
|
||||||
|
cancel.setText("Cancel");
|
||||||
|
cancel.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
|
||||||
|
cancel.setBackgroundResource(R.drawable.bg_rounded_btn_cancel_cv);
|
||||||
|
cancel.setTextColor(ContextCompat.getColor(requireContext(), R.color.colorPrimary));
|
||||||
|
cancel.setOnClickListener(v -> {
|
||||||
|
if (dialogHolder[0] != null) {
|
||||||
|
dialogHolder[0].dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
root.addView(cancel);
|
||||||
|
|
||||||
|
AlertDialog dialog = new AlertDialog.Builder(requireContext())
|
||||||
|
.setView(root)
|
||||||
|
.create();
|
||||||
|
dialogHolder[0] = dialog;
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int dp(int value) {
|
||||||
|
return Math.round(value * requireContext().getResources().getDisplayMetrics().density);
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface CurrencySelectCallback {
|
||||||
|
void onSelected(String currency);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CurrencyType toCurrencyType(String value) {
|
||||||
|
String normalized = normalizeCurrency(value);
|
||||||
|
try {
|
||||||
|
return CurrencyType.valueOf(normalized);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
return CurrencyType.MMK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeCurrency(String raw) {
|
||||||
|
if (TextUtils.isEmpty(raw)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
String value = raw.trim().toUpperCase();
|
||||||
|
switch (value) {
|
||||||
|
case "104":
|
||||||
|
case "MMK":
|
||||||
|
return "MMK";
|
||||||
|
case "840":
|
||||||
|
case "USD":
|
||||||
|
return "USD";
|
||||||
|
case "156":
|
||||||
|
case "CNY":
|
||||||
|
case "RMB":
|
||||||
|
return "CNY";
|
||||||
|
case "764":
|
||||||
|
case "THB":
|
||||||
|
return "THB";
|
||||||
|
case "643":
|
||||||
|
case "RUB":
|
||||||
|
return "RUB";
|
||||||
|
default:
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void processBatch() {
|
private void processBatch() {
|
||||||
|
|
||||||
calculateLastTransaction();
|
calculateLastTransaction();
|
||||||
@ -722,18 +931,11 @@ public class MainFragment extends DataBindingFragment {
|
|||||||
showSingleInfoDialog(getResourceString(R.string.txt_please_enable_internet));
|
showSingleInfoDialog(getResourceString(R.string.txt_please_enable_internet));
|
||||||
} else if (SystemParamsOperation.getInstance().isNeedSettlement()) {
|
} else if (SystemParamsOperation.getInstance().isNeedSettlement()) {
|
||||||
AlertXDialog.getInstance().showDialog(requireContext(), getResourceString(R.string.title_need_settle), getResourceString(R.string.txt_do_you_want_to_continue), () -> {
|
AlertXDialog.getInstance().showDialog(requireContext(), getResourceString(R.string.title_need_settle), getResourceString(R.string.txt_do_you_want_to_continue), () -> {
|
||||||
processBatch();
|
showCurrencyChooserForCardSale();
|
||||||
sharedViewModel.transactionsType.setValue(TransactionsType.SALE);
|
|
||||||
sharedViewModel.processCode.postValue(ProcessCode.SALE_PURCHASE + ProcessCode.SMART + ProcessCode.TO_ACCOUNT);
|
|
||||||
navigateToAmount();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
processBatch();
|
showCurrencyChooserForCardSale();
|
||||||
sharedViewModel.transactionsType.setValue(TransactionsType.SALE);
|
|
||||||
sharedViewModel.setTransMenu(TransMenu.SALE);
|
|
||||||
sharedViewModel.processCode.postValue(ProcessCode.SALE_PURCHASE + ProcessCode.SMART + ProcessCode.TO_ACCOUNT);
|
|
||||||
navigateToAmount();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,16 +2,25 @@ package com.utsmm.kbz.ui.dashboard;
|
|||||||
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.widget.AppCompatButton;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import com.utsmm.kbz.util.enums.SettlementType;
|
import com.utsmm.kbz.util.enums.SettlementType;
|
||||||
import com.utsmyanmar.baselib.fragment.DataBindingFragment;
|
import com.utsmyanmar.baselib.fragment.DataBindingFragment;
|
||||||
import com.utsmyanmar.baselib.util.DataBindingConfig;
|
import com.utsmyanmar.baselib.util.DataBindingConfig;
|
||||||
import com.utsmyanmar.paylibs.utils.LogUtil;
|
import com.utsmyanmar.paylibs.utils.LogUtil;
|
||||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
||||||
|
import com.utsmyanmar.paylibs.utils.enums.CurrencyType;
|
||||||
import com.utsmyanmar.paylibs.utils.enums.TransMenu;
|
import com.utsmyanmar.paylibs.utils.enums.TransMenu;
|
||||||
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType;
|
import com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType;
|
||||||
import com.utsmm.kbz.BR;
|
import com.utsmm.kbz.BR;
|
||||||
@ -24,6 +33,8 @@ import com.utsmm.kbz.ui.core_viewmodel.SharedViewModel;
|
|||||||
import com.utsmm.kbz.util.tms.TMSUtil;
|
import com.utsmm.kbz.util.tms.TMSUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DashboardTransFragment extends DataBindingFragment {
|
public class DashboardTransFragment extends DataBindingFragment {
|
||||||
|
|
||||||
@ -34,6 +45,13 @@ public class DashboardTransFragment extends DataBindingFragment {
|
|||||||
private ArrayList<Features> featuresList = new ArrayList<>();
|
private ArrayList<Features> featuresList = new ArrayList<>();
|
||||||
|
|
||||||
MainAdapter mainAdapter;
|
MainAdapter mainAdapter;
|
||||||
|
private boolean cardPrimaryHostCached = false;
|
||||||
|
private String cardPrimaryHostName = "";
|
||||||
|
private String cardPrimaryTid = "";
|
||||||
|
private String cardPrimaryMid = "";
|
||||||
|
private String cardPrimaryIp = "";
|
||||||
|
private String cardPrimarySecIp = "";
|
||||||
|
private CurrencyType cardPrimaryCurrency = CurrencyType.MMK;
|
||||||
|
|
||||||
private static final int hostId = Constants.NAV_HOST_ID;
|
private static final int hostId = Constants.NAV_HOST_ID;
|
||||||
private int routeId;
|
private int routeId;
|
||||||
@ -220,9 +238,11 @@ public class DashboardTransFragment extends DataBindingFragment {
|
|||||||
} else if (checkTid()) {
|
} else if (checkTid()) {
|
||||||
showDeclineDialog("Please Download Config!");
|
showDeclineDialog("Please Download Config!");
|
||||||
} else {
|
} else {
|
||||||
sharedViewModel.setTransactionsType(TransactionsType.PRE_AUTH_SALE);
|
showCurrencyChooserForCardFlow(() -> {
|
||||||
routeId = R.id.action_dashboardTransFragment_to_inputAmountFragment;
|
sharedViewModel.setTransactionsType(TransactionsType.PRE_AUTH_SALE);
|
||||||
safeRouteTo(currentId,routeId,hostId);
|
routeId = R.id.action_dashboardTransFragment_to_inputAmountFragment;
|
||||||
|
safeRouteTo(currentId, routeId, hostId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -253,10 +273,12 @@ public class DashboardTransFragment extends DataBindingFragment {
|
|||||||
|
|
||||||
|
|
||||||
public void onClickCashAdvance() {
|
public void onClickCashAdvance() {
|
||||||
sharedViewModel.setTransactionsType(TransactionsType.CASH_OUT);
|
showCurrencyChooserForCardFlow(() -> {
|
||||||
sharedViewModel.setTransMenu(TransMenu.CASH_OUT);
|
sharedViewModel.setTransactionsType(TransactionsType.CASH_OUT);
|
||||||
routeId = R.id.action_dashboardTransFragment_to_inputAmountFragment;
|
sharedViewModel.setTransMenu(TransMenu.CASH_OUT);
|
||||||
safeRouteTo(currentId,routeId,hostId);
|
routeId = R.id.action_dashboardTransFragment_to_inputAmountFragment;
|
||||||
|
safeRouteTo(currentId, routeId, hostId);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
public void onClickDeviceConfig(){
|
public void onClickDeviceConfig(){
|
||||||
@ -265,4 +287,190 @@ public class DashboardTransFragment extends DataBindingFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showCurrencyChooserForCardFlow(Runnable onSelected) {
|
||||||
|
List<String> currencies = getAvailableCardSaleCurrencies();
|
||||||
|
if (currencies.isEmpty()) {
|
||||||
|
applyCardCurrencyAndHost("MMK");
|
||||||
|
onSelected.run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currencies.size() == 1) {
|
||||||
|
applyCardCurrencyAndHost(currencies.get(0));
|
||||||
|
onSelected.run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
showCurrencyPickerDialog("Choose Currency", currencies, currency -> {
|
||||||
|
applyCardCurrencyAndHost(currency);
|
||||||
|
onSelected.run();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getAvailableCardSaleCurrencies() {
|
||||||
|
cachePrimaryCardHostIfNeeded();
|
||||||
|
LinkedHashSet<String> values = new LinkedHashSet<>();
|
||||||
|
|
||||||
|
if (cardPrimaryCurrency != null && !TextUtils.isEmpty(cardPrimaryCurrency.name)) {
|
||||||
|
values.add(normalizeCurrency(cardPrimaryCurrency.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
String secondaryCurrency = normalizeCurrency(SystemParamsOperation.getInstance().getThirdHostCurrency());
|
||||||
|
if (!TextUtils.isEmpty(SystemParamsOperation.getInstance().getThirdHostName()) && !TextUtils.isEmpty(secondaryCurrency)) {
|
||||||
|
values.add(secondaryCurrency);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ArrayList<>(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyCardCurrencyAndHost(String selectedCurrency) {
|
||||||
|
cachePrimaryCardHostIfNeeded();
|
||||||
|
|
||||||
|
String selected = normalizeCurrency(selectedCurrency);
|
||||||
|
String secondaryCurrency = normalizeCurrency(SystemParamsOperation.getInstance().getThirdHostCurrency());
|
||||||
|
|
||||||
|
boolean useSecondaryCardHost = !TextUtils.isEmpty(SystemParamsOperation.getInstance().getThirdHostName())
|
||||||
|
&& !TextUtils.isEmpty(secondaryCurrency)
|
||||||
|
&& secondaryCurrency.equals(selected);
|
||||||
|
|
||||||
|
if (useSecondaryCardHost) {
|
||||||
|
SystemParamsOperation.getInstance().setHostName(SystemParamsOperation.getInstance().getThirdHostName());
|
||||||
|
SystemParamsOperation.getInstance().setTerminalId(SystemParamsOperation.getInstance().getThirdHostTerminalId());
|
||||||
|
SystemParamsOperation.getInstance().setMerchantId(SystemParamsOperation.getInstance().getThirdHostMerchantId());
|
||||||
|
SystemParamsOperation.getInstance().setIpAddress(SystemParamsOperation.getInstance().getThirdHostIpAddress());
|
||||||
|
SystemParamsOperation.getInstance().setSecIpAddress(SystemParamsOperation.getInstance().getThirdHostSecIpAddress());
|
||||||
|
} else {
|
||||||
|
SystemParamsOperation.getInstance().setHostName(cardPrimaryHostName);
|
||||||
|
SystemParamsOperation.getInstance().setTerminalId(cardPrimaryTid);
|
||||||
|
SystemParamsOperation.getInstance().setMerchantId(cardPrimaryMid);
|
||||||
|
SystemParamsOperation.getInstance().setIpAddress(cardPrimaryIp);
|
||||||
|
SystemParamsOperation.getInstance().setSecIpAddress(cardPrimarySecIp);
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrencyType currencyType = useSecondaryCardHost ? toCurrencyType(selected) : cardPrimaryCurrency;
|
||||||
|
SystemParamsOperation.getInstance().setCurrencyType(currencyType);
|
||||||
|
sharedViewModel.set_currencyText(currencyType.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cachePrimaryCardHostIfNeeded() {
|
||||||
|
if (cardPrimaryHostCached) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cardPrimaryHostName = SystemParamsOperation.getInstance().getHostName();
|
||||||
|
cardPrimaryTid = SystemParamsOperation.getInstance().getTerminalId();
|
||||||
|
cardPrimaryMid = SystemParamsOperation.getInstance().getMerchantId();
|
||||||
|
cardPrimaryIp = SystemParamsOperation.getInstance().getIpAddress();
|
||||||
|
cardPrimarySecIp = SystemParamsOperation.getInstance().getSecIpAddress();
|
||||||
|
CurrencyType activeCurrency = SystemParamsOperation.getInstance().getCurrencyType();
|
||||||
|
cardPrimaryCurrency = activeCurrency == null ? CurrencyType.MMK : activeCurrency;
|
||||||
|
cardPrimaryHostCached = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CurrencyType toCurrencyType(String value) {
|
||||||
|
String normalized = normalizeCurrency(value);
|
||||||
|
try {
|
||||||
|
return CurrencyType.valueOf(normalized);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
return CurrencyType.MMK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeCurrency(String raw) {
|
||||||
|
if (TextUtils.isEmpty(raw)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
String value = raw.trim().toUpperCase();
|
||||||
|
switch (value) {
|
||||||
|
case "104":
|
||||||
|
case "MMK":
|
||||||
|
return "MMK";
|
||||||
|
case "840":
|
||||||
|
case "USD":
|
||||||
|
return "USD";
|
||||||
|
case "156":
|
||||||
|
case "CNY":
|
||||||
|
case "RMB":
|
||||||
|
return "CNY";
|
||||||
|
case "764":
|
||||||
|
case "THB":
|
||||||
|
return "THB";
|
||||||
|
case "643":
|
||||||
|
case "RUB":
|
||||||
|
return "RUB";
|
||||||
|
default:
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showCurrencyPickerDialog(String title, List<String> currencies, CurrencySelectCallback callback) {
|
||||||
|
LinearLayout root = new LinearLayout(requireContext());
|
||||||
|
root.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
root.setPadding(dp(20), dp(20), dp(20), dp(12));
|
||||||
|
|
||||||
|
TextView tvTitle = new TextView(requireContext());
|
||||||
|
tvTitle.setText(title);
|
||||||
|
tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
|
||||||
|
tvTitle.setTextColor(ContextCompat.getColor(requireContext(), R.color.colorTextTitle));
|
||||||
|
tvTitle.setPadding(0, 0, 0, dp(16));
|
||||||
|
root.addView(tvTitle);
|
||||||
|
|
||||||
|
final AlertDialog[] dialogHolder = new AlertDialog[1];
|
||||||
|
for (String currency : currencies) {
|
||||||
|
AppCompatButton button = new AppCompatButton(requireContext());
|
||||||
|
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
dp(56)
|
||||||
|
);
|
||||||
|
lp.bottomMargin = dp(10);
|
||||||
|
button.setLayoutParams(lp);
|
||||||
|
button.setAllCaps(false);
|
||||||
|
button.setText(currency);
|
||||||
|
button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
|
||||||
|
button.setGravity(Gravity.CENTER);
|
||||||
|
button.setBackgroundResource(R.drawable.bg_rounded_btn_cv);
|
||||||
|
button.setTextColor(ContextCompat.getColor(requireContext(), R.color.white));
|
||||||
|
button.setOnClickListener(v -> {
|
||||||
|
if (dialogHolder[0] != null) {
|
||||||
|
dialogHolder[0].dismiss();
|
||||||
|
}
|
||||||
|
callback.onSelected(currency);
|
||||||
|
});
|
||||||
|
root.addView(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
AppCompatButton cancel = new AppCompatButton(requireContext());
|
||||||
|
LinearLayout.LayoutParams cancelLp = new LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
dp(52)
|
||||||
|
);
|
||||||
|
cancel.setLayoutParams(cancelLp);
|
||||||
|
cancel.setAllCaps(false);
|
||||||
|
cancel.setText("Cancel");
|
||||||
|
cancel.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
|
||||||
|
cancel.setBackgroundResource(R.drawable.bg_rounded_btn_cancel_cv);
|
||||||
|
cancel.setTextColor(ContextCompat.getColor(requireContext(), R.color.colorPrimary));
|
||||||
|
cancel.setOnClickListener(v -> {
|
||||||
|
if (dialogHolder[0] != null) {
|
||||||
|
dialogHolder[0].dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
root.addView(cancel);
|
||||||
|
|
||||||
|
AlertDialog dialog = new AlertDialog.Builder(requireContext())
|
||||||
|
.setView(root)
|
||||||
|
.create();
|
||||||
|
dialogHolder[0] = dialog;
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int dp(int value) {
|
||||||
|
return Math.round(value * requireContext().getResources().getDisplayMetrics().density);
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface CurrencySelectCallback {
|
||||||
|
void onSelected(String currency);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user