From 89b521248f455442523644c9586c35a9be3bf072 Mon Sep 17 00:00:00 2001 From: Preyea Regmi Date: Wed, 24 Jul 2019 13:41:07 +0900 Subject: [PATCH] Exrate in splash integration done --- .../adapter/PayoutModeSelectionRVAdapter.java | 2 + .../presenter/SplashScreenPresenter.java | 138 +++++++++++++----- .../SplashScreenPresenterInterface.java | 10 +- .../splash_screen/view/SplashScreen.java | 76 ++++++---- 4 files changed, 161 insertions(+), 65 deletions(-) diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/adapter/PayoutModeSelectionRVAdapter.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/adapter/PayoutModeSelectionRVAdapter.java index 72add440..345424ce 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/adapter/PayoutModeSelectionRVAdapter.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/adapter/PayoutModeSelectionRVAdapter.java @@ -40,6 +40,8 @@ public class PayoutModeSelectionRVAdapter extends RecyclerView.Adapter languageModels; private final CompositeDisposable compositeDisposables; + private final String sendCountryDefault = "118"; + /** * Exrate Related Data */ - private List payoutModeRelatedDataList; - private CountryPaymentService selectedPayoutModeData; + private List 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 getDefaultValue() { + @Override + public void setPaymentMode(PaymentMode paymentMode) { + this.selectedPaymentMode = paymentMode; + calcExrate(); + } + + @Override + public List 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 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 { @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); } } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/presenter/SplashScreenPresenterInterface.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/presenter/SplashScreenPresenterInterface.java index f6e6ba97..6a15a82e 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/presenter/SplashScreenPresenterInterface.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/presenter/SplashScreenPresenterInterface.java @@ -23,6 +23,13 @@ public interface SplashScreenPresenterInterface extends BasePresenterInterface { void getExrateRelatedData(); + void setPaymentMode(PaymentMode paymentMode); + + List getAvailableCountryRelatedCurrency(); + + void setCountryRelatedCurrencyData(CountryPaymentService countryPaymentService); + + interface SplashScreenContractInterfacee extends BaseContractInterface { void proceedToDashboardScreen(); @@ -45,9 +52,8 @@ public interface SplashScreenPresenterInterface extends BasePresenterInterface { void showSelectedPayoutCurrency(CountryPaymentService selectedPayoutCountryCurrency); - void showTransferCharge(String chargeAmount); + void showTransferChargeAndExrate(String chargeAmount,String exRate,boolean playAnimation); - void showExrate(String exrate); void animateToExrateView(Runnable task); } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/view/SplashScreen.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/view/SplashScreen.java index 76895868..29e5b6d8 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/view/SplashScreen.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/view/SplashScreen.java @@ -5,7 +5,6 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.graphics.Paint; import android.os.Bundle; -import android.os.Handler; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.constraint.ConstraintLayout; @@ -15,7 +14,6 @@ import android.support.transition.ChangeBounds; import android.support.transition.Transition; import android.support.transition.TransitionListenerAdapter; import android.support.transition.TransitionManager; -import android.support.v4.app.Fragment; import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewPropertyAnimatorListenerAdapter; import android.support.v7.widget.RecyclerView; @@ -34,6 +32,7 @@ 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.exchangecountrylistingdialog.CountryFlagMapper; +import com.gmeremit.online.gmeremittance_native.customwidgets.exchangecountrylistingdialog.ExchangeRateCurrencyListingDialog; import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.CountryPaymentService; import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.PaymentMode; import com.gmeremit.online.gmeremittance_native.exchange_rate.view.SelectedRedBorderDecoration; @@ -46,11 +45,7 @@ import com.gmeremit.online.gmeremittance_native.splash_screen.adapter.ViewPagerA import com.gmeremit.online.gmeremittance_native.splash_screen.model.LanguageModel; import com.gmeremit.online.gmeremittance_native.splash_screen.presenter.SplashScreenPresenter; import com.gmeremit.online.gmeremittance_native.splash_screen.presenter.SplashScreenPresenterInterface; -import com.gmeremit.online.gmeremittance_native.splash_screen.view.avdfrags.SplashAVD1Fragment; -import com.gmeremit.online.gmeremittance_native.splash_screen.view.avdfrags.SplashAVD2Fragment; -import com.gmeremit.online.gmeremittance_native.splash_screen.view.avdfrags.SplashAVD3Fragment; -import java.util.ArrayList; import java.util.List; import butterknife.BindView; @@ -113,6 +108,8 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener, @BindView(R.id.exchangeRateTxtView) TextView exchangeRateTxtView; + @BindView(R.id.countrySelectionSpinner) + View countrySelectionSpinner; LanguageViewTransitionManager languageViewTransitionManager; @@ -123,6 +120,9 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener, PayoutModeSelectionRVAdapter payoutModeSelectionRVAdapter; + private ExchangeRateCurrencyListingDialog countryListingDialog; + + private SplashScreenPresenterInterface presenter; public final String TAG = getClass().getSimpleName(); @@ -179,6 +179,9 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener, @Override public void onClick(View view) { switch (view.getId()) { + case R.id.countrySelectionSpinner: + showCountryListinDialog(); + break; case R.id.btn_login: startActivity(new Intent(this, LoginV2Activity.class)); break; @@ -206,6 +209,7 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener, iv_back.setOnClickListener(this); selectedLanguageText.setOnClickListener(this); selectedLanguageIcon.setOnClickListener(this); + countrySelectionSpinner.setOnClickListener(this); } @Override @@ -216,6 +220,7 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener, iv_back.setOnClickListener(null); selectedLanguageText.setOnClickListener(null); selectedLanguageIcon.setOnClickListener(null); + countrySelectionSpinner.setOnClickListener(null); } @@ -271,9 +276,6 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener, @Override public void updateFlagImage(int flagFromCountryCode) { -// Glide.with(this) -// .load(flagFromCountryCode) -// .into(selectedLanguageIcon); selectedLanguageIcon.setImageResource(flagFromCountryCode); } @@ -285,6 +287,21 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener, //-------------------Exrate Related View------------------- + private void showCountryListinDialog() { + if (countryListingDialog == null) + countryListingDialog = new ExchangeRateCurrencyListingDialog(); + countryListingDialog.setCountryPaymentData(presenter.getAvailableCountryRelatedCurrency()); + countryListingDialog.setListener(new ExchangeRateCurrencyListingDialog.CountrySelectionListener() { + @Override + public void onCountrySelected(CountryPaymentService countryPaymentService) { + presenter.setCountryRelatedCurrencyData(countryPaymentService); + countryListingDialog.dismiss(); + } + }); + if (!countryListingDialog.isAdded()) + countryListingDialog.show(getSupportFragmentManager(), "GenericTextListingDialog"); + } + private void startSendAmountListener(boolean action) { if (action) { sendAmountEdTxt.addTextChangedListener(sendMoneyTextWatcher); @@ -328,30 +345,33 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener, receivingCountryFlagImageView.setBackgroundResource(CountryFlagMapper.getFlagFromCountryCode(selectedPayoutCountryCurrency.getCountryCode())); } - @Override - public void showTransferCharge(String transferDisplay) { - ViewCompat.animate(this.transferFeeTxtView).alpha(0).withLayer().setDuration(200).setInterpolator(languageViewTransitionManager.accelerateDecelerateInterpolator).setListener(new ViewPropertyAnimatorListenerAdapter(){ - @Override - public void onAnimationEnd(View view) { - transferFeeTxtView.setText(transferDisplay); - ViewCompat.animate(transferFeeTxtView).alpha(1).withLayer().setDuration(200).setInterpolator(languageViewTransitionManager.accelerateDecelerateInterpolator).start(); - } - }).start(); - } @Override - public void showExrate(String exRateDisplay) { - ViewCompat.animate(this.exchangeRateTxtView).alpha(0).withLayer().setDuration(200).setInterpolator(languageViewTransitionManager.accelerateDecelerateInterpolator).setListener(new ViewPropertyAnimatorListenerAdapter(){ - @Override - public void onAnimationEnd(View view) { - exchangeRateTxtView.setText(exRateDisplay); - ViewCompat.animate(exchangeRateTxtView).alpha(1).withLayer().setDuration(200).setInterpolator(languageViewTransitionManager.accelerateDecelerateInterpolator).start(); - } - }).start(); + public void showTransferChargeAndExrate(String chargeAmount, String exRate,boolean playAnimation) { + if(playAnimation) { + ViewCompat.animate(this.transferFeeTxtView).alpha(0).withLayer().setDuration(200).setInterpolator(languageViewTransitionManager.accelerateDecelerateInterpolator).withEndAction(() -> { + transferFeeTxtView.setText(chargeAmount); + ViewCompat.animate(transferFeeTxtView).alpha(1).withLayer().setDuration(200).setInterpolator(languageViewTransitionManager.accelerateDecelerateInterpolator).start(); + }).withStartAction(() -> { + ViewCompat.animate(exchangeRateTxtView).alpha(0).withLayer().setDuration(200).setInterpolator(languageViewTransitionManager.accelerateDecelerateInterpolator).setListener(new ViewPropertyAnimatorListenerAdapter() { + @Override + public void onAnimationEnd(View view) { + exchangeRateTxtView.setText(exRate); + ViewCompat.animate(exchangeRateTxtView).alpha(1).withLayer().setDuration(200).setInterpolator(languageViewTransitionManager.accelerateDecelerateInterpolator).start(); + } + }).start(); + }).start(); + } + else + { + transferFeeTxtView.setText(chargeAmount); + exchangeRateTxtView.setText(exRate); + } } + @Override public void animateToExrateView(Runnable task) { languageViewTransitionManager.showMainViewLanguageFromPreLoadingScreen(400, task); @@ -359,7 +379,7 @@ public class SplashScreen extends BaseActivity implements View.OnClickListener, @Override public void onPaymentModeSelected(PaymentMode selectedData) { - + presenter.setPaymentMode(selectedData); } /**