Browse Source

Exrate in splash integration done

master
Preyea Regmi 5 years ago
parent
commit
89b521248f
  1. 2
      app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/adapter/PayoutModeSelectionRVAdapter.java
  2. 124
      app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/presenter/SplashScreenPresenter.java
  3. 10
      app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/presenter/SplashScreenPresenterInterface.java
  4. 66
      app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/view/SplashScreen.java

2
app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/adapter/PayoutModeSelectionRVAdapter.java

@ -40,6 +40,8 @@ public class PayoutModeSelectionRVAdapter extends RecyclerView.Adapter<PayoutMod
@Override
public void onClick(View v) {
setSelectedItem(payoutModeSelectionItemViewHolder.getAdapterPosition());
if(listener!=null)
listener.onPaymentModeSelected(data.get(payoutModeSelectionItemViewHolder.getAdapterPosition()));
}
});
payoutModeSelectionItemViewHolder.setImage(PaymentModeMapper.getPaymentModeImageFromId(data.get(payoutModeSelectionItemViewHolder.getAdapterPosition()).getId()));

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

@ -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,10 +138,64 @@ 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";
for (CountryPaymentServiceSeedValueModel seedValueModel : seedValueList) {
@ -161,29 +218,36 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen
protected void onSuccess(PaymentServiceData paymentServiceApiResponse) {
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());
selectedCountryPaymentService = paymentServiceApiResponse.getPaymentServiceApiResponse().getDefaultPayoutMode(seedValueModel.getCountryCode());
selectedPaymentMode = selectedCountryPaymentService.getServiceAvailable().get(0);
calcByPayoutAmount = false;
cAmount = Constants.DEFAULT_EXCHANGE_SEND_AMOUNT;
view.animateToExrateView(SplashScreenPresenter.this::updateViewWithSelectedValues);
view.animateToExrateView(() -> {
updateViewWithDefaulValues();
calcExrate();
});
} else {
//No Default PAmount available for the selected country
//Update UI with PAmount,CAmount,SelectedPayoutMode,SelectedCurrency
selectedPaymentMode = selectedCountryPaymentService.getServiceAvailable().get(0);
calcByPayoutAmount = true;
pAmount = seedValueModel.getRecipientSeedValue();
view.animateToExrateView(SplashScreenPresenter.this::updateViewWithSelectedValues);
view.animateToExrateView(() -> {
updateViewWithDefaulValues();
calcExrate();
});
}
} else {
@ -211,20 +275,20 @@ public class SplashScreenPresenter extends BasePresenter implements SplashScreen
}
}
private void updateViewWithSelectedValues() {
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);
}
}

10
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<CountryPaymentService> 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);
}

66
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(){
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(exRateDisplay);
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);
}
/**

Loading…
Cancel
Save