Browse Source

Exchange rate calculator default amount fetch fixes

master
preyearegmi 6 years ago
parent
commit
4a8455dec1
  1. 39
      app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2Presenter.java
  2. 4
      app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2PresenterInterface.java
  3. 32
      app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/view/ExchangeMethodV2Activity.java

39
app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2Presenter.java

@ -18,6 +18,7 @@ import com.gmeremit.online.gmeremittance_native.utils.https.GenericApiObserverRe
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
public class ExchangeRateV2Presenter extends BasePresenter implements ExchangeRateV2PresenterInterface, ExchangeRateV2InteractorInterface { public class ExchangeRateV2Presenter extends BasePresenter implements ExchangeRateV2PresenterInterface, ExchangeRateV2InteractorInterface {
@ -73,6 +74,20 @@ public class ExchangeRateV2Presenter extends BasePresenter implements ExchangeRa
} }
@Override
public void getDefaultReceivingAmountForSelectedCurrency(CountryPaymentService countryPaymentService) {
String nativeCountryCode = countryPaymentService.getCountryCode();
String preferredCurrency= countryPaymentService.getCurrency();
compositeDisposables.add(
this.gateway.getAllSeedVAlues().flatMap(seedValueList -> {
for (CountryPaymentServiceSeedValueModel seedValueModel : seedValueList) {
if (seedValueModel.getCountryCode().equalsIgnoreCase(nativeCountryCode)&&seedValueModel.getCurrency().equalsIgnoreCase(preferredCurrency))
return Observable.just(seedValueModel);
}
return Observable.just(new CountryPaymentServiceSeedValueModel(null, null, null));
}).subscribeWith(new DefaultRecievingAmountObserver()));
}
@Override @Override
public void onViewDestroyed() { public void onViewDestroyed() {
super.onViewDestroyed(); super.onViewDestroyed();
@ -216,4 +231,28 @@ public class ExchangeRateV2Presenter extends BasePresenter implements ExchangeRa
} }
} }
public class DefaultRecievingAmountObserver extends DisposableObserver<CountryPaymentServiceSeedValueModel>
{
@Override
public void onNext(CountryPaymentServiceSeedValueModel countryPaymentServiceSeedValueModel) {
String receivingAmount=countryPaymentServiceSeedValueModel.getRecipientSeedValue();
if(receivingAmount!=null)
view.updateReceivingAmountAndFetchExchangeRate(Utils.formatCurrency(receivingAmount));
else
view.fallbackToSendingAmountAndFetchExchangeRate();
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
}
} }

4
app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2PresenterInterface.java

@ -15,6 +15,7 @@ public interface ExchangeRateV2PresenterInterface extends BasePresenterInterface
void getForex(CountryPaymentService selectedCountryPaymentService, PaymentMode selectedPaymentMode, String recieveAmount, String sendMoneyEditTextText, boolean shouldCaulatedByRecipient); void getForex(CountryPaymentService selectedCountryPaymentService, PaymentMode selectedPaymentMode, String recieveAmount, String sendMoneyEditTextText, boolean shouldCaulatedByRecipient);
void getDefaultReceivingAmountForSelectedCurrency(CountryPaymentService countryPaymentService);
interface ExchangeRateV2ContractInterface extends BaseContractInterface interface ExchangeRateV2ContractInterface extends BaseContractInterface
{ {
@ -28,5 +29,8 @@ public interface ExchangeRateV2PresenterInterface extends BasePresenterInterface
void updateExchangeRates(String recipientAmount, String sendAmount, String transferDisplay, String exRateDisplay); void updateExchangeRates(String recipientAmount, String sendAmount, String transferDisplay, String exRateDisplay);
void clearCurrencyData(); void clearCurrencyData();
void updateReceivingAmountAndFetchExchangeRate(String amount);
void fallbackToSendingAmountAndFetchExchangeRate();
} }
} }

32
app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/view/ExchangeMethodV2Activity.java

@ -210,6 +210,7 @@ public class ExchangeMethodV2Activity extends BaseActivity implements PaymentMod
} }
//TODO Implementation for calculating exchange rate on the basis of provided default receiving amount for native country only //
@Override @Override
public void onCountrySelected(CountryPaymentService countryPaymentService) { public void onCountrySelected(CountryPaymentService countryPaymentService) {
this.selectedCountryPaymentService = countryPaymentService; this.selectedCountryPaymentService = countryPaymentService;
@ -225,6 +226,37 @@ public class ExchangeMethodV2Activity extends BaseActivity implements PaymentMod
} }
} }
//TODO Implementation for calculating exchange rate on the basis of provided default receiving amount for corresponding currency.
// @Override
// public void onCountrySelected(CountryPaymentService countryPaymentService) {
// this.selectedCountryPaymentService = countryPaymentService;
// showSelectedRecipient(countryPaymentService.getCountryCode(), countryPaymentService.getCurrency());
// if (this.countryListingDialog != null) {
// this.countryListingDialog.hideKeyboard();
// this.countryListingDialog.dismiss();
// }
// this.presenter.getDefaultReceivingAmountForSelectedCurrency(countryPaymentService);
// }
@Override
public void updateReceivingAmountAndFetchExchangeRate(String amount) {
registerAvailableTextWatchersForEditText(recieveMoneyEditText, true);
recieveMoneyEditText.setText(amount);
shouldCaulatedByRecipient = true;
registerAvailableTextWatchersForEditText(recieveMoneyEditText, false);
showPaymentService(true, this.selectedCountryPaymentService.getServiceAvailable());
}
@Override
public void fallbackToSendingAmountAndFetchExchangeRate() {
registerAvailableTextWatchersForEditText(recieveMoneyEditText, false);
recieveMoneyEditText.setText("");
shouldCaulatedByRecipient = true;
registerAvailableTextWatchersForEditText(recieveMoneyEditText, true);
showPaymentService(true, this.selectedCountryPaymentService.getServiceAvailable());
}
private void showSelectedRecipient(String selectedCountryCode, String selectedCountryCurrency) { private void showSelectedRecipient(String selectedCountryCode, String selectedCountryCurrency) {
int flagResId = CountryFlagMapper.getFlagFromCountryCode(selectedCountryCode); int flagResId = CountryFlagMapper.getFlagFromCountryCode(selectedCountryCode);
if (flagResId != -1) if (flagResId != -1)

Loading…
Cancel
Save