From 4d8a40828f2397e1479f46ce78374c8932a4daae Mon Sep 17 00:00:00 2001 From: adarshs Date: Tue, 1 Feb 2022 19:08:56 +0530 Subject: [PATCH] Implemented PAN error handling in PL basic details screen --- .../profile/fragments/ProfileFragment.kt | 14 +++++++++- .../profile/repositories/ProfileRepository.kt | 3 ++ .../profile/viewmodels/ProfileVM.kt | 28 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/naviapp/personalloan/useridentification/profile/fragments/ProfileFragment.kt b/app/src/main/java/com/naviapp/personalloan/useridentification/profile/fragments/ProfileFragment.kt index 06d8d2af24..85e152a2ab 100644 --- a/app/src/main/java/com/naviapp/personalloan/useridentification/profile/fragments/ProfileFragment.kt +++ b/app/src/main/java/com/naviapp/personalloan/useridentification/profile/fragments/ProfileFragment.kt @@ -38,6 +38,7 @@ import com.naviapp.homeloan.common.listener.HeaderInteractionListener import com.naviapp.models.UserDetail import com.naviapp.network.ApiErrorTagType.PROFILE_DETAILS_UPLOAD import com.naviapp.personalloan.getloan.kyc.fragments.KycFragment +import com.naviapp.personalloan.useridentification.pan.fragments.PanErrorFragment import com.naviapp.personalloan.useridentification.profile.viewmodels.ProfileVM import com.naviapp.personalloan.useridentification.viewmodels.EligibilityShareVM import com.naviapp.utils.* @@ -170,6 +171,15 @@ class ProfileFragment : BaseFragment(), viewModel.postFinoramicData.observeNullable(this) { viewModel.fetchProfileData() } + + viewModel.panError.observeNonNull(this) { + if (!isAdded || activity?.isFinishing.orTrue()) { + return@observeNonNull + } + hideLoader() + PanErrorFragment.getInstance(it, listener) + .show(childFragmentManager, PanErrorFragment.TAG) + } } @ExperimentalStdlibApi @@ -212,7 +222,9 @@ class ProfileFragment : BaseFragment(), apiPollScheduler?.invoke() return } else { - viewModel.checkUiStatus(null, null) + viewModel.profileAsyncResponse.value?.requestId?.let { requestId -> + viewModel.fetchAsyncRequestDataWithError(requestId) + } ?: viewModel.checkUiStatus(null, null) } } } diff --git a/app/src/main/java/com/naviapp/personalloan/useridentification/profile/repositories/ProfileRepository.kt b/app/src/main/java/com/naviapp/personalloan/useridentification/profile/repositories/ProfileRepository.kt index 4261982974..01057208ff 100644 --- a/app/src/main/java/com/naviapp/personalloan/useridentification/profile/repositories/ProfileRepository.kt +++ b/app/src/main/java/com/naviapp/personalloan/useridentification/profile/repositories/ProfileRepository.kt @@ -27,4 +27,7 @@ class ProfileRepository : ResponseCallback() { suspend fun fetchNextCta(requestId: String) = apiResponseCallback(retrofitService().fetchNextCta(requestId = requestId)) + suspend fun fetchAsyncRequestDataWithError(requestId: String) = + apiResponseCallback(retrofitService().fetchAsyncRequestWithError(requestId)) + } \ No newline at end of file diff --git a/app/src/main/java/com/naviapp/personalloan/useridentification/profile/viewmodels/ProfileVM.kt b/app/src/main/java/com/naviapp/personalloan/useridentification/profile/viewmodels/ProfileVM.kt index 3770ac168a..5160060cff 100644 --- a/app/src/main/java/com/naviapp/personalloan/useridentification/profile/viewmodels/ProfileVM.kt +++ b/app/src/main/java/com/naviapp/personalloan/useridentification/profile/viewmodels/ProfileVM.kt @@ -11,6 +11,7 @@ import com.naviapp.models.request.ProfileRequest import com.naviapp.models.response.ProfileDetailsResponse import com.naviapp.models.response.SuccessResponse import com.naviapp.models.response.UploadDataAsyncResponse +import com.naviapp.network.ApiConstants.E_PAN_NAME_MISMATCH import com.naviapp.network.ApiErrorTagType.PROFILE_DETAILS_UPLOAD import com.naviapp.network.models.GenericErrorResponse import com.naviapp.network.models.GenericWarningResponse @@ -43,6 +44,10 @@ class ProfileVM(private val repository: ProfileRepository = ProfileRepository()) val nextCtaData: LiveData get() = _nextCtaData + private val _panError = MutableLiveData() + val panError: LiveData + get() = _panError + fun fetchProfileData() { coroutineScope.launch { val response = repository.fetchProfileData() @@ -135,4 +140,27 @@ class ProfileVM(private val repository: ProfileRepository = ProfileRepository()) } } } + + fun fetchAsyncRequestDataWithError(requestId: String) { + coroutineScope.launch { + val response = repository.fetchAsyncRequestDataWithError(requestId) + if (response.error == null && response.errors.isNullOrEmpty()) { + if (TextUtils.equals(response.data?.status, FirebaseStatusType.FAILURE)) { + checkUiStatus(response.errors, response.warning) + return@launch + } + _dataAsyncResponse.value = response.data + } else { + val error = response.errors?.firstOrNull() + when (error?.code) { + E_PAN_NAME_MISMATCH -> { + _panError.value = error + } + else -> { + checkUiStatus(response.errors, response.warning) + } + } + } + } + } } \ No newline at end of file