From 4753e696b71ff3fc29f40e07613334704ab7faad Mon Sep 17 00:00:00 2001 From: preyearegmi Date: Wed, 22 Aug 2018 18:52:50 +0900 Subject: [PATCH] Exchange Rate first api flow to be tested --- .idea/caches/build_file_checksums.ser | Bin 535 -> 535 bytes .idea/misc.xml | 2 +- app/build.gradle | 14 +-- .../gmeremittance_native/GmeApplication.java | 12 ++ .../base/BasePresenter.java | 14 +++ .../base/BasePresenterInterface.java | 6 + .../base/PrivilegedGateway.java | 9 +- .../base/PrivilegedGatewayInterface.java | 4 + .../gateway/ExchangeRateV2Gateway.java | 28 +++++ .../CountryPaymentServiceSeedValueModel.java | 44 +++++++ .../datav2/PaymentServiceApiResponse.java | 31 +++++ .../ExchangeRateV2InteractorInterface.java | 12 +- .../presenter/ExchangeRateV2Presenter.java | 116 ++++++++++++++++-- .../ExchangeRateV2PresenterInterface.java | 22 ++++ .../view/ExchangeMethodV2Activity.java | 44 ++++++- .../gmeremittance_native/utils/Constants.java | 1 + .../utils/https/API_URL.java | 4 + .../utils/https/ApiEndpoints.java | 11 ++ .../https/GenericApiObservableResponse.java | 68 ++++++++++ .../utils/https/GenericApiResponse.java | 24 +--- .../utils/https/HTTPConstants.java | 32 ++++- .../utils/https/HttpClientV2.java | 2 +- 22 files changed, 447 insertions(+), 53 deletions(-) create mode 100644 app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/gateway/ExchangeRateV2Gateway.java create mode 100644 app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/model/datav2/CountryPaymentServiceSeedValueModel.java create mode 100644 app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/model/datav2/PaymentServiceApiResponse.java create mode 100644 app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2PresenterInterface.java create mode 100644 app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/GenericApiObservableResponse.java diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 4c55ffc3fbc59a497e611fdf87feba99ea776649..fe29bbe1a78b6912d4c7319e0ff82bc3705e3ce8 100644 GIT binary patch delta 33 rcmV++0N($X1eXMmm;_)aY*w+HY5@_TaQXie&Dy&hmZ+ElU6^cm=>HDC delta 33 pcmbQvGM#0@43_vX@0N{ovKR$7W?h?na#?vz!Gg4Ja$EBpD*)`r4*UQB diff --git a/.idea/misc.xml b/.idea/misc.xml index 99202cc2..c0f68edd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -25,7 +25,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 54b167e6..6a818ec4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -68,10 +68,14 @@ android { shrinkResources false } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation fileTree(include: ['*.jar'], dir: 'libs') //noinspection GradleCompatible implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support:design:26.1.0' @@ -94,8 +98,7 @@ dependencies { implementation 'com.github.kapilmhr:SizesDP:1.1' implementation 'de.hdodenhof:circleimageview:2.2.0' implementation 'com.facebook.android:facebook-share:[4,5)' -// compile group: 'com.zendesk', name: 'sdk', version: '1.10.0.1' - + // compile group: 'com.zendesk', name: 'sdk', version: '1.10.0.1' implementation 'joda-time:joda-time:2.9.9' implementation 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' @@ -106,12 +109,7 @@ dependencies { implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' implementation 'io.reactivex.rxjava2:rxjava:2.1.0' - - - - implementation 'org.greenrobot:eventbus:3.1.1' - } apply plugin: 'com.google.gms.google-services' diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/GmeApplication.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/GmeApplication.java index adfa7260..3f22691a 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/GmeApplication.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/GmeApplication.java @@ -1,6 +1,8 @@ package com.gmeremit.online.gmeremittance_native; import android.app.Application; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Build; import android.os.StrictMode; import android.support.multidex.MultiDex; @@ -17,6 +19,8 @@ import java.lang.reflect.Method; */ public class GmeApplication extends Application { + + private static SharedPreferences gmeSharedPreferences = null; @Override public void onCreate() { super.onCreate(); @@ -30,6 +34,8 @@ public class GmeApplication extends Application { builder.detectFileUriExposure(); StrictMode.setVmPolicy(builder.build()); } + + gmeSharedPreferences= this.getSharedPreferences("GME", Context.MODE_PRIVATE); /* if(Build.VERSION.SDK_INT>=24){ try{ Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure"); @@ -39,4 +45,10 @@ public class GmeApplication extends Application { } }*/ } + + + public static SharedPreferences getStorage() { + return gmeSharedPreferences; + } + } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/BasePresenter.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/BasePresenter.java index a952abc7..46fecb12 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/BasePresenter.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/BasePresenter.java @@ -1,4 +1,18 @@ package com.gmeremit.online.gmeremittance_native.base; public class BasePresenter implements BasePresenterInterface { + @Override + public void onViewReady() { + + } + + @Override + public void onViewNotReady() { + + } + + @Override + public void onViewDestroyed() { + + } } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/BasePresenterInterface.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/BasePresenterInterface.java index 4629c89d..e7f812dd 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/BasePresenterInterface.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/BasePresenterInterface.java @@ -1,4 +1,10 @@ package com.gmeremit.online.gmeremittance_native.base; public interface BasePresenterInterface { + + void onViewReady(); + + void onViewNotReady(); + + void onViewDestroyed(); } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/PrivilegedGateway.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/PrivilegedGateway.java index f48cd39a..2c3829cc 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/PrivilegedGateway.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/PrivilegedGateway.java @@ -1,4 +1,11 @@ package com.gmeremit.online.gmeremittance_native.base; -public class PrivilegedGateway implements PrivilegedGatewayInterface { +import com.gmeremit.online.gmeremittance_native.GmeApplication; + +public abstract class PrivilegedGateway implements PrivilegedGatewayInterface { + + @Override + public String getAuth(){ + return "Basic "+GmeApplication.getStorage().getString("ACCESS_CODE",""); + } } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/PrivilegedGatewayInterface.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/PrivilegedGatewayInterface.java index 11c21f6a..e172ea86 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/PrivilegedGatewayInterface.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/base/PrivilegedGatewayInterface.java @@ -1,4 +1,8 @@ package com.gmeremit.online.gmeremittance_native.base; +import com.gmeremit.online.gmeremittance_native.GmeApplication; + public interface PrivilegedGatewayInterface extends BaseGatewayInterface { + + String getAuth(); } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/gateway/ExchangeRateV2Gateway.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/gateway/ExchangeRateV2Gateway.java new file mode 100644 index 00000000..f68731fd --- /dev/null +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/gateway/ExchangeRateV2Gateway.java @@ -0,0 +1,28 @@ +package com.gmeremit.online.gmeremittance_native.exchange_rate.gateway; + +import com.gmeremit.online.gmeremittance_native.base.PrivilegedGateway; +import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.CountryPaymentServiceSeedValueModel; +import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.PaymentServiceApiResponse; +import com.gmeremit.online.gmeremittance_native.exchange_rate.presenter.ExchangeRateV2InteractorInterface; +import com.gmeremit.online.gmeremittance_native.utils.https.HttpClientV2; + +import io.reactivex.Observable; + +public class ExchangeRateV2Gateway extends PrivilegedGateway implements ExchangeRateV2InteractorInterface.ExchangeRateV2GatewayInterface { + + + @Override + public Observable getPaymentServiceInfoFromServer(String auth) { + return HttpClientV2.getInstance().getPaymentServiceV2(auth); + } + + @Override + public Observable getNativeCountry() { + return Observable.just("Asdf"); + } + + @Override + public Observable getAllSeedVAlues(String nativeCountry) { + return Observable.just(new CountryPaymentServiceSeedValueModel("asdf","asdf")); + } +} diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/model/datav2/CountryPaymentServiceSeedValueModel.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/model/datav2/CountryPaymentServiceSeedValueModel.java new file mode 100644 index 00000000..ec6e8a12 --- /dev/null +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/model/datav2/CountryPaymentServiceSeedValueModel.java @@ -0,0 +1,44 @@ +package com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2; + +import com.google.gson.annotations.SerializedName; + +public class CountryPaymentServiceSeedValueModel { + + @SerializedName("countryCode") + String countryCode; + + @SerializedName("currency") + String currency; + + @SerializedName("recipientSeedValue") + String recipientSeedValue; + + public CountryPaymentServiceSeedValueModel(String countryCode, String recipientSeedValue) { + this.countryCode = countryCode; + this.recipientSeedValue = recipientSeedValue; + } + + public String getCountryCode() { + return countryCode; + } + + public void setCountryCode(String countryCode) { + this.countryCode = countryCode; + } + + public String getRecipientSeedValue() { + return recipientSeedValue; + } + + public void setRecipientSeedValue(String recipientSeedValue) { + this.recipientSeedValue = recipientSeedValue; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } +} diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/model/datav2/PaymentServiceApiResponse.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/model/datav2/PaymentServiceApiResponse.java new file mode 100644 index 00000000..b4d48904 --- /dev/null +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/model/datav2/PaymentServiceApiResponse.java @@ -0,0 +1,31 @@ +package com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2; + +import java.util.ArrayList; +import java.util.List; + +public class PaymentServiceApiResponse { + + List countryPaymentServices; + + public PaymentServiceApiResponse() { + countryPaymentServices=new ArrayList<>(); + } + + public List getCountryPaymentServices() { + return countryPaymentServices; + } + + public void setCountryPaymentServices(List countryPaymentServices) { + this.countryPaymentServices = countryPaymentServices; + } + + public CountryPaymentService getCountryPaymentServiceFromCountryCodeAndCurrency(String countryCode,String currency){ + + for(CountryPaymentService countryPaymentService:countryPaymentServices) + { + if(countryPaymentService.getCountryCode().equalsIgnoreCase(countryCode)&&countryPaymentService.getCurrency().equalsIgnoreCase(currency)) + return countryPaymentService; + } + return null; + } +} diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2InteractorInterface.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2InteractorInterface.java index e371fd6a..432c252e 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2InteractorInterface.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2InteractorInterface.java @@ -2,17 +2,23 @@ package com.gmeremit.online.gmeremittance_native.exchange_rate.presenter; import com.gmeremit.online.gmeremittance_native.base.BaseGatewayInterface; import com.gmeremit.online.gmeremittance_native.base.BaseInteractorInterface; +import com.gmeremit.online.gmeremittance_native.base.PrivilegedGatewayInterface; import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.CountryPaymentService; +import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.CountryPaymentServiceSeedValueModel; +import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.PaymentServiceApiResponse; import java.util.List; +import io.reactivex.Observable; + public interface ExchangeRateV2InteractorInterface extends BaseInteractorInterface { - void onGettinPaymentServiceInforFromServer(List data); - interface ExchangeRateV2GatewayInterface extends BaseGatewayInterface + interface ExchangeRateV2GatewayInterface extends PrivilegedGatewayInterface { //Change to observable rxjava - void getPaymentServiceInfoFromServer(); + Observable getPaymentServiceInfoFromServer(String auth); + String getNativeCountry(); + Observable> getAllSeedVAlues(); } } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2Presenter.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2Presenter.java index e00f7723..df29afc9 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2Presenter.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2Presenter.java @@ -1,18 +1,114 @@ package com.gmeremit.online.gmeremittance_native.exchange_rate.presenter; -import com.gmeremit.online.gmeremittance_native.base.BaseContractInterface; -import com.gmeremit.online.gmeremittance_native.base.BasePresenterInterface; -import com.gmeremit.online.gmeremittance_native.base.PrivilegedGatewayInterface; -import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.CountryPaymentService; +import android.util.Log; -import java.util.List; +import com.gmeremit.online.gmeremittance_native.base.BasePresenter; +import com.gmeremit.online.gmeremittance_native.exchange_rate.gateway.ExchangeRateV2Gateway; +import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.CountryPaymentServiceSeedValueModel; +import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.PaymentServiceApiResponse; +import com.gmeremit.online.gmeremittance_native.utils.https.GenericApiObservableResponse; -public interface ExchangeRateV2Presenter extends BasePresenterInterface { +import io.reactivex.Observable; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.schedulers.Schedulers; - void getCountryServiceData(); +public class ExchangeRateV2Presenter extends BasePresenter implements ExchangeRateV2PresenterInterface, ExchangeRateV2InteractorInterface { - interface ExchangeRateV2ContractInterface extends PrivilegedGatewayInterface - { - void showCountryServiceData(List countryPaymentServiceList); + private final ExchangeRateV2ContractInterface view; + private final ExchangeRateV2GatewayInterface gateway; + private final CompositeDisposable compositeDisposables; + + public ExchangeRateV2Presenter(ExchangeRateV2ContractInterface view) { + this.view = view; + this.gateway = new ExchangeRateV2Gateway(); + this.compositeDisposables = new CompositeDisposable(); + } + + @Override + public void getAllData() { + compositeDisposables.add( + Observable.zip(getPaymentServiceInfo(), getDefaultValue(), PaymentServiceData::new) + .doOnSubscribe(disposable -> this.view.showProgressBar(true, "Fetching Exchange Rates...")) + .doOnError((err) -> this.view.showProgressBar(false, "")) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new PaymentServiceDataObservable()) + ); + } + + @Override + public void getForex() { + + } + + private Observable getDefaultValue() { + + return this.gateway.getAllSeedVAlues().flatMap(seedValueList->{ + String nativeCountryCode= this.gateway.getNativeCountry(); + for(CountryPaymentServiceSeedValueModel seedValueModel:seedValueList) + { + if(seedValueModel.getCountryCode().equalsIgnoreCase(nativeCountryCode)) + return Observable.just(seedValueModel); + } + return Observable.just(new CountryPaymentServiceSeedValueModel(null,null)); + }); + + + } + + private Observable getPaymentServiceInfo() { + return this.gateway.getPaymentServiceInfoFromServer(this.gateway.getAuth()).subscribeOn(Schedulers.io()); + } + + + public class PaymentServiceDataObservable extends GenericApiObservableResponse { + + @Override + protected void onSuccess(PaymentServiceData paymentServiceApiResponse) { + Log.d("ExchangeV2", "Success"); + CountryPaymentServiceSeedValueModel seedValueModel = paymentServiceApiResponse.getCountryPaymentServiceSeedValueModel(); + view.showCountryServiceData(paymentServiceApiResponse.getPaymentServiceApiResponse().getCountryPaymentServices(), + paymentServiceApiResponse.getPaymentServiceApiResponse().getCountryPaymentServiceFromCountryCodeAndCurrency(seedValueModel.getCountryCode(), seedValueModel.getCurrency()), + paymentServiceApiResponse.getCountryPaymentServiceSeedValueModel().getRecipientSeedValue() + ); + + } + + @Override + public void onFailed(String message) { + Log.d("ExchangeV2", "Failed:" + message); + } + + @Override + protected void onConnectionNotEstablished(String message) { + Log.d("ExchangeV2", "ConnectionNotEstablished:" + message); + + } + } + + public class PaymentServiceData { + private PaymentServiceApiResponse paymentServiceApiResponse; + private CountryPaymentServiceSeedValueModel countryPaymentServiceSeedValueModel; + + public PaymentServiceData(PaymentServiceApiResponse paymentServiceApiResponse, CountryPaymentServiceSeedValueModel countryPaymentServiceSeedValueModel) { + this.paymentServiceApiResponse = paymentServiceApiResponse; + this.countryPaymentServiceSeedValueModel = countryPaymentServiceSeedValueModel; + } + + public PaymentServiceApiResponse getPaymentServiceApiResponse() { + return paymentServiceApiResponse; + } + + public void setPaymentServiceApiResponse(PaymentServiceApiResponse paymentServiceApiResponse) { + this.paymentServiceApiResponse = paymentServiceApiResponse; + } + + public CountryPaymentServiceSeedValueModel getCountryPaymentServiceSeedValueModel() { + return countryPaymentServiceSeedValueModel; + } + + public void setCountryPaymentServiceSeedValueModel(CountryPaymentServiceSeedValueModel countryPaymentServiceSeedValueModel) { + this.countryPaymentServiceSeedValueModel = countryPaymentServiceSeedValueModel; + } } } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2PresenterInterface.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2PresenterInterface.java new file mode 100644 index 00000000..023f867c --- /dev/null +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2PresenterInterface.java @@ -0,0 +1,22 @@ +package com.gmeremit.online.gmeremittance_native.exchange_rate.presenter; + +import com.gmeremit.online.gmeremittance_native.base.BaseContractInterface; +import com.gmeremit.online.gmeremittance_native.base.BasePresenterInterface; +import com.gmeremit.online.gmeremittance_native.base.PrivilegedGatewayInterface; +import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.CountryPaymentService; +import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.CountryPaymentServiceSeedValueModel; + +import java.util.List; + +public interface ExchangeRateV2PresenterInterface extends BasePresenterInterface { + + void getAllData(); + + void getForex(); + + + interface ExchangeRateV2ContractInterface extends BaseContractInterface + { + void showCountryServiceData(List countryPaymentServiceList, CountryPaymentService defaultCountryService,String recepientSeedValue); + } +} diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/view/ExchangeMethodV2Activity.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/view/ExchangeMethodV2Activity.java index b48f237f..c7de8b14 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/view/ExchangeMethodV2Activity.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/view/ExchangeMethodV2Activity.java @@ -1,7 +1,6 @@ package com.gmeremit.online.gmeremittance_native.exchange_rate.view; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.RecyclerView; import android.util.Log; @@ -11,13 +10,17 @@ import android.widget.ImageView; import android.widget.TextView; import com.gmeremit.online.gmeremittance_native.R; -import com.gmeremit.online.gmeremittance_native.customwidgets.CustomPaddingRv; +import com.gmeremit.online.gmeremittance_native.base.BaseActivity; import com.gmeremit.online.gmeremittance_native.customwidgets.GmeTextView; import com.gmeremit.online.gmeremittance_native.customwidgets.countrylistingdialog.CountryFlagMapper; import com.gmeremit.online.gmeremittance_native.customwidgets.countrylistingdialog.CountryListingDialog; import com.gmeremit.online.gmeremittance_native.exchange_rate.adapter.PaymentModeRvAdapter; import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.CountryPaymentService; +import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.CountryPaymentServiceSeedValueModel; import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.PaymentMode; +import com.gmeremit.online.gmeremittance_native.exchange_rate.presenter.ExchangeRateV2Presenter; +import com.gmeremit.online.gmeremittance_native.exchange_rate.presenter.ExchangeRateV2PresenterInterface; +import com.gmeremit.online.gmeremittance_native.utils.Constants; import java.util.ArrayList; import java.util.List; @@ -25,7 +28,7 @@ import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; -public class ExchangeMethodV2Activity extends AppCompatActivity implements PaymentModeRvAdapter.OnPaymentModeSelectionListener, CountryListingDialog.CountrySelectionListener, View.OnClickListener { +public class ExchangeMethodV2Activity extends BaseActivity implements PaymentModeRvAdapter.OnPaymentModeSelectionListener, CountryListingDialog.CountrySelectionListener, View.OnClickListener, ExchangeRateV2PresenterInterface.ExchangeRateV2ContractInterface { @BindView(R.id.sendAmountEdTxt) EditText sendMoneyEditText; @@ -51,8 +54,10 @@ public class ExchangeMethodV2Activity extends AppCompatActivity implements Payme private PaymentModeRvAdapter paymentModeRvAdapter; private PaymentMode selectedPaymentMode; private List mockedData; + private List paymentServiceList; private CountryListingDialog countryListingDialog; private CountryPaymentService selectedCountryPaymentService; + private ExchangeRateV2PresenterInterface presenter; @Override protected void onCreate(Bundle savedInstanceState) { @@ -66,11 +71,14 @@ public class ExchangeMethodV2Activity extends AppCompatActivity implements Payme private void init() { setupRv(); + + this.presenter=new ExchangeRateV2Presenter(this); } private void performDefaultAction(Bundle savedInstanceState) { toolbarTitle.setText("Today's Rate"); mockData(); + this.presenter.getAllData(); } @@ -101,7 +109,6 @@ public class ExchangeMethodV2Activity extends AppCompatActivity implements Payme paymentModeRvAdapter = new PaymentModeRvAdapter(this); paymentModeRv.setAdapter(paymentModeRvAdapter); paymentModeRv.addItemDecoration(new SelectedRedBorderDecoration(this)); -// paymentModeRv.addItemDecoration(new CustomPaddingRv(10)); paymentModeRv.setItemAnimator(new DefaultItemAnimator()); } @@ -136,12 +143,17 @@ public class ExchangeMethodV2Activity extends AppCompatActivity implements Payme public void onCountrySelected(CountryPaymentService countryPaymentService) { Log.d("ExchangeRateV2", "Selected Country " + countryPaymentService.getCountryCode()); this.selectedCountryPaymentService=countryPaymentService; - this.recepientFlagImageView.setBackgroundResource(CountryFlagMapper.getFlagFromCountryCode(countryPaymentService.getCountryCode())); - this.recepientCurrencyTextView.setText(countryPaymentService.getCurrency()); + showSelectedRecipient(countryPaymentService.getCountryCode(),countryPaymentService.getCurrency()); if (this.countryListingDialog != null) this.countryListingDialog.dismiss(); } + private void showSelectedRecipient(String selectedCountryCode,String selectedCountryCurrency) + { + this.recepientFlagImageView.setBackgroundResource(CountryFlagMapper.getFlagFromCountryCode(selectedCountryCode)); + this.recepientCurrencyTextView.setText(selectedCountryCurrency); + } + @Override public void onClick(View v) { switch (v.getId()) { @@ -150,4 +162,24 @@ public class ExchangeMethodV2Activity extends AppCompatActivity implements Payme break; } } + + @Override + public void showCountryServiceData(List countryPaymentServiceList,CountryPaymentService defaultCountryPaymentService,String seedValue) { + showSelectedRecipient(defaultCountryPaymentService.getCountryCode(),defaultCountryPaymentService.getCurrency()); + if(seedValue!=null) { + this.recepientCurrencyTextView.setText(seedValue); + } + else + { + this.sendMoneyEditText.setText(Constants.DEFAULT_EXCHANGE_SEND_AMOUNT); + this.recepientCurrencyTextView.setText(""); + } + this.paymentServiceList=countryPaymentServiceList; + this.selectedCountryPaymentService=defaultCountryPaymentService; + this.presenter.getForex(); + } + + + + } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/Constants.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/Constants.java index 19135083..1742e45d 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/Constants.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/Constants.java @@ -127,6 +127,7 @@ public class Constants { public static final String RECIPIENT_UPDATE = "RECIPIENT_UPDATE"; // User Request public static final String USER_REQUEST_PAGE = "USER_REQUEST_PAGE"; + public static final String DEFAULT_EXCHANGE_SEND_AMOUNT = ""; // public static final String DEVICEID = "gme1234apps12sanam"; /* public static final String DEVICEID = "iakhycas"; new@test.com pw: test*/ // public static String key = Utils.toBase64("172017F9EC11222E8107142733:QRK2UM0Q:" + DEVICEID); diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/API_URL.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/API_URL.java index ecbd407c..2e719dbd 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/API_URL.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/API_URL.java @@ -116,5 +116,9 @@ public class API_URL { public static final String RELATION_LIST = "cdds/CDDRELV1"; public static final String STATE_LIST = "cdds/CDDPRLSTV1"; public static final String DISTRICT_LIST = "cdds/CDDDTLSTV1"; + + /* V2 Api Endpoints */ + + public static final String EXCHANGE_RATE_SERVICE="mobile/countriesServices"; } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/ApiEndpoints.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/ApiEndpoints.java index 9ebfd176..d93d25a1 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/ApiEndpoints.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/ApiEndpoints.java @@ -4,6 +4,7 @@ import com.gmeremit.online.gmeremittance_native.customer_support.model.Amendment import com.gmeremit.online.gmeremittance_native.customer_support.model.Suggestion; import com.gmeremit.online.gmeremittance_native.exchange_rate.model.data.Currency; import com.gmeremit.online.gmeremittance_native.exchange_rate.model.data.ExchangeRateResponse; +import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.PaymentServiceApiResponse; import com.gmeremit.online.gmeremittance_native.gme_branches.model.data.PayoutLocationData; import com.gmeremit.online.gmeremittance_native.home.model.data.FireToken; import com.gmeremit.online.gmeremittance_native.home.model.data.Profile; @@ -85,10 +86,12 @@ import com.gmeremit.online.gmeremittance_native.wallet_to_wallet.model.WalletReq import com.gmeremit.online.gmeremittance_native.wallet_to_wallet.model.WalletResponse; import com.gmeremit.online.gmeremittance_native.wallet_to_wallet.model.WalletUserInfo; import com.gmeremit.online.gmeremittance_native.withdraw.model.WithDraw; +import com.google.gson.JsonObject; import java.util.List; import java.util.Map; +import io.reactivex.Observable; import okhttp3.MultipartBody; import okhttp3.RequestBody; import okhttp3.ResponseBody; @@ -96,6 +99,7 @@ import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.DELETE; import retrofit2.http.GET; +import retrofit2.http.Header; import retrofit2.http.Headers; import retrofit2.http.Multipart; import retrofit2.http.PATCH; @@ -512,4 +516,11 @@ public interface ApiEndpoints { @GET(API_URL.DISTRICT_LIST) @Headers("Content-Type: application/json") Call> getDistrictList(@Query("countryId") String countryId, @Query("provinceId") String provinceId); + + /* V2 */ + + @POST(API_URL.EXCHANGE_RATE_SERVICE) + @Headers("Content-Type: application/json") + Observable getPaymentServiceV2(@Header("Authorization") String token); + } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/GenericApiObservableResponse.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/GenericApiObservableResponse.java new file mode 100644 index 00000000..5679b65b --- /dev/null +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/GenericApiObservableResponse.java @@ -0,0 +1,68 @@ +package com.gmeremit.online.gmeremittance_native.utils.https; + + +import org.json.JSONObject; + +import java.io.IOException; +import java.net.SocketTimeoutException; + +import io.reactivex.observers.DisposableObserver; +import okhttp3.ResponseBody; +import retrofit2.HttpException; + +/** + * Created by Preyea R. Regmi + * Use this wrapper class to abstract application wise network response for rx-retrofit 2.0 and above + */ +public abstract class GenericApiObservableResponse extends DisposableObserver { + + + protected abstract void onSuccess(T t); + + public abstract void onFailed(String message); + + protected abstract void onConnectionNotEstablished(String message); + + @Override + public void onNext(T t) { + //Handle application wise response code here + String errorMessage = checkIfResponseIsValidOrNot(t); + if (errorMessage == null) + onSuccess(t); + else + onFailed(errorMessage); + } + + @Override + public void onError(Throwable e) { + + if (e instanceof HttpException) { + onFailed(HTTPConstants.getErrorMessageFromCode(((HttpException) e).code())); + } else if (e instanceof SocketTimeoutException) { + onFailed(HTTPConstants.HTTP_RESPONSE_NO_INTERNET); + } else if (e instanceof IOException) { + onConnectionNotEstablished(HTTPConstants.HTTP_RESPONSE_NO_INTERNET); + } else { + onFailed(e.getMessage()); + } + } + + @Override + public void onComplete() { + + } + + private String checkIfResponseIsValidOrNot(T genericBody) { + try { + ResponseBody responseBody = (ResponseBody) genericBody; + JSONObject jsonObject = new JSONObject(responseBody.string()); + if (jsonObject.getString("errorCode").equalsIgnoreCase(HTTPConstants.APPLICATION_WISE_ERROR_KEY)) + return jsonObject.getString("responseDescription"); + else + return null; + } catch (Exception e) { + return e.getMessage(); + } + } +} + diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/GenericApiResponse.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/GenericApiResponse.java index 260b8d50..cd8d16f4 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/GenericApiResponse.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/GenericApiResponse.java @@ -4,6 +4,10 @@ import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; +/** + * Created by Preyea R. Regmi + * Use this wrapper class to abstract application wise network response for retrofit 2.0 and above + */ public class GenericApiResponse implements Callback { private GenericApiResponseListener listener; @@ -17,25 +21,7 @@ public class GenericApiResponse implements Callback { if (response.isSuccessful()) { listener.onSuccess(response.body()); } else { - switch (response.code()) { - case 401: - listener.onError(HTTPConstants.HTTP_RESPONSE_401); - break; - - case 403: - listener.onError(HTTPConstants.HTTP_RESPONSE_403); - break; - - case 500: - listener.onError(HTTPConstants.HTTP_RESPONSE_500); - break; - - case 404: - listener.onError(HTTPConstants.HTTP_RESPONSE_500); - break; - - - } + listener.onError(HTTPConstants.getErrorMessageFromCode(response.code())); } } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/HTTPConstants.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/HTTPConstants.java index 31fcfa70..2a8c815a 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/HTTPConstants.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/HTTPConstants.java @@ -1,8 +1,32 @@ package com.gmeremit.online.gmeremittance_native.utils.https; public class HTTPConstants { - public static final String HTTP_RESPONSE_401 = ""; - public static final String HTTP_RESPONSE_403 = ""; - public static final String HTTP_RESPONSE_500 = ""; - public static final String HTTP_RESPONSE_NO_INTERNET = ""; + public static final String HTTP_RESPONSE_401 = "401"; + public static final String HTTP_RESPONSE_403 = "403"; + public static final String HTTP_RESPONSE_500 = "500"; + public static final String HTTP_RESPONSE_NO_INTERNET = "No internet"; + public static final String HTTP_RESPONSE_UNKNOWN = "Unknown Error"; + public static final String APPLICATION_WISE_ERROR_KEY = "1"; + + + public static String getErrorMessageFromCode(int errorCode) { + switch (errorCode) { + case 401: + return HTTP_RESPONSE_401; + + case 403: + return HTTPConstants.HTTP_RESPONSE_403; + + case 500: + return HTTPConstants.HTTP_RESPONSE_500; + + case 404: + return HTTPConstants.HTTP_RESPONSE_500; + + default: + return HTTPConstants.HTTP_RESPONSE_NO_INTERNET; + + + } + } } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/HttpClientV2.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/HttpClientV2.java index 52f25f83..24e8371a 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/HttpClientV2.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/HttpClientV2.java @@ -17,7 +17,7 @@ public class HttpClientV2 { private static ApiEndpoints apiInterface; /** - * Creates an instance for API Interface + * Creates an instance for Http Client Interface * * @return apiInterface */