Browse Source

Text change listener added

master
Preyea Regmi 5 years ago
parent
commit
f1a3ef16ee
  1. 47
      app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/presenter/SplashScreenPresenter.java
  2. 14
      app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/presenter/SplashScreenPresenterInterface.java
  3. 67
      app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/view/SplashScreen.java

47
app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/presenter/SplashScreenPresenter.java

@ -144,6 +144,26 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen
calcExrate();
}
@Override
public void setPAmount(String amount) {
this.pAmount=Utils.removeCommaFromAmount(amount);
this.cAmount="";
view.showCollectionAmount("");
}
@Override
public void setCAmount(String amount) {
this.cAmount=Utils.removeCommaFromAmount(amount);
this.pAmount="";
view.showPayoutAmount("");
}
@Override
public void setCalcByPayoutAmount(boolean action) {
calcByPayoutAmount=action;
}
@Override
public List<CountryPaymentService> getAvailableCountryRelatedCurrency() {
return this.countryRelatedCurrencyList;
@ -170,13 +190,20 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen
}
}));
view.updateCollectionAmount(Utils.formatCurrency(cAmount));
view.updatePayoutAmount(Utils.formatCurrencyWithoutTruncatingDecimal(pAmount));
view.showCollectionAmount(Utils.formatCurrency(cAmount));
view.showPayoutAmount(Utils.formatCurrencyWithoutTruncatingDecimal(pAmount));
calcExrate();
}
private void calcExrate() {
@Override
public void calcExrate() {
if(!validateAmount())
{
view.showToastMessage(getStringfromStringId(R.string.sending_amount_error));
return;
}
String calculateFlag = calcByPayoutAmount ? Constants.CALC_BY_RECIPEINT : Constants.CALC_BY_SENDER;
view.hideKeyBoard();
compositeDisposables.add(
this.gateway.sendDataForForexCalculation(gateway.getAuth(),
sendCountryDefault,
@ -192,6 +219,12 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen
);
}
private boolean validateAmount() {
if(calcByPayoutAmount&&pAmount.length()>1)
return true;
else return !calcByPayoutAmount && cAmount.length() > 1;
}
private Observable<CountryPaymentServiceSeedValueModel> getDefaultValue(String countryCode) {
return this.gateway.getAllSeedVAlues().flatMap(seedValueList -> {
@ -278,9 +311,9 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen
private void updateViewWithDefaulValues() {
if (calcByPayoutAmount)
view.updatePayoutAmount(Utils.formatCurrencyWithoutTruncatingDecimal(pAmount));
view.showPayoutAmount(Utils.formatCurrencyWithoutTruncatingDecimal(pAmount));
else
view.updateCollectionAmount(Utils.formatCurrency(cAmount));
view.showCollectionAmount(Utils.formatCurrency(cAmount));
view.showSelectedPayoutMode(selectedCountryPaymentService.getServiceAvailable(), 0);
@ -306,8 +339,8 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen
String exRateDisplay = " " + exRate + " (" + getStringfromStringId(R.string.current_exchange_rate_text) + ")";
view.showTransferChargeAndExrate(transferDisplay, exRateDisplay, false);
view.updatePayoutAmount(Utils.formatCurrencyWithoutTruncatingDecimal(pAmount));
view.updateCollectionAmount(Utils.formatCurrency(cAmount));
view.showPayoutAmount(Utils.formatCurrencyWithoutTruncatingDecimal(pAmount));
view.showCollectionAmount(Utils.formatCurrency(cAmount));
} else {
view.showTransferChargeAndExrate("", "", false);

14
app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/presenter/SplashScreenPresenterInterface.java

@ -25,10 +25,18 @@ public interface SplashScreenPresenterInterface extends BasePresenterInterface {
void setPaymentMode(PaymentMode paymentMode);
void setPAmount(String amount);
void setCAmount(String amount);
void setCalcByPayoutAmount(boolean action);
List<CountryPaymentService> getAvailableCountryRelatedCurrency();
void setCountryRelatedCurrencyData(CountryPaymentService countryPaymentService);
void calcExrate();
interface SplashScreenContractInterfacee extends BaseContractInterface
{
@ -36,16 +44,14 @@ public interface SplashScreenPresenterInterface extends BasePresenterInterface {
void updateLanguageData(List<LanguageModel> languageModels);
//TODO for mocking
Context getContext();
void updateFlagImage(int flagFromCountryCode);
void showAppVersion(String appVersion);
void updatePayoutAmount(String pAmount);
void updateCollectionAmount(String pAmount);
void showPayoutAmount(String pAmount);
void showCollectionAmount(String pAmount);
void showSelectedPayoutMode(List<PaymentMode> serviceAvailable, int selectedIndex);

67
app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/view/SplashScreen.java

@ -19,18 +19,20 @@ import android.support.v4.view.ViewPropertyAnimatorListenerAdapter;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AnticipateOvershootInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.OvershootInterpolator;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.gmeremit.online.gmeremittance_native.R;
import com.gmeremit.online.gmeremittance_native.base.BaseActivity;
import com.gmeremit.online.gmeremittance_native.customwidgets.CurrencyFormatterTextWatcher;
import com.gmeremit.online.gmeremittance_native.customwidgets.exchangecountrylistingdialog.CountryFlagMapper;
import com.gmeremit.online.gmeremittance_native.customwidgets.exchangecountrylistingdialog.ExchangeRateCurrencyListingDialog;
import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.CountryPaymentService;
@ -52,7 +54,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
public class SplashScreen extends BaseActivity implements View.OnClickListener, LanguageSelectionRVAdapter.LanguageSelectionListener, SplashScreenPresenterInterface.SplashScreenContractInterfacee, PayoutModeSelectionRVAdapter.OnPaymentModeSelectionListener {
public class SplashScreen extends BaseActivity implements View.OnClickListener, LanguageSelectionRVAdapter.LanguageSelectionListener, SplashScreenPresenterInterface.SplashScreenContractInterfacee, PayoutModeSelectionRVAdapter.OnPaymentModeSelectionListener, TextView.OnEditorActionListener {
@BindView(R.id.view_pager)
ConstraintLayout view_pager;
@ -157,8 +159,8 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener,
languageViewTransitionManager = new LanguageViewTransitionManager(this);
initLanguageRV();
initPayoutModeRV();
sendMoneyTextWatcher = new SendAmountTextWatcher();
receiveMoneyTextWatcher = new ReceiveAmountTextWatcher();
sendMoneyTextWatcher = new SendAmountTextWatcher(sendAmountEdTxt);
receiveMoneyTextWatcher = new ReceiveAmountTextWatcher(receiveAmountEdTxt);
}
@ -210,6 +212,8 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener,
selectedLanguageText.setOnClickListener(this);
selectedLanguageIcon.setOnClickListener(this);
countrySelectionSpinner.setOnClickListener(this);
receiveAmountEdTxt.setOnEditorActionListener(this);
sendAmountEdTxt.setOnEditorActionListener(this);
}
@Override
@ -221,6 +225,8 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener,
selectedLanguageText.setOnClickListener(null);
selectedLanguageIcon.setOnClickListener(null);
countrySelectionSpinner.setOnClickListener(null);
receiveAmountEdTxt.setOnEditorActionListener(this);
sendAmountEdTxt.setOnEditorActionListener(this);
}
@ -320,14 +326,14 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener,
}
@Override
public void updatePayoutAmount(String pAmount) {
public void showPayoutAmount(String pAmount) {
startReceiveAmountListener(false);
receiveAmountEdTxt.setText(pAmount);
startReceiveAmountListener(true);
}
@Override
public void updateCollectionAmount(String pAmount) {
public void showCollectionAmount(String pAmount) {
startSendAmountListener(false);
sendAmountEdTxt.setText(pAmount);
startSendAmountListener(true);
@ -361,9 +367,7 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener,
}
}).start();
}).start();
}
else
{
} else {
transferFeeTxtView.setText(chargeAmount);
exchangeRateTxtView.setText(exRate);
}
@ -382,6 +386,33 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener,
presenter.setPaymentMode(selectedData);
}
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
switch (v.getId()) {
case R.id.sendAmountEdTxt:
if (actionId == EditorInfo.IME_ACTION_DONE) {
presenter.setCalcByPayoutAmount(false);
presenter.calcExrate();
return true;
}
case R.id.receiveAmountEdTxt:
if (actionId == EditorInfo.IME_ACTION_DONE) {
presenter.setCalcByPayoutAmount(true);
presenter.calcExrate();
return true;
}
}
return false;
}
@Override
public void onPointerCaptureChanged(boolean hasCapture) {
}
/**
* Helper class to switch between different state of this activity layout.
*/
@ -550,7 +581,11 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener,
}
class SendAmountTextWatcher implements TextWatcher {
class SendAmountTextWatcher extends CurrencyFormatterTextWatcher {
public SendAmountTextWatcher(EditText editText) {
super(editText);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@ -564,11 +599,16 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener,
@Override
public void afterTextChanged(Editable s) {
super.afterTextChanged(s);
presenter.setCAmount(s.toString());
}
}
class ReceiveAmountTextWatcher implements TextWatcher {
class ReceiveAmountTextWatcher extends CurrencyFormatterTextWatcher {
public ReceiveAmountTextWatcher(EditText editText) {
super(editText);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@ -582,7 +622,8 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener,
@Override
public void afterTextChanged(Editable s) {
super.afterTextChanged(s);
presenter.setPAmount(s.toString());
}
}

Loading…
Cancel
Save