|
|
@ -21,7 +21,6 @@ import com.gmeremit.online.gmeremittance_native.utils.https.GenericApiObserverRe |
|
|
|
import com.gmeremit.online.gmeremittance_native.utils.security.SignatureCheck; |
|
|
|
import com.scottyab.rootbeer.RootBeer; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
@ -38,12 +37,15 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen |
|
|
|
private SplashScreenContractInterfacee view; |
|
|
|
private List<LanguageModel> languageModels; |
|
|
|
private final CompositeDisposable compositeDisposables; |
|
|
|
private final String sendCountryDefault = "118"; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Exrate Related Data |
|
|
|
*/ |
|
|
|
private List<CountryPaymentService> payoutModeRelatedDataList; |
|
|
|
private CountryPaymentService selectedPayoutModeData; |
|
|
|
private List<CountryPaymentService> countryRelatedCurrencyList; |
|
|
|
private CountryPaymentService selectedCountryPaymentService; |
|
|
|
private PaymentMode selectedPaymentMode; |
|
|
|
private boolean calcByPayoutAmount; |
|
|
|
private String cAmount; |
|
|
|
private String pAmount; |
|
|
@ -54,6 +56,8 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen |
|
|
|
this.gateway = new SplashScreenGateway(this); |
|
|
|
rootBeer = new RootBeer(view.getContext()); |
|
|
|
this.compositeDisposables = new CompositeDisposable(); |
|
|
|
cAmount = ""; |
|
|
|
pAmount = ""; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -85,7 +89,6 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean checkIfAppSafe() { |
|
|
|
boolean isSafe = false; |
|
|
|
try { |
|
|
@ -126,7 +129,7 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen |
|
|
|
@Override |
|
|
|
public void getExrateRelatedData() { |
|
|
|
compositeDisposables.add( |
|
|
|
Observable.zip(getPaymentServiceInfo(), getDefaultValue(), PaymentServiceData::new) |
|
|
|
Observable.zip(getPaymentServiceInfo(), getDefaultValue(this.gateway.getPreferredCountryCode()), PaymentServiceData::new) |
|
|
|
.delay(300, TimeUnit.MILLISECONDS) |
|
|
|
// .doOnSubscribe(disposable -> this.view.showProgressBar(true, getStringfromStringId(R.string.processing_request_text))) |
|
|
|
// .doFinally(() -> this.view.showProgressBar(false, "")) |
|
|
@ -135,12 +138,66 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
private Observable<CountryPaymentServiceSeedValueModel> getDefaultValue() { |
|
|
|
@Override |
|
|
|
public void setPaymentMode(PaymentMode paymentMode) { |
|
|
|
this.selectedPaymentMode = paymentMode; |
|
|
|
calcExrate(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<CountryPaymentService> getAvailableCountryRelatedCurrency() { |
|
|
|
return this.countryRelatedCurrencyList; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void setCountryRelatedCurrencyData(CountryPaymentService countryPaymentService) { |
|
|
|
this.selectedCountryPaymentService = countryPaymentService; |
|
|
|
selectedPaymentMode = selectedCountryPaymentService.getServiceAvailable().get(0); |
|
|
|
view.showSelectedPayoutMode(selectedCountryPaymentService.getServiceAvailable(), 0); |
|
|
|
view.showSelectedPayoutCurrency(selectedCountryPaymentService); |
|
|
|
pAmount = ""; |
|
|
|
cAmount = ""; |
|
|
|
|
|
|
|
compositeDisposables.add(getDefaultValue(selectedCountryPaymentService.getCountryCode()).subscribe(countryPaymentServiceSeedValueModel -> { |
|
|
|
if (countryPaymentServiceSeedValueModel.getRecipientSeedValue() != null && |
|
|
|
countryPaymentServiceSeedValueModel.getCountryCode().equalsIgnoreCase(countryPaymentService.getCountryCode()) |
|
|
|
&& countryPaymentServiceSeedValueModel.getCurrency().equalsIgnoreCase(countryPaymentService.getCurrency())) { |
|
|
|
calcByPayoutAmount = true; |
|
|
|
pAmount = countryPaymentServiceSeedValueModel.getRecipientSeedValue(); |
|
|
|
} else { |
|
|
|
calcByPayoutAmount = false; |
|
|
|
cAmount = Constants.DEFAULT_EXCHANGE_SEND_AMOUNT; |
|
|
|
} |
|
|
|
})); |
|
|
|
|
|
|
|
view.updateCollectionAmount(Utils.formatCurrency(cAmount)); |
|
|
|
view.updatePayoutAmount(Utils.formatCurrencyWithoutTruncatingDecimal(pAmount)); |
|
|
|
calcExrate(); |
|
|
|
} |
|
|
|
|
|
|
|
private void calcExrate() { |
|
|
|
String calculateFlag = calcByPayoutAmount ? Constants.CALC_BY_RECIPEINT : Constants.CALC_BY_SENDER; |
|
|
|
compositeDisposables.add( |
|
|
|
this.gateway.sendDataForForexCalculation(gateway.getAuth(), |
|
|
|
sendCountryDefault, |
|
|
|
gateway.getUserPreferredCurrency(), selectedCountryPaymentService.getCurrency(), |
|
|
|
Utils.removeCommaFromAmount(cAmount), Utils.removeCommaFromAmount(pAmount), selectedPaymentMode.getId(), calculateFlag, selectedCountryPaymentService.getCountry(), |
|
|
|
selectedCountryPaymentService.getCountryId() |
|
|
|
).doOnSubscribe(disposable -> this.view.showProgressBar(true, getStringfromStringId(R.string.processing_request_text))) |
|
|
|
.doOnError((err) -> this.view.showProgressBar(false, "")) |
|
|
|
.doFinally(() -> this.view.showProgressBar(false, "")) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
.observeOn(AndroidSchedulers.mainThread()) |
|
|
|
.subscribeWith(new ExchangeRateCalcObserver()) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
private Observable<CountryPaymentServiceSeedValueModel> getDefaultValue(String countryCode) { |
|
|
|
|
|
|
|
return this.gateway.getAllSeedVAlues().flatMap(seedValueList -> { |
|
|
|
String preferredLanguage = this.gateway.getPreferredCountryCode(); |
|
|
|
String preferredLanguage = countryCode; |
|
|
|
if (preferredLanguage == null || preferredLanguage.length() < 1) |
|
|
|
preferredLanguage="NP"; |
|
|
|
preferredLanguage = "NP"; |
|
|
|
for (CountryPaymentServiceSeedValueModel seedValueModel : seedValueList) { |
|
|
|
if (seedValueModel.getCountryCode().equalsIgnoreCase(preferredLanguage)) |
|
|
|
return Observable.just(seedValueModel); |
|
|
@ -159,31 +216,38 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onSuccess(PaymentServiceData paymentServiceApiResponse) { |
|
|
|
if (paymentServiceApiResponse.getPaymentServiceApiResponse().getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)&&paymentServiceApiResponse.getPaymentServiceApiResponse().getCountryPaymentServices().size()>0) { |
|
|
|
if (paymentServiceApiResponse.getPaymentServiceApiResponse().getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2) && paymentServiceApiResponse.getPaymentServiceApiResponse().getCountryPaymentServices().size() > 0) { |
|
|
|
CountryPaymentServiceSeedValueModel seedValueModel = paymentServiceApiResponse.getCountryPaymentServiceSeedValueModel(); |
|
|
|
payoutModeRelatedDataList=paymentServiceApiResponse.getPaymentServiceApiResponse().getCountryPaymentServices(); |
|
|
|
countryRelatedCurrencyList = paymentServiceApiResponse.getPaymentServiceApiResponse().getCountryPaymentServices(); |
|
|
|
try { |
|
|
|
selectedPayoutModeData = paymentServiceApiResponse.getPaymentServiceApiResponse().getCountryPaymentServiceFromCountryCodeAndCurrency(seedValueModel.getCountryCode(), seedValueModel.getCurrency()); |
|
|
|
} |
|
|
|
catch(Exception e) |
|
|
|
{ |
|
|
|
selectedPayoutModeData=null; |
|
|
|
selectedCountryPaymentService = paymentServiceApiResponse.getPaymentServiceApiResponse().getCountryPaymentServiceFromCountryCodeAndCurrency(seedValueModel.getCountryCode(), seedValueModel.getCurrency()); |
|
|
|
} catch (Exception e) { |
|
|
|
selectedCountryPaymentService = null; |
|
|
|
} |
|
|
|
|
|
|
|
if (selectedPayoutModeData == null || selectedPayoutModeData.getCountryCode() == null || selectedPayoutModeData.getCountry() == null || selectedPayoutModeData.getCurrency() == null) { |
|
|
|
if (selectedCountryPaymentService == null || selectedCountryPaymentService.getCountryCode() == null || selectedCountryPaymentService.getCountry() == null || selectedCountryPaymentService.getCurrency() == null) { |
|
|
|
//No Default PAmount available for the selected country |
|
|
|
//Update UI with PAmount,CAmount,SelectedPayoutMode,SelectedCurrency |
|
|
|
//TODO Select a default payoutModeData for this case |
|
|
|
selectedPayoutModeData=paymentServiceApiResponse.getPaymentServiceApiResponse().getDefaultPayoutMode(seedValueModel.getCountryCode()); |
|
|
|
calcByPayoutAmount=false; |
|
|
|
cAmount=Constants.DEFAULT_EXCHANGE_SEND_AMOUNT; |
|
|
|
view.animateToExrateView(SplashScreenPresenter.this::updateViewWithSelectedValues); |
|
|
|
selectedCountryPaymentService = paymentServiceApiResponse.getPaymentServiceApiResponse().getDefaultPayoutMode(seedValueModel.getCountryCode()); |
|
|
|
selectedPaymentMode = selectedCountryPaymentService.getServiceAvailable().get(0); |
|
|
|
calcByPayoutAmount = false; |
|
|
|
cAmount = Constants.DEFAULT_EXCHANGE_SEND_AMOUNT; |
|
|
|
view.animateToExrateView(() -> { |
|
|
|
updateViewWithDefaulValues(); |
|
|
|
calcExrate(); |
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
//No Default PAmount available for the selected country |
|
|
|
//Update UI with PAmount,CAmount,SelectedPayoutMode,SelectedCurrency |
|
|
|
calcByPayoutAmount=true; |
|
|
|
pAmount=seedValueModel.getRecipientSeedValue(); |
|
|
|
view.animateToExrateView(SplashScreenPresenter.this::updateViewWithSelectedValues); |
|
|
|
selectedPaymentMode = selectedCountryPaymentService.getServiceAvailable().get(0); |
|
|
|
calcByPayoutAmount = true; |
|
|
|
pAmount = seedValueModel.getRecipientSeedValue(); |
|
|
|
view.animateToExrateView(() -> { |
|
|
|
updateViewWithDefaulValues(); |
|
|
|
calcExrate(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
@ -211,20 +275,20 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void updateViewWithSelectedValues() { |
|
|
|
if(calcByPayoutAmount) |
|
|
|
|
|
|
|
private void updateViewWithDefaulValues() { |
|
|
|
if (calcByPayoutAmount) |
|
|
|
view.updatePayoutAmount(Utils.formatCurrencyWithoutTruncatingDecimal(pAmount)); |
|
|
|
else |
|
|
|
view.updateCollectionAmount(Utils.formatCurrency(cAmount)); |
|
|
|
|
|
|
|
if(selectedPayoutModeData!=null) { |
|
|
|
view.showSelectedPayoutMode(selectedPayoutModeData.getServiceAvailable(), 0); |
|
|
|
view.showSelectedPayoutCurrency(selectedPayoutModeData); |
|
|
|
} |
|
|
|
view.showTransferCharge("Charge amount 123456"); |
|
|
|
view.showExrate("Ex rate 0.0963"); |
|
|
|
|
|
|
|
view.showSelectedPayoutMode(selectedCountryPaymentService.getServiceAvailable(), 0); |
|
|
|
view.showSelectedPayoutCurrency(selectedCountryPaymentService); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class ExchangeRateCalcObserver extends GenericApiObserverResponse<ExchangeCalculationApiResponse> { |
|
|
|
|
|
|
|
@Override |
|
|
@ -233,16 +297,20 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen |
|
|
|
ExchangeCalculationModel data = exchangeCalculationApiResponse.getData(); |
|
|
|
String transferAmount = Utils.formatCurrency(data.getScCharge()); |
|
|
|
String exRate = data.getExRateDisplay(); |
|
|
|
String recipientAmount = data.getpAmt(); |
|
|
|
String sendAmount = data.getCollAmt(); |
|
|
|
pAmount = data.getpAmt(); |
|
|
|
cAmount = data.getCollAmt(); |
|
|
|
|
|
|
|
String sendingCurrency = data.getCollCurr(); |
|
|
|
|
|
|
|
String transferDisplay = " - " + transferAmount + " " + sendingCurrency + " (" + getStringfromStringId(R.string.transfer_fee_included_text) + ")"; |
|
|
|
String exRateDisplay = " " + exRate + " (" + getStringfromStringId(R.string.current_exchange_rate_text) + ")"; |
|
|
|
|
|
|
|
// view.updateExchangeRates(recipientAmount, sendAmount, transferDisplay, exRateDisplay); |
|
|
|
view.showTransferChargeAndExrate(transferDisplay, exRateDisplay, false); |
|
|
|
view.updatePayoutAmount(Utils.formatCurrencyWithoutTruncatingDecimal(pAmount)); |
|
|
|
view.updateCollectionAmount(Utils.formatCurrency(cAmount)); |
|
|
|
|
|
|
|
} else { |
|
|
|
// view.clearExrateAndServiceCharge(); |
|
|
|
view.showTransferChargeAndExrate("", "", false); |
|
|
|
view.showPopUpMessage(exchangeCalculationApiResponse.getMsg(), CustomAlertDialog.AlertType.FAILED, null); |
|
|
|
} |
|
|
|
} |
|
|
|