|
|
@ -3,6 +3,7 @@ package com.swifttech.remit.android.features.kyc.newCustomer.presenter; |
|
|
|
import android.annotation.SuppressLint; |
|
|
|
import android.util.Log; |
|
|
|
|
|
|
|
import com.google.gson.reflect.TypeToken; |
|
|
|
import com.swifttech.remit.android.R; |
|
|
|
import com.swifttech.remit.android.base.BaseViewModel; |
|
|
|
import com.swifttech.remit.android.common.customwidgets.CustomAlertDialog; |
|
|
@ -13,10 +14,9 @@ import com.swifttech.remit.android.features.kyc.newCustomer.model.KYCRelatedData |
|
|
|
import com.swifttech.remit.android.features.kyc.newCustomer.model.KYCRequestDataDTO; |
|
|
|
import com.swifttech.remit.android.features.kyc.newCustomer.model.PersonalInfoDTO; |
|
|
|
import com.swifttech.remit.android.features.kyc.newCustomer.model.PicturesDTO; |
|
|
|
import com.swifttech.remit.android.features.kyc.newCustomer.view.documents.KYCIDTypeViewLiveData; |
|
|
|
import com.swifttech.remit.android.features.kyc.newCustomer.view.documents.KYCIDTypeFragment; |
|
|
|
import com.swifttech.remit.android.features.kyc.newCustomer.view.documents.KYCIDTypeViewLiveData; |
|
|
|
import com.swifttech.remit.android.features.kyc.newCustomer.view.personal.CustomerDetailViewLiveData; |
|
|
|
|
|
|
|
import com.swifttech.remit.android.features.login.model.LoginV2DataApiResponse; |
|
|
|
import com.swifttech.remit.android.features.login.presenter.LoginV2InteractorInterface; |
|
|
|
import com.swifttech.remit.android.utils.Constants; |
|
|
@ -25,10 +25,10 @@ import com.swifttech.remit.android.utils.https.GenericApiObserverResponse; |
|
|
|
import com.swifttech.remit.android.utils.https.GenericApiObserverResponseV2; |
|
|
|
import com.swifttech.remit.android.utils.https.GenericResponseDataModel; |
|
|
|
import com.swifttech.remit.android.utils.https.MessageResponseDataModel; |
|
|
|
import com.google.gson.reflect.TypeToken; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.lang.reflect.Type; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
@ -44,34 +44,22 @@ import static android.app.Activity.RESULT_OK; |
|
|
|
public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInterface { |
|
|
|
|
|
|
|
|
|
|
|
public static final String TAG = "KYCV3Process"; |
|
|
|
private static final int THUMBNAIL_HEIGHT = 150; |
|
|
|
private static final int THUMBNAIL_WIDTH = 150; |
|
|
|
private final KYCV3PresenterInterface.KYCV3ViewContractInterface view; |
|
|
|
private final KYCV3GatewayInterface gateway; |
|
|
|
private final FileDownloadGateway fileDownloadGateway; |
|
|
|
private final LoginV2InteractorInterface.Login2GatewayInterface loginGateway; |
|
|
|
private CustomerDetailViewValidator validator; |
|
|
|
|
|
|
|
|
|
|
|
private PublishSubject<Boolean> form1ValidationSubject; |
|
|
|
private PublishSubject<Boolean> form2ValidationSubject; |
|
|
|
|
|
|
|
private final CompositeDisposable viewSubscriptions; |
|
|
|
|
|
|
|
private final CustomerDetailViewLiveData customerDetailLiveData; |
|
|
|
private final KYCIDTypeViewLiveData idTypeLiveData; |
|
|
|
|
|
|
|
|
|
|
|
private final CompositeDisposable compositeDisposable; |
|
|
|
|
|
|
|
public static final String TAG = "KYCV3Process"; |
|
|
|
private final String userId; |
|
|
|
private final String userPwd; |
|
|
|
|
|
|
|
public static void log(String message) { |
|
|
|
Log.d(TAG, message); |
|
|
|
} |
|
|
|
|
|
|
|
private CustomerDetailViewValidator validator; |
|
|
|
private PublishSubject<Boolean> form1ValidationSubject; |
|
|
|
private PublishSubject<Boolean> form2ValidationSubject; |
|
|
|
|
|
|
|
public KYCV3ViewModel(KYCV3ViewContractInterface view, KYCV3GatewayInterface gatewayInterface, FileDownloadGateway fileDownloadGateway, LoginV2InteractorInterface.Login2GatewayInterface loginGateway, String userId, String userPwd) { |
|
|
|
this.compositeDisposable = new CompositeDisposable(); |
|
|
@ -95,6 +83,10 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public static void log(String message) { |
|
|
|
Log.d(TAG, message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onViewReady() { |
|
|
|
|
|
|
@ -121,9 +113,9 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter |
|
|
|
} |
|
|
|
|
|
|
|
private void bindCustomerDetailView(CustomerDetailViewLiveData.CustomerDetailViewBinding viewBindings) { |
|
|
|
viewSubscriptions.add( |
|
|
|
Observable.combineLatest( |
|
|
|
List<Observable<Boolean>> list = Arrays.asList( |
|
|
|
viewBindings.getAdditionalIdTypeObservable().map(validator::validateAdditionalIdType), |
|
|
|
viewBindings.getOccupationObservable().map(validator::validateOccupation), |
|
|
|
viewBindings.getSourceOfFundObservable().map(validator::validateSourceOfFund), |
|
|
|
viewBindings.getAddressObservable().map(validator::validateAddress), |
|
|
|
viewBindings.getBusinessTypeObservable().map(validator::validateBusineesType), |
|
|
@ -131,11 +123,16 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter |
|
|
|
viewBindings.getIdTypeObservable().map(validator::validateSelectedIDType), |
|
|
|
viewBindings.getMobileNumberObservable().map(validator::validateMobileNumber), |
|
|
|
viewBindings.getMonthlyIncomeObservable().map(validator::validateMonthlyIncome), |
|
|
|
viewBindings.getEmployerNameObservable().map(validator::validateEmployerName), |
|
|
|
(isAdditionalTypeValid, isSourceOfFundValid, isAddressValid, isBusinessTypeValid, isEmailValid, isIdTypeValid, isMobileNumberValid, isMonthlyIncomeValid, isEmployerNameValid) -> |
|
|
|
isAdditionalTypeValid && isSourceOfFundValid && isAddressValid && isBusinessTypeValid && isEmailValid && isIdTypeValid && isMobileNumberValid && isMonthlyIncomeValid && isEmployerNameValid |
|
|
|
|
|
|
|
).subscribeWith(new DisposableObserver<Boolean>() { |
|
|
|
viewBindings.getEmployerNameObservable().map(validator::validateEmployerName) |
|
|
|
); |
|
|
|
viewSubscriptions.add( |
|
|
|
Observable.combineLatest(list, objects -> { |
|
|
|
for (Object value : objects) { |
|
|
|
if (!(value instanceof Boolean)) return false; |
|
|
|
if (!((Boolean) value)) return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
}).subscribeWith(new DisposableObserver<Boolean>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onNext(Boolean form1ValidationResult) { |
|
|
@ -216,6 +213,7 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter |
|
|
|
mobileNumber = mobileNumber.substring(3); |
|
|
|
} |
|
|
|
customerDetailLiveData.getEmployerNameLiveData().postValue(new FormInputStateDTO<>(true, null, personalInfoDTO.getEmployeerName())); |
|
|
|
customerDetailLiveData.getOccupationsLiveData().postValue(new FormInputStateDTO<>(true, null, data.getOccupationFromId(personalInfoDTO.getOccupation()))); |
|
|
|
customerDetailLiveData.getSourceOfFundLiveData().postValue(new FormInputStateDTO<>(true, null, data.getSourceOfFundFromId(personalInfoDTO.getSourceOfFund()))); |
|
|
|
customerDetailLiveData.getMonthlyIncomeLiveData().postValue(new FormInputStateDTO<>(true, null, data.getMonthlyIncomeFromId(personalInfoDTO.getMonthlyIncome()))); |
|
|
|
customerDetailLiveData.getBusinessTypeLiveData().postValue(new FormInputStateDTO<>(true, null, data.getBusinessTypeFromId(personalInfoDTO.getBusinessType()))); |
|
|
@ -453,6 +451,7 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void checkImageStatus(int requestCode, int resultCode, File data) { |
|
|
|
if (data == null) { |
|
|
@ -564,6 +563,10 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<IDTextDTO> getOccupationList() { |
|
|
|
return validator.getKycRelatedDataDTO().getOccupationList(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@ -618,8 +621,18 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter |
|
|
|
postKYCFormToServer(validator.getKycRelatedDataDTO().getForm1PostData(gateway.getUserID()), view::showDocumentDetailForm); |
|
|
|
} |
|
|
|
|
|
|
|
private void getNewAccessToken(Runnable task) { |
|
|
|
compositeDisposable.add( |
|
|
|
loginGateway.loginUser(loginGateway.getBasicAuth(view.getContext()), this.userId, this.userPwd) |
|
|
|
.doOnSubscribe(sub -> view.showProgressBar(true, "")) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
.observeOn(AndroidSchedulers.mainThread()) |
|
|
|
.doFinally(() -> view.showProgressBar(false, "")) |
|
|
|
.subscribeWith(new AccessTokenGenerationObserver(task))); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public class KycRelatedDataObserver extends GenericApiObserverResponseV2<KYCRelatedDataDTO> { |
|
|
|
|
|
|
|
@Override |
|
|
@ -630,9 +643,14 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter |
|
|
|
@Override |
|
|
|
protected void onSuccess(GenericResponseDataModel<KYCRelatedDataDTO> t) { |
|
|
|
if (t.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) { |
|
|
|
onReceivingKycRelatedData(t.getData()); |
|
|
|
/* onReceivingKycRelatedData(t.getData()); |
|
|
|
view.lazyLoadForms(); |
|
|
|
if (t.getData().areAnyPicturesAvailableFromServer()) |
|
|
|
view.showDocumentDetailForm();*/ |
|
|
|
|
|
|
|
onReceivingKycRelatedData(gateway.getMockedData()); |
|
|
|
view.lazyLoadForms(); |
|
|
|
if (true) |
|
|
|
view.showDocumentDetailForm(); |
|
|
|
|
|
|
|
} else |
|
|
@ -657,7 +675,6 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class CustomerDetailViewValidator { |
|
|
|
|
|
|
|
/** |
|
|
@ -693,6 +710,19 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
boolean validateOccupation(IDTextDTO data) { |
|
|
|
if (kycRelatedDataDTO.getPersonalInformation() == null) |
|
|
|
kycRelatedDataDTO.setPersonalInformation(new PersonalInfoDTO()); |
|
|
|
|
|
|
|
kycRelatedDataDTO.getPersonalInformation().setOccupation(data.getId()); |
|
|
|
if (kycRelatedDataDTO.getPersonalInformation().isOccupationValid()) { |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
customerDetailLiveData.getOccupationsLiveData().setValue(new FormInputStateDTO<>(false, view.getContext().getString(R.string.invalidOccupation), null)); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
boolean validateSourceOfFund(IDTextDTO data) { |
|
|
|
if (kycRelatedDataDTO.getPersonalInformation() == null) |
|
|
|
kycRelatedDataDTO.setPersonalInformation(new PersonalInfoDTO()); |
|
|
@ -884,20 +914,6 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void getNewAccessToken(Runnable task) { |
|
|
|
compositeDisposable.add( |
|
|
|
loginGateway.loginUser(loginGateway.getBasicAuth(view.getContext()), this.userId, this.userPwd) |
|
|
|
.doOnSubscribe(sub -> view.showProgressBar(true, "")) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
.observeOn(AndroidSchedulers.mainThread()) |
|
|
|
.doFinally(() -> view.showProgressBar(false, "")) |
|
|
|
.subscribeWith(new AccessTokenGenerationObserver(task))); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class KYCFormUploadObserver extends GenericApiObserverResponseV2<MessageResponseDataModel> { |
|
|
|
|
|
|
|
Runnable task; |
|
|
|