|
|
@ -34,7 +34,7 @@ import butterknife.BindView; |
|
|
|
import butterknife.ButterKnife; |
|
|
|
import io.reactivex.disposables.CompositeDisposable; |
|
|
|
|
|
|
|
public class AmountDetailSendMoneyFragment extends BaseFragment implements View.OnClickListener, View.OnKeyListener, AmountDetailExRateCountryListingDialog.ExRateCurrencySelectionListener { |
|
|
|
public class AmountDetailSendMoneyFragment extends BaseFragment implements View.OnClickListener, AmountDetailExRateCountryListingDialog.ExRateCurrencySelectionListener, TextView.OnEditorActionListener { |
|
|
|
|
|
|
|
@BindView(R.id.amountDetailContinueButton) |
|
|
|
Button continueBtn; |
|
|
@ -95,8 +95,8 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
public void onStart() { |
|
|
|
super.onStart(); |
|
|
|
continueBtn.setOnClickListener(this); |
|
|
|
// receiveAmountEdTxt.setOnKeyListener(this); |
|
|
|
// sendAmountEdTxt.setOnKeyListener(this); |
|
|
|
receiveAmountEdTxt.setOnEditorActionListener(this); |
|
|
|
sendAmountEdTxt.setOnEditorActionListener(this); |
|
|
|
countrySelectionSpinner.setOnClickListener(this); |
|
|
|
} |
|
|
|
|
|
|
@ -104,8 +104,8 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
public void onStop() { |
|
|
|
super.onStop(); |
|
|
|
continueBtn.setOnClickListener(null); |
|
|
|
// receiveAmountEdTxt.setOnKeyListener(null); |
|
|
|
// sendAmountEdTxt.setOnKeyListener(null); |
|
|
|
receiveAmountEdTxt.setOnEditorActionListener(null); |
|
|
|
sendAmountEdTxt.setOnEditorActionListener(null); |
|
|
|
countrySelectionSpinner.setOnClickListener(null); |
|
|
|
} |
|
|
|
|
|
|
@ -153,7 +153,8 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
private void performDefaultAction(Bundle savedInstance) { |
|
|
|
shouldCaulatedByRecipient = false; |
|
|
|
compositeDisposable.add( |
|
|
|
((SendMoneyActionListener) getActivity()).getPresenter().getAmountDetailRelatedData().subscribeWith(new AmountDetailRelatedDataObserver())); |
|
|
|
((SendMoneyActionListener) getActivity()).getPresenter().getAmountDetailRelatedData().subscribeWith(new AmountDetailRelatedDataObserver()) |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -170,34 +171,11 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean onKey(View v, int keyCode, KeyEvent event) { |
|
|
|
switch (v.getId()) { |
|
|
|
case R.id.sendAmountEdTxt: |
|
|
|
if (keyCode == EditorInfo.IME_ACTION_DONE) { |
|
|
|
shouldCaulatedByRecipient = false; |
|
|
|
if (validateAmountIsNotEmpty(sendAmountEdTxt.getText().toString())) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
case R.id.receiveAmountEdTxt: |
|
|
|
if (keyCode == EditorInfo.IME_ACTION_DONE) { |
|
|
|
shouldCaulatedByRecipient = true; |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void getForex() { |
|
|
|
compositeDisposable.add( |
|
|
|
((SendMoneyActionListener) getActivity()).getPresenter().getForex( |
|
|
|
receiveAmountEdTxt.getText().toString(), sendAmountEdTxt.getText().toString(), shouldCaulatedByRecipient, "RECIEVERCURRENCY" |
|
|
|
receiveAmountEdTxt.getText().toString(), sendAmountEdTxt.getText().toString(), shouldCaulatedByRecipient, amountDetailRelatedData.getDefaultSelectedCurrency().getCurrencyCode() |
|
|
|
).doOnSubscribe(d -> showProgressBar(true, "Calculating...")) |
|
|
|
.subscribeWith(new ExchangeRateCalcObserver()) |
|
|
|
); |
|
|
@ -238,41 +216,73 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onCurrencySelected(RecipientCurrencyModel selectedCurrency) { |
|
|
|
|
|
|
|
amountDetailRelatedData.setDefaultSelectedCurrency(selectedCurrency); |
|
|
|
|
|
|
|
if (exRateCountryListingDialog != null) |
|
|
|
exRateCountryListingDialog.dismiss(); |
|
|
|
exRateCountryListingDialog = null; |
|
|
|
|
|
|
|
showSelectedCurrency(amountDetailRelatedData.getDefaultSelectedCurrency().getCountryCode(),amountDetailRelatedData.getDefaultSelectedCurrency().getCurrencyCode()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
|
|
|
switch (v.getId()) { |
|
|
|
case R.id.sendAmountEdTxt: |
|
|
|
if (actionId == EditorInfo.IME_ACTION_DONE) { |
|
|
|
hideKeyBoard(); |
|
|
|
shouldCaulatedByRecipient = false; |
|
|
|
if (validateAmountIsNotEmpty(sendAmountEdTxt.getText().toString())) |
|
|
|
getForex(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
|
|
|
|
case R.id.receiveAmountEdTxt: |
|
|
|
if (actionId == EditorInfo.IME_ACTION_DONE) { |
|
|
|
hideKeyBoard(); |
|
|
|
shouldCaulatedByRecipient = true; |
|
|
|
if (validateAmountIsNotEmpty(receiveAmountEdTxt.getText().toString())) |
|
|
|
getForex(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public class ExchangeRateCalcObserver extends GenericApiObserverResponse<ExchangeCalculationApiResponse> { |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onSuccess(ExchangeCalculationApiResponse exchangeCalculationApiResponse) { |
|
|
|
if (exchangeCalculationApiResponse.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) { |
|
|
|
ExchangeCalculationModel data = exchangeCalculationApiResponse.getData(); |
|
|
|
String transferAmount = data.getScCharge(); |
|
|
|
String exRate = data.getExRateDisplay(); |
|
|
|
String recipientAmount = data.getpAmt(); |
|
|
|
String sendAmount = data.getCollAmt(); |
|
|
|
String sendingCurrency = data.getCollCurr(); |
|
|
|
|
|
|
|
String transferDisplay = " - " + transferAmount + " " + sendingCurrency + " (Transfer Fee Included)"; |
|
|
|
String exRateDisplay = " " + exRate + " (Current Exchange Rate)"; |
|
|
|
|
|
|
|
showTransferfeeAndExRate(transferDisplay, exRateDisplay); |
|
|
|
showSendAndRecieveAmount(sendAmount, recipientAmount); |
|
|
|
} else |
|
|
|
showPopUpMessage(exchangeCalculationApiResponse.getMsg(), CustomAlertDialog.AlertType.FAILED, null); |
|
|
|
if(isUIReady()) { |
|
|
|
showProgressBar(false, ""); |
|
|
|
if (exchangeCalculationApiResponse.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) { |
|
|
|
ExchangeCalculationModel data = exchangeCalculationApiResponse.getData(); |
|
|
|
String transferAmount = data.getScCharge(); |
|
|
|
String exRate = data.getExRateDisplay(); |
|
|
|
String recipientAmount = data.getpAmt(); |
|
|
|
String sendAmount = data.getCollAmt(); |
|
|
|
String sendingCurrency = data.getCollCurr(); |
|
|
|
|
|
|
|
String transferDisplay = " - " + transferAmount + " " + sendingCurrency + " (Transfer Fee Included)"; |
|
|
|
String exRateDisplay = " " + exRate + " (Current Exchange Rate)"; |
|
|
|
|
|
|
|
showTransferfeeAndExRate(transferDisplay, exRateDisplay); |
|
|
|
showSendAndRecieveAmount(sendAmount, recipientAmount); |
|
|
|
} else |
|
|
|
showPopUpMessage(exchangeCalculationApiResponse.getMsg(), CustomAlertDialog.AlertType.FAILED, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailed(String message) { |
|
|
|
showProgressBar(false,""); |
|
|
|
showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, null); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onConnectionNotEstablished(String message) { |
|
|
|
showProgressBar(false,""); |
|
|
|
showPopUpMessage(message, CustomAlertDialog.AlertType.NO_INTERNET, null); |
|
|
|
} |
|
|
|
} |
|
|
|