gary
4 years ago
11 changed files with 365 additions and 63 deletions
-
1app/src/main/java/com/swifttech/remit/android/base/PrivilegedGateway.java
-
266app/src/main/java/com/swifttech/remit/android/features/home/HomeViewModel.java
-
30app/src/main/java/com/swifttech/remit/android/features/home/HomeViewModelFactory.java
-
5app/src/main/java/com/swifttech/remit/android/features/home/presenter/HomeV2Presenter.java
-
10app/src/main/java/com/swifttech/remit/android/features/home/presenter/HomeV2PresenterInterface.java
-
44app/src/main/java/com/swifttech/remit/android/features/home/view/HomeActivityV2.java
-
12app/src/main/java/com/swifttech/remit/android/features/home/view/HomeFragmentV2.java
-
5app/src/main/java/com/swifttech/remit/android/features/kyc/newCustomer/KYCV3ViewModelFactory.java
-
1app/src/main/res/layout/activity_splash_screen_key_0.xml
-
1app/src/main/res/layout/activity_splash_screen_key_1.xml
-
53app/src/main/res/values/styles.xml
@ -0,0 +1,266 @@ |
|||||
|
package com.swifttech.remit.android.features.home; |
||||
|
|
||||
|
import android.util.Log; |
||||
|
|
||||
|
import androidx.lifecycle.LiveData; |
||||
|
import androidx.lifecycle.MutableLiveData; |
||||
|
|
||||
|
import com.google.firebase.iid.FirebaseInstanceId; |
||||
|
import com.swifttech.remit.android.BuildConfig; |
||||
|
import com.swifttech.remit.android.R; |
||||
|
import com.swifttech.remit.android.RemitApplication; |
||||
|
import com.swifttech.remit.android.base.BaseViewModel; |
||||
|
import com.swifttech.remit.android.common.customwidgets.CustomAlertDialog; |
||||
|
import com.swifttech.remit.android.features.home.model.AppUpdateModel; |
||||
|
import com.swifttech.remit.android.features.home.model.HomeNotificationViewDTO; |
||||
|
import com.swifttech.remit.android.features.home.model.HomeViewRelatedDTOV2; |
||||
|
import com.swifttech.remit.android.features.home.model.UserInfoModelV2; |
||||
|
import com.swifttech.remit.android.features.home.presenter.HomeNotificationHandler; |
||||
|
import com.swifttech.remit.android.features.home.presenter.HomeV2InteractorInterface; |
||||
|
import com.swifttech.remit.android.features.home.presenter.HomeV2PresenterInterface; |
||||
|
import com.swifttech.remit.android.utils.Constants; |
||||
|
import com.swifttech.remit.android.utils.https.HTTPConstants; |
||||
|
import com.swifttech.remit.android.utils.https.SessionExpiredException; |
||||
|
import com.swifttech.remit.android.utils.https.UserSessionObserverResponse; |
||||
|
|
||||
|
import java.util.concurrent.TimeUnit; |
||||
|
|
||||
|
import io.reactivex.Observable; |
||||
|
import io.reactivex.ObservableSource; |
||||
|
import io.reactivex.android.schedulers.AndroidSchedulers; |
||||
|
import io.reactivex.disposables.CompositeDisposable; |
||||
|
import io.reactivex.functions.Function; |
||||
|
import io.reactivex.schedulers.Schedulers; |
||||
|
import retrofit2.HttpException; |
||||
|
|
||||
|
public class HomeViewModel extends BaseViewModel implements HomeV2PresenterInterface { |
||||
|
private final HomeV2ContractInterface view; |
||||
|
private final HomeV2InteractorInterface.HomeV2GatewayInterface gateway; |
||||
|
private final boolean shouldCheckFingerprintPrompt; |
||||
|
private final CompositeDisposable compositeDisposable; |
||||
|
private boolean shouldNotPromptAppUpdate; |
||||
|
|
||||
|
public HomeViewModel(HomeV2ContractInterface view, |
||||
|
HomeV2InteractorInterface.HomeV2GatewayInterface gateway, |
||||
|
boolean shouldCheckFingerprintPrompt) { |
||||
|
this.view = view; |
||||
|
this.gateway = gateway; |
||||
|
this.compositeDisposable = new CompositeDisposable(); |
||||
|
this.shouldNotPromptAppUpdate = false; |
||||
|
this.shouldCheckFingerprintPrompt = shouldCheckFingerprintPrompt; |
||||
|
homeRelatedMutableLiveData = new MutableLiveData<>(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
private MutableLiveData<HomeViewRelatedDTOV2> homeRelatedMutableLiveData; |
||||
|
@Override |
||||
|
public void getRequiredData() { |
||||
|
compositeDisposable.add( |
||||
|
Observable.concat(getDataFromServerAndSaveIt().timeout(25, TimeUnit.SECONDS).onErrorResumeNext(new Function<Throwable, ObservableSource<? extends UserInfoModelV2>>() { |
||||
|
@Override |
||||
|
public ObservableSource<? extends UserInfoModelV2> apply(Throwable throwable) throws Exception { |
||||
|
if (throwable instanceof SessionExpiredException) |
||||
|
return Observable.error(throwable); |
||||
|
else if (throwable instanceof HttpException && ((HttpException) throwable).code() == 401) |
||||
|
return Observable.error(new SessionExpiredException(HTTPConstants.getErrorMessageFromCode(((HttpException) throwable).code()))); |
||||
|
else |
||||
|
return Observable.empty(); |
||||
|
} |
||||
|
}), |
||||
|
this.gateway.getCachedUserInfoFromDB()) |
||||
|
.subscribeOn(Schedulers.io()) |
||||
|
.observeOn(AndroidSchedulers.mainThread()) |
||||
|
.take(1) |
||||
|
.subscribeWith(new UserInfoObserver())); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void getRequiredCachedData() { |
||||
|
compositeDisposable.add( |
||||
|
this.gateway.getCachedUserInfoFromDB() |
||||
|
.subscribeOn(Schedulers.io()) |
||||
|
.observeOn(AndroidSchedulers.mainThread()) |
||||
|
.subscribeWith(new UserInfoObserver()) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void clearAllData() { |
||||
|
this.gateway.clearAllUserData(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String checkIfUserVerified() { |
||||
|
String resultMessage = null; |
||||
|
String pennyTestStatus = gateway.getPennyTestStatus(); |
||||
|
if (!gateway.hasUserSubmittedKYC()) |
||||
|
resultMessage = getStringfromStringId(R.string.complete_your_registration_text); |
||||
|
else if (pennyTestStatus != null && pennyTestStatus.length() > 0 && !pennyTestStatus.equalsIgnoreCase("2")) |
||||
|
resultMessage = getStringfromStringId(R.string.complete_penny_test); |
||||
|
else if (!gateway.isUserKYCVerified()) |
||||
|
resultMessage = getStringfromStringId(R.string.verification_in_aproval_process_text); |
||||
|
|
||||
|
return resultMessage; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void storeAppUpdateDecision(boolean booleanExtra) { |
||||
|
this.shouldNotPromptAppUpdate = booleanExtra; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean shouldNotPromptAppUpdate() { |
||||
|
return this.shouldNotPromptAppUpdate; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void checkIfFingerprintPromptShouldBeShown() { |
||||
|
//TODO disable fingerprint |
||||
|
// if (shouldCheckFingerprintPrompt) { |
||||
|
// if (!gateway.hasPromptedUserForFingerprintFirstTime() && SecurityUtils.checkFingerPrintUsablity(view.getContext()) && !gateway.isFingerPrintAuthEnabled() && gateway.getPersistedUserId() != null && gateway.getPersistedUserPwd() != null) |
||||
|
// view.showFingerprintAvailablityToUser(); |
||||
|
// |
||||
|
// } |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public LiveData<HomeViewRelatedDTOV2> subscribeToHomeRelatedDataEvent() { |
||||
|
return homeRelatedMutableLiveData; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public HomeNotificationViewDTO constructKYCVerificationRequiredViewNotification() { |
||||
|
return HomeNotificationHandler.generateNotificationFromType(RemitApplication.getStringExtractor(), HomeNotificationHandler.HomeNoticeViewTypeEnum.KYC_NOT_VERIFIED); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onViewReady() { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onViewNotReady() { |
||||
|
|
||||
|
} |
||||
|
@Override |
||||
|
public void onViewDestroyed() { |
||||
|
super.onViewDestroyed(); |
||||
|
if (compositeDisposable != null && !compositeDisposable.isDisposed()) |
||||
|
compositeDisposable.dispose(); |
||||
|
} |
||||
|
|
||||
|
private Observable<UserInfoModelV2> getDataFromServerAndSaveIt() { |
||||
|
String fcmID; |
||||
|
try { |
||||
|
fcmID = FirebaseInstanceId.getInstance().getToken(); |
||||
|
} catch (Exception e) { |
||||
|
fcmID = null; |
||||
|
} |
||||
|
|
||||
|
if (fcmID == null || fcmID.length() < 1) |
||||
|
fcmID = this.gateway.getLastKnownFcmId(); |
||||
|
RemitApplication.AppRelatedMetaData appRelatedMetaData = RemitApplication.getAppRelatedMetaData(view.getContext()); |
||||
|
return this.gateway.getUserRelatedData(this.gateway.getAuth(), |
||||
|
this.gateway.getUserID(), |
||||
|
fcmID, |
||||
|
appRelatedMetaData.getAppVersion(), |
||||
|
appRelatedMetaData.getPhoneBrand(), |
||||
|
appRelatedMetaData.getOsName(), |
||||
|
appRelatedMetaData.getDeviceId(), |
||||
|
appRelatedMetaData.getOsVersion() |
||||
|
).flatMap(userInfoV2DataApiResponse -> { |
||||
|
if (userInfoV2DataApiResponse.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) { |
||||
|
|
||||
|
return this.gateway.saveUserInfo(userInfoV2DataApiResponse.getData()); |
||||
|
} else |
||||
|
return Observable.error(new SessionExpiredException(userInfoV2DataApiResponse.getMsg())); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public class UserInfoObserver extends UserSessionObserverResponse<UserInfoModelV2> { |
||||
|
|
||||
|
@Override |
||||
|
protected void onSuccess(UserInfoModelV2 userInfoModelV2) { |
||||
|
|
||||
|
|
||||
|
String fullName = userInfoModelV2.getFirstName(); |
||||
|
|
||||
|
|
||||
|
view.showInfoInDrawer(fullName, userInfoModelV2.getCustomerEmail(), userInfoModelV2.getYearlyLimit(), userInfoModelV2.getWalletNumber(), userInfoModelV2.getPrimaryBankName(), userInfoModelV2.getMobileNumber()); |
||||
|
|
||||
|
|
||||
|
boolean shouldShowTermsAndCondition = "0".equalsIgnoreCase(userInfoModelV2.getAgreeYn()); |
||||
|
|
||||
|
|
||||
|
HomeNotificationViewDTO notificationViewDTO = new HomeNotificationHandler( |
||||
|
RemitApplication.getStringExtractor(), |
||||
|
userInfoModelV2.getKyc(), |
||||
|
userInfoModelV2.isVerified(), |
||||
|
userInfoModelV2.getPennyTestStatus(), |
||||
|
userInfoModelV2.getRedirectTo(), |
||||
|
shouldShowTermsAndCondition) |
||||
|
.generateAppropriateHomeNotificationViewDTO(); |
||||
|
|
||||
|
|
||||
|
homeRelatedMutableLiveData.setValue( |
||||
|
new HomeViewRelatedDTOV2( |
||||
|
fullName, |
||||
|
userInfoModelV2.getAvailableBalance(), |
||||
|
userInfoModelV2.getYearlyLimit(), |
||||
|
userInfoModelV2.getRewardPoint(), |
||||
|
userInfoModelV2.getPrimaryBankName(), |
||||
|
userInfoModelV2.getWalletNumber(), |
||||
|
notificationViewDTO, |
||||
|
shouldShowTermsAndCondition |
||||
|
)); |
||||
|
|
||||
|
//If no notification is generated then we can show privileged Operation View |
||||
|
view.showPrivilegedOperationView(notificationViewDTO == null || notificationViewDTO.shouldShowPrivilegedView()); |
||||
|
|
||||
|
AppUpdateModel androidAppUpdateModel = null; |
||||
|
if (userInfoModelV2.getAppUpdate() != null) |
||||
|
for (AppUpdateModel model : userInfoModelV2.getAppUpdate()) { |
||||
|
if (model.getOS().equalsIgnoreCase("ANDROID")) |
||||
|
androidAppUpdateModel = model; |
||||
|
} |
||||
|
// checkIfUpdateIsRequired(androidAppUpdateModel); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onFailed(String message) { |
||||
|
Log.d("DashBoardError", "Recieved Error : " + message); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void onConnectionNotEstablished(String message) { |
||||
|
Log.d("DashBoardError", "Recieved Error : " + message); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void onSessionExpired(String message) { |
||||
|
view.showPopUpMessage(message, CustomAlertDialog.AlertType.ALERT, alertType -> { |
||||
|
view.performLogout(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void checkIfUpdateIsRequired(AppUpdateModel androidAppUpdateModel) { |
||||
|
if (androidAppUpdateModel == null) |
||||
|
return; |
||||
|
try { |
||||
|
int playStoreBuildNumber = Integer.parseInt(androidAppUpdateModel.getBuild()); |
||||
|
if (playStoreBuildNumber > BuildConfig.VERSION_CODE) { |
||||
|
if (androidAppUpdateModel.getInfo() != null && androidAppUpdateModel.getInfo().length() < 1) |
||||
|
androidAppUpdateModel.setInfo(null); |
||||
|
boolean isForceUpdate = androidAppUpdateModel.getCritical().equalsIgnoreCase("Y"); |
||||
|
if (isForceUpdate) |
||||
|
view.showUpdateScreen(androidAppUpdateModel.getBuild(), androidAppUpdateModel.getInfo(), true); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
package com.swifttech.remit.android.features.home; |
||||
|
|
||||
|
import androidx.annotation.NonNull; |
||||
|
import androidx.lifecycle.ViewModel; |
||||
|
import androidx.lifecycle.ViewModelProvider; |
||||
|
|
||||
|
import com.swifttech.remit.android.features.home.presenter.HomeV2InteractorInterface; |
||||
|
import com.swifttech.remit.android.features.home.presenter.HomeV2PresenterInterface; |
||||
|
|
||||
|
public class HomeViewModelFactory implements ViewModelProvider.Factory { |
||||
|
private final HomeV2PresenterInterface.HomeV2ContractInterface view; |
||||
|
private final HomeV2InteractorInterface.HomeV2GatewayInterface gateway; |
||||
|
private final boolean shouldCheckFingerprintPrompt; |
||||
|
|
||||
|
public HomeViewModelFactory( |
||||
|
HomeV2PresenterInterface.HomeV2ContractInterface view, |
||||
|
HomeV2InteractorInterface.HomeV2GatewayInterface gateway, |
||||
|
boolean shouldCheckFingerprintPrompt) { |
||||
|
this.view = view; |
||||
|
this.gateway=gateway; |
||||
|
this.shouldCheckFingerprintPrompt=shouldCheckFingerprintPrompt; |
||||
|
} |
||||
|
|
||||
|
@SuppressWarnings("unchecked") |
||||
|
@NonNull |
||||
|
@Override |
||||
|
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { |
||||
|
return (T) new HomeViewModel(view,gateway,shouldCheckFingerprintPrompt); |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue