|
|
@ -5,6 +5,8 @@ import android.content.Context; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.support.annotation.Nullable; |
|
|
|
import android.support.v4.view.ViewCompat; |
|
|
|
import android.text.Editable; |
|
|
|
import android.text.TextWatcher; |
|
|
|
import android.view.KeyEvent; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.View; |
|
|
@ -23,6 +25,7 @@ import com.gmeremit.online.gmeremittance_native.customwidgets.CustomAlertDialog; |
|
|
|
import com.gmeremit.online.gmeremittance_native.customwidgets.exchangecountrylistingdialog.CountryFlagMapper; |
|
|
|
import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.ExchangeCalculationApiResponse; |
|
|
|
import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.ExchangeCalculationModel; |
|
|
|
import com.gmeremit.online.gmeremittance_native.exchange_rate.view.ExchangeMethodV2Activity; |
|
|
|
import com.gmeremit.online.gmeremittance_native.sendmoneyV2.model.amountdetail.AmountDetailRelatedDataModel; |
|
|
|
import com.gmeremit.online.gmeremittance_native.sendmoneyV2.model.amountdetail.RecipientCurrencyModel; |
|
|
|
import com.gmeremit.online.gmeremittance_native.sendmoneyV2.view.SendMoneyActionListener; |
|
|
@ -40,10 +43,10 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
Button continueBtn; |
|
|
|
|
|
|
|
@BindView(R.id.sendAmountEdTxt) |
|
|
|
EditText sendAmountEdTxt; |
|
|
|
EditText sendMoneyEditText; |
|
|
|
|
|
|
|
@BindView(R.id.receiveAmountEdTxt) |
|
|
|
EditText receiveAmountEdTxt; |
|
|
|
EditText recieveMoneyEditText; |
|
|
|
|
|
|
|
@BindView(R.id.transferFeeTxtView) |
|
|
|
TextView transferFeeTxtView; |
|
|
@ -62,6 +65,7 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
ImageView recepientFlagImageView; |
|
|
|
|
|
|
|
private boolean shouldCaulatedByRecipient; |
|
|
|
private boolean shouldCalculateExRate=true; |
|
|
|
|
|
|
|
CompositeDisposable compositeDisposable = null; |
|
|
|
|
|
|
@ -76,6 +80,8 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
private String selectedRecipientAmount; |
|
|
|
private String selectedSendAmount; |
|
|
|
private String selectedsendingCurrency; |
|
|
|
private SendAmountTextWatcher sendAmountTextWatcher; |
|
|
|
private RecipientAmountTextWatcher recepientAmountTextWatcher; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@ -92,9 +98,12 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
} |
|
|
|
|
|
|
|
private void init() { |
|
|
|
this.sendAmountTextWatcher = new SendAmountTextWatcher(); |
|
|
|
this.recepientAmountTextWatcher = new RecipientAmountTextWatcher(); |
|
|
|
compositeDisposable = new CompositeDisposable(); |
|
|
|
interpolator = new AccelerateDecelerateInterpolator(); |
|
|
|
setupRecyclerView(); |
|
|
|
registerTextWatchers(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -102,8 +111,8 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
public void onStart() { |
|
|
|
super.onStart(); |
|
|
|
continueBtn.setOnClickListener(this); |
|
|
|
receiveAmountEdTxt.setOnEditorActionListener(this); |
|
|
|
sendAmountEdTxt.setOnEditorActionListener(this); |
|
|
|
// recieveMoneyEditText.setOnEditorActionListener(this); |
|
|
|
// sendMoneyEditText.setOnEditorActionListener(this); |
|
|
|
countrySelectionSpinner.setOnClickListener(this); |
|
|
|
} |
|
|
|
|
|
|
@ -111,8 +120,8 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
public void onStop() { |
|
|
|
super.onStop(); |
|
|
|
continueBtn.setOnClickListener(null); |
|
|
|
receiveAmountEdTxt.setOnEditorActionListener(null); |
|
|
|
sendAmountEdTxt.setOnEditorActionListener(null); |
|
|
|
// recieveMoneyEditText.setOnEditorActionListener(null); |
|
|
|
// sendMoneyEditText.setOnEditorActionListener(null); |
|
|
|
countrySelectionSpinner.setOnClickListener(null); |
|
|
|
} |
|
|
|
|
|
|
@ -139,6 +148,7 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
@Override |
|
|
|
public void onDestroy() { |
|
|
|
((SendMoneyActionListener) getActivity()).getPresenter().clearExRateData(); |
|
|
|
registerTextWatchers(false); |
|
|
|
super.onDestroy(); |
|
|
|
if (compositeDisposable != null && !compositeDisposable.isDisposed()) |
|
|
|
compositeDisposable.dispose(); |
|
|
@ -170,15 +180,37 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
public void onClick(View v) { |
|
|
|
switch (v.getId()) { |
|
|
|
case R.id.amountDetailContinueButton: |
|
|
|
if(validateAmountIsNotEmpty(sendAmountEdTxt.getText().toString())) { |
|
|
|
((SendMoneyActionListener) getActivity()).getPresenter().setSendingAmount(sendAmountEdTxt.getText().toString(),selectedsendingCurrency,selectedExRate,selectedTransferAmount); |
|
|
|
((SendMoneyV2Activity) getActivity()).addScreenToSendMoney(R.layout.fragment_verification_send_money_v2, true); |
|
|
|
// if(validateAmountIsNotEmpty(sendMoneyEditText.getText().toString())) { |
|
|
|
// ((SendMoneyActionListener) getActivity()).getPresenter().setSendingAmount(sendMoneyEditText.getText().toString(),selectedsendingCurrency,selectedExRate,selectedTransferAmount); |
|
|
|
// ((SendMoneyV2Activity) getActivity()).addScreenToSendMoney(R.layout.fragment_verification_send_money_v2, true); |
|
|
|
// } |
|
|
|
// else |
|
|
|
// { |
|
|
|
// showToastMessage("Please specify sending amount."); |
|
|
|
// } |
|
|
|
//TODO remove && false |
|
|
|
if(shouldCalculateExRate&&false) |
|
|
|
{ |
|
|
|
if(shouldCaulatedByRecipient&&!validateAmountIsNotEmpty(recieveMoneyEditText.getText().toString())) |
|
|
|
{ |
|
|
|
showToastMessage("Please specify either of the amount."); |
|
|
|
return; |
|
|
|
} |
|
|
|
if(!shouldCaulatedByRecipient&&!validateAmountIsNotEmpty(sendMoneyEditText.getText().toString())) |
|
|
|
{ |
|
|
|
showToastMessage("Please specify either of the amount."); |
|
|
|
return; |
|
|
|
} |
|
|
|
getForex(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
showToastMessage("Please specify sending amount."); |
|
|
|
if(validateAll()) { |
|
|
|
((SendMoneyActionListener) getActivity()).getPresenter().setSendingAmount(sendMoneyEditText.getText().toString(),selectedsendingCurrency,selectedExRate,selectedTransferAmount); |
|
|
|
((SendMoneyV2Activity) getActivity()).addScreenToSendMoney(R.layout.fragment_verification_send_money_v2, true); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
case R.id.countrySelectionSpinner: |
|
|
|
if (!amountDetailRelatedData.getAvailableCurrencyData().isEmpty()) |
|
|
@ -191,7 +223,7 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
private void getForex() { |
|
|
|
compositeDisposable.add( |
|
|
|
((SendMoneyActionListener) getActivity()).getPresenter().getForex( |
|
|
|
receiveAmountEdTxt.getText().toString(), sendAmountEdTxt.getText().toString(), shouldCaulatedByRecipient, amountDetailRelatedData.getDefaultSelectedCurrency().getCurrencyCode() |
|
|
|
recieveMoneyEditText.getText().toString(), sendMoneyEditText.getText().toString(), shouldCaulatedByRecipient, amountDetailRelatedData.getDefaultSelectedCurrency().getCurrencyCode() |
|
|
|
).doOnSubscribe(d -> showProgressBar(true, "Calculating...")) |
|
|
|
.subscribeWith(new ExchangeRateCalcObserver()) |
|
|
|
); |
|
|
@ -222,8 +254,8 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
|
|
|
|
|
|
|
|
private void showSendAndRecieveAmount(String sendAmount, String recieveAmount) { |
|
|
|
this.sendAmountEdTxt.setText(sendAmount); |
|
|
|
this.receiveAmountEdTxt.setText(recieveAmount); |
|
|
|
updateSendAmount(sendAmount); |
|
|
|
updateRecievingAmount(recieveAmount); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean validateAmountIsNotEmpty(String amount) { |
|
|
@ -248,7 +280,7 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
if (actionId == EditorInfo.IME_ACTION_DONE) { |
|
|
|
hideKeyBoard(); |
|
|
|
shouldCaulatedByRecipient = false; |
|
|
|
if (validateAmountIsNotEmpty(sendAmountEdTxt.getText().toString())) |
|
|
|
if (validateAmountIsNotEmpty(sendMoneyEditText.getText().toString())) |
|
|
|
getForex(); |
|
|
|
else |
|
|
|
showToastMessage("Please specify sending amount."); |
|
|
@ -259,7 +291,7 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
if (actionId == EditorInfo.IME_ACTION_DONE) { |
|
|
|
hideKeyBoard(); |
|
|
|
shouldCaulatedByRecipient = true; |
|
|
|
if (validateAmountIsNotEmpty(receiveAmountEdTxt.getText().toString())) |
|
|
|
if (validateAmountIsNotEmpty(recieveMoneyEditText.getText().toString())) |
|
|
|
getForex(); |
|
|
|
else |
|
|
|
showToastMessage("Please specify recieving amount."); |
|
|
@ -339,4 +371,117 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private boolean validateAll() |
|
|
|
{ |
|
|
|
if(validateAmountIsNotEmpty(sendMoneyEditText.getText().toString())) |
|
|
|
{ |
|
|
|
if(validateAmountIsNotEmpty(sendMoneyEditText.getText().toString())) |
|
|
|
return true; |
|
|
|
|
|
|
|
else |
|
|
|
{ |
|
|
|
showToastMessage("Please specify recieving amount."); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
showToastMessage("Please specify sending amount."); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
private void updateButtonToCalculate(boolean action) |
|
|
|
{ |
|
|
|
shouldCalculateExRate=action; |
|
|
|
if(action) |
|
|
|
continueBtn.setText("Calculate"); |
|
|
|
else |
|
|
|
continueBtn.setText("Continue"); |
|
|
|
} |
|
|
|
|
|
|
|
private void updateSendAmount(String amount) |
|
|
|
{ |
|
|
|
registerAvailableTextWatchersForEditText(sendMoneyEditText,false); |
|
|
|
sendMoneyEditText.setText(amount); |
|
|
|
registerAvailableTextWatchersForEditText(sendMoneyEditText,true); |
|
|
|
} |
|
|
|
private void updateRecievingAmount(String amount) |
|
|
|
{ |
|
|
|
registerAvailableTextWatchersForEditText(recieveMoneyEditText,false); |
|
|
|
recieveMoneyEditText.setText(amount); |
|
|
|
registerAvailableTextWatchersForEditText(recieveMoneyEditText,true); |
|
|
|
} |
|
|
|
|
|
|
|
private void registerTextWatchers(boolean action) { |
|
|
|
if (action) { |
|
|
|
if (sendAmountTextWatcher == null) |
|
|
|
sendAmountTextWatcher = new SendAmountTextWatcher(); |
|
|
|
if (recepientAmountTextWatcher == null) |
|
|
|
recepientAmountTextWatcher = new RecipientAmountTextWatcher(); |
|
|
|
|
|
|
|
sendMoneyEditText.addTextChangedListener(sendAmountTextWatcher); |
|
|
|
recieveMoneyEditText.addTextChangedListener(recepientAmountTextWatcher); |
|
|
|
} else { |
|
|
|
sendMoneyEditText.addTextChangedListener(null); |
|
|
|
recieveMoneyEditText.addTextChangedListener(null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void registerAvailableTextWatchersForEditText(EditText editText, boolean action) { |
|
|
|
switch (editText.getId()) { |
|
|
|
case R.id.sendAmountEdTxt: |
|
|
|
if (action) |
|
|
|
sendMoneyEditText.addTextChangedListener(sendAmountTextWatcher); |
|
|
|
else |
|
|
|
sendMoneyEditText.removeTextChangedListener(sendAmountTextWatcher); |
|
|
|
break; |
|
|
|
case R.id.receiveAmountEdTxt: |
|
|
|
if (action) |
|
|
|
recieveMoneyEditText.addTextChangedListener(recepientAmountTextWatcher); |
|
|
|
else |
|
|
|
recieveMoneyEditText.removeTextChangedListener(recepientAmountTextWatcher); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private class SendAmountTextWatcher implements TextWatcher { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void afterTextChanged(Editable s) { |
|
|
|
shouldCaulatedByRecipient = false; |
|
|
|
updateRecievingAmount(""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private class RecipientAmountTextWatcher implements TextWatcher { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void afterTextChanged(Editable s) { |
|
|
|
shouldCaulatedByRecipient = true; |
|
|
|
updateSendAmount(""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |