From 2854b803678fc8fce0adf88e70cd44da94c82f91 Mon Sep 17 00:00:00 2001 From: preyearegmi Date: Thu, 23 Aug 2018 18:22:06 +0900 Subject: [PATCH] Flow done --- .../view/ExchangeMethodV2Activity.java | 101 ++++++++++-------- .../layout/activity_exchange_method_v2.xml | 2 + 2 files changed, 59 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/view/ExchangeMethodV2Activity.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/view/ExchangeMethodV2Activity.java index 44d90cdb..994d1b2c 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/view/ExchangeMethodV2Activity.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/view/ExchangeMethodV2Activity.java @@ -83,8 +83,8 @@ public class ExchangeMethodV2Activity extends BaseActivity implements PaymentMod @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - this.sendAmountTextWatcher=new SendAmountTextWatcher(); - this.recepientAmountTextWatcher=new RecipientAmountTextWatcher(); + this.sendAmountTextWatcher = new SendAmountTextWatcher(); + this.recepientAmountTextWatcher = new RecipientAmountTextWatcher(); setContentView(R.layout.activity_exchange_method_v2); ButterKnife.bind(this); init(); @@ -106,13 +106,9 @@ public class ExchangeMethodV2Activity extends BaseActivity implements PaymentMod } - - - private void showPaymentService(boolean action, List paymentModeList) - { - if(paymentModeRvAdapter!=null&&action&&paymentModeList.size()>0) - { - if(paymentModeViewContainer.getVisibility()!=View.VISIBLE) + private void showPaymentService(boolean action, List paymentModeList) { + if (paymentModeRvAdapter != null && action && paymentModeList.size() > 0) { + if (paymentModeViewContainer.getVisibility() != View.VISIBLE) paymentModeViewContainer.setVisibility(View.VISIBLE); paymentModeRvAdapter.setData(paymentModeList); paymentModeRvAdapter.setSelectedItem(0); @@ -139,7 +135,8 @@ public class ExchangeMethodV2Activity extends BaseActivity implements PaymentMod super.onStart(); countrySelectionSpinner.setOnClickListener(this); exRateCalculateButton.setOnClickListener(this); - registerTextWatchers(true); + registerTextWatchers(true); + } @@ -161,7 +158,7 @@ public class ExchangeMethodV2Activity extends BaseActivity implements PaymentMod public void onCountrySelected(CountryPaymentService countryPaymentService) { this.selectedCountryPaymentService = countryPaymentService; showSelectedRecipient(countryPaymentService.getCountryCode(), countryPaymentService.getCurrency()); - showPaymentService(true,countryPaymentService.getServiceAvailable()); + showPaymentService(true, countryPaymentService.getServiceAvailable()); if (this.countryListingDialog != null) this.countryListingDialog.dismiss(); } @@ -169,9 +166,9 @@ public class ExchangeMethodV2Activity extends BaseActivity implements PaymentMod private void showSelectedRecipient(String selectedCountryCode, String selectedCountryCurrency) { int flagResId = CountryFlagMapper.getFlagFromCountryCode(selectedCountryCode); if (flagResId != -1) - this.recepientFlagImageView.setBackgroundResource(CountryFlagMapper.getFlagFromCountryCode(selectedCountryCode)); - if(selectedCountryCurrency!=null) - this.recepientCurrencyTextView.setText(selectedCountryCurrency); + this.recepientFlagImageView.setBackgroundResource(CountryFlagMapper.getFlagFromCountryCode(selectedCountryCode)); + if (selectedCountryCurrency != null) + this.recepientCurrencyTextView.setText(selectedCountryCurrency); } @Override @@ -180,41 +177,39 @@ public class ExchangeMethodV2Activity extends BaseActivity implements PaymentMod case R.id.countrySelectionSpinner: showCountryListinDialog(); break; - case R.id.exRateCalculateButton: - prepareToGetForex(); - break; + case R.id.exRateCalculateButton: + prepareToGetForex(); + break; } } @Override public void showCountryServiceData(List countryPaymentServiceList, CountryPaymentService defaultCountryPaymentService, String seedValue) { - if(defaultCountryPaymentService!=null) { + if (defaultCountryPaymentService != null) { //Update some flag here for forexchange (i.e either recieve) if (seedValue != null) { this.recieveMoneyEditText.setText(seedValue); } showSelectedRecipient(defaultCountryPaymentService.getCountryCode(), defaultCountryPaymentService.getCurrency()); - showPaymentService(true,defaultCountryPaymentService.getServiceAvailable()); + showPaymentService(true, defaultCountryPaymentService.getServiceAvailable()); this.selectedCountryPaymentService = defaultCountryPaymentService; - this.selectedPaymentMode=defaultCountryPaymentService.getServiceAvailable().get(0); - shouldCaulatedByRecipient=true; + this.selectedPaymentMode = defaultCountryPaymentService.getServiceAvailable().get(0); + shouldCaulatedByRecipient = true; - } - else - { + } else { //Update some flag here for forexchange (i.e either send) if (seedValue != null) { this.sendMoneyEditText.setText(seedValue); recieveMoneyEditText.setText(""); } //We are taking first item as default as we don't have any default item enlisted - CountryPaymentService firstSelectedItem=countryPaymentServiceList.get(0); + CountryPaymentService firstSelectedItem = countryPaymentServiceList.get(0); showSelectedRecipient(firstSelectedItem.getCountryCode(), firstSelectedItem.getCurrency()); - showPaymentService(true,firstSelectedItem.getServiceAvailable()); + showPaymentService(true, firstSelectedItem.getServiceAvailable()); this.selectedCountryPaymentService = firstSelectedItem; - this.selectedPaymentMode=firstSelectedItem.getServiceAvailable().get(0); - shouldCaulatedByRecipient=true; + this.selectedPaymentMode = firstSelectedItem.getServiceAvailable().get(0); + shouldCaulatedByRecipient = true; } @@ -222,23 +217,36 @@ public class ExchangeMethodV2Activity extends BaseActivity implements PaymentMod prepareToGetForex(); } - private void registerTextWatchers(boolean action) - { - if(action) - { + private void registerTextWatchers(boolean action) { + if (action) { sendMoneyEditText.addTextChangedListener(sendAmountTextWatcher); recieveMoneyEditText.addTextChangedListener(recepientAmountTextWatcher); - } - else - { + } else { sendMoneyEditText.addTextChangedListener(null); recieveMoneyEditText.addTextChangedListener(null); } } - private void prepareToGetForex() - { - this.presenter.getForex(this.selectedCountryPaymentService,this.selectedPaymentMode,recieveMoneyEditText.getText().toString(),sendMoneyEditText.getText().toString(),shouldCaulatedByRecipient); + 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 void prepareToGetForex() { + this.presenter.getForex(this.selectedCountryPaymentService, this.selectedPaymentMode, recieveMoneyEditText.getText().toString(), sendMoneyEditText.getText().toString(), shouldCaulatedByRecipient); } @@ -252,8 +260,7 @@ public class ExchangeMethodV2Activity extends BaseActivity implements PaymentMod } - private class SendAmountTextWatcher implements TextWatcher - { + private class SendAmountTextWatcher implements TextWatcher { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -267,11 +274,14 @@ public class ExchangeMethodV2Activity extends BaseActivity implements PaymentMod @Override public void afterTextChanged(Editable s) { - shouldCaulatedByRecipient=false; + shouldCaulatedByRecipient = false; + registerAvailableTextWatchersForEditText(recieveMoneyEditText,false); + recieveMoneyEditText.setText(""); + registerAvailableTextWatchersForEditText(recieveMoneyEditText,true); } } - private class RecipientAmountTextWatcher implements TextWatcher - { + + private class RecipientAmountTextWatcher implements TextWatcher { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -285,7 +295,10 @@ public class ExchangeMethodV2Activity extends BaseActivity implements PaymentMod @Override public void afterTextChanged(Editable s) { - shouldCaulatedByRecipient=true; + shouldCaulatedByRecipient = true; + registerAvailableTextWatchersForEditText(sendMoneyEditText,false); + sendMoneyEditText.setText(""); + registerAvailableTextWatchersForEditText(sendMoneyEditText,true); } } diff --git a/app/src/main/res/layout/activity_exchange_method_v2.xml b/app/src/main/res/layout/activity_exchange_method_v2.xml index 6bd17eb2..2253a013 100644 --- a/app/src/main/res/layout/activity_exchange_method_v2.xml +++ b/app/src/main/res/layout/activity_exchange_method_v2.xml @@ -47,6 +47,7 @@ android:inputType="numberDecimal" android:gravity="center_vertical" android:backgroundTint="@android:color/transparent" + android:hint="10,000,000" android:textColor="@color/colorPrimary" android:imeOptions="actionDone" android:textSize="21sp"/> @@ -211,6 +212,7 @@ android:inputType="numberDecimal" android:gravity="center_vertical" android:imeOptions="actionDone" + android:hint="10,000,000" android:backgroundTint="@android:color/transparent" android:textColor="@color/colorPrimary" android:textSize="21sp"/>