preyearegmi
6 years ago
22 changed files with 447 additions and 53 deletions
-
BIN.idea/caches/build_file_checksums.ser
-
2.idea/misc.xml
-
14app/build.gradle
-
12app/src/main/java/com/gmeremit/online/gmeremittance_native/GmeApplication.java
-
14app/src/main/java/com/gmeremit/online/gmeremittance_native/base/BasePresenter.java
-
6app/src/main/java/com/gmeremit/online/gmeremittance_native/base/BasePresenterInterface.java
-
9app/src/main/java/com/gmeremit/online/gmeremittance_native/base/PrivilegedGateway.java
-
4app/src/main/java/com/gmeremit/online/gmeremittance_native/base/PrivilegedGatewayInterface.java
-
28app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/gateway/ExchangeRateV2Gateway.java
-
44app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/model/datav2/CountryPaymentServiceSeedValueModel.java
-
31app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/model/datav2/PaymentServiceApiResponse.java
-
12app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2InteractorInterface.java
-
114app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2Presenter.java
-
22app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/presenter/ExchangeRateV2PresenterInterface.java
-
44app/src/main/java/com/gmeremit/online/gmeremittance_native/exchange_rate/view/ExchangeMethodV2Activity.java
-
1app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/Constants.java
-
4app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/API_URL.java
-
11app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/ApiEndpoints.java
-
68app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/GenericApiObservableResponse.java
-
24app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/GenericApiResponse.java
-
32app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/HTTPConstants.java
-
2app/src/main/java/com/gmeremit/online/gmeremittance_native/utils/https/HttpClientV2.java
@ -1,4 +1,18 @@ |
|||||
package com.gmeremit.online.gmeremittance_native.base; |
package com.gmeremit.online.gmeremittance_native.base; |
||||
|
|
||||
public class BasePresenter implements BasePresenterInterface { |
public class BasePresenter implements BasePresenterInterface { |
||||
|
@Override |
||||
|
public void onViewReady() { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onViewNotReady() { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onViewDestroyed() { |
||||
|
|
||||
|
} |
||||
} |
} |
@ -1,4 +1,10 @@ |
|||||
package com.gmeremit.online.gmeremittance_native.base; |
package com.gmeremit.online.gmeremittance_native.base; |
||||
|
|
||||
public interface BasePresenterInterface { |
public interface BasePresenterInterface { |
||||
|
|
||||
|
void onViewReady(); |
||||
|
|
||||
|
void onViewNotReady(); |
||||
|
|
||||
|
void onViewDestroyed(); |
||||
} |
} |
@ -1,4 +1,11 @@ |
|||||
package com.gmeremit.online.gmeremittance_native.base; |
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",""); |
||||
|
} |
||||
} |
} |
@ -1,4 +1,8 @@ |
|||||
package com.gmeremit.online.gmeremittance_native.base; |
package com.gmeremit.online.gmeremittance_native.base; |
||||
|
|
||||
|
import com.gmeremit.online.gmeremittance_native.GmeApplication; |
||||
|
|
||||
public interface PrivilegedGatewayInterface extends BaseGatewayInterface { |
public interface PrivilegedGatewayInterface extends BaseGatewayInterface { |
||||
|
|
||||
|
String getAuth(); |
||||
} |
} |
@ -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<PaymentServiceApiResponse> getPaymentServiceInfoFromServer(String auth) { |
||||
|
return HttpClientV2.getInstance().getPaymentServiceV2(auth); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Observable<String> getNativeCountry() { |
||||
|
return Observable.just("Asdf"); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Observable<CountryPaymentServiceSeedValueModel> getAllSeedVAlues(String nativeCountry) { |
||||
|
return Observable.just(new CountryPaymentServiceSeedValueModel("asdf","asdf")); |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
} |
||||
|
} |
@ -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<CountryPaymentService> countryPaymentServices; |
||||
|
|
||||
|
public PaymentServiceApiResponse() { |
||||
|
countryPaymentServices=new ArrayList<>(); |
||||
|
} |
||||
|
|
||||
|
public List<CountryPaymentService> getCountryPaymentServices() { |
||||
|
return countryPaymentServices; |
||||
|
} |
||||
|
|
||||
|
public void setCountryPaymentServices(List<CountryPaymentService> 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; |
||||
|
} |
||||
|
} |
@ -1,18 +1,114 @@ |
|||||
package com.gmeremit.online.gmeremittance_native.exchange_rate.presenter; |
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 |
|
||||
|
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<CountryPaymentServiceSeedValueModel> getDefaultValue() { |
||||
|
|
||||
|
return this.gateway.getAllSeedVAlues().flatMap(seedValueList->{ |
||||
|
String nativeCountryCode= this.gateway.getNativeCountry(); |
||||
|
for(CountryPaymentServiceSeedValueModel seedValueModel:seedValueList) |
||||
{ |
{ |
||||
void showCountryServiceData(List<CountryPaymentService> countryPaymentServiceList); |
|
||||
|
if(seedValueModel.getCountryCode().equalsIgnoreCase(nativeCountryCode)) |
||||
|
return Observable.just(seedValueModel); |
||||
|
} |
||||
|
return Observable.just(new CountryPaymentServiceSeedValueModel(null,null)); |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
private Observable<PaymentServiceApiResponse> getPaymentServiceInfo() { |
||||
|
return this.gateway.getPaymentServiceInfoFromServer(this.gateway.getAuth()).subscribeOn(Schedulers.io()); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public class PaymentServiceDataObservable extends GenericApiObservableResponse<PaymentServiceData> { |
||||
|
|
||||
|
@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; |
||||
|
} |
||||
} |
} |
||||
} |
} |
@ -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<CountryPaymentService> countryPaymentServiceList, CountryPaymentService defaultCountryService,String recepientSeedValue); |
||||
|
} |
||||
|
} |
@ -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<T> extends DisposableObserver<T> { |
||||
|
|
||||
|
|
||||
|
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(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
@ -1,8 +1,32 @@ |
|||||
package com.gmeremit.online.gmeremittance_native.utils.https; |
package com.gmeremit.online.gmeremittance_native.utils.https; |
||||
|
|
||||
public class HTTPConstants { |
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; |
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue