From 05382461bd1a1be83c1a01a8f0b52d8d8e680944 Mon Sep 17 00:00:00 2001 From: harish Date: Sat, 30 Sep 2023 20:54:00 +0530 Subject: [PATCH] API Fixes : Care Context --- .../abha/ui/main/activity/AbdmActivity.kt | 9 +- .../abha/ui/main/activity/TestActivity.kt | 2 +- .../abha/ui/main/fragment/CCLinkFragment.kt | 58 ++++++++++--- .../ui/main/fragment/CCVerifyOtpFragment.kt | 17 ++++ .../res/layout/fragment_link_context_care.xml | 87 ++++++++++++++++++- .../main/res/navigation/link_care_context.xml | 4 +- app/src/main/res/values-hi-rIN/strings.xml | 3 +- app/src/main/res/values/strings.xml | 3 +- .../dalvik/data/network/NetworkUtil.kt | 51 +++++++---- .../domain/model/OtpRequestCallModel.kt | 8 +- .../dalvik/domain/model/ResponseModel.kt | 30 ++++--- 11 files changed, 213 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/org/commcare/dalvik/abha/ui/main/activity/AbdmActivity.kt b/app/src/main/java/org/commcare/dalvik/abha/ui/main/activity/AbdmActivity.kt index 820851b..dc8e3b4 100644 --- a/app/src/main/java/org/commcare/dalvik/abha/ui/main/activity/AbdmActivity.kt +++ b/app/src/main/java/org/commcare/dalvik/abha/ui/main/activity/AbdmActivity.kt @@ -218,7 +218,9 @@ class AbdmActivity : BaseActivity(AbdmActivityBinding::infl ) } } + } + lifecycleScope.launch(Dispatchers.Main) { careContextViewModel.otpRequestBlocked.asFlow().collect { otpBlockedRequest -> otpBlockedRequest?.let { DialogUtility.showDialog( @@ -229,9 +231,8 @@ class AbdmActivity : BaseActivity(AbdmActivityBinding::infl ) } } - - } + } private fun observerPatientViewModel(){ @@ -361,6 +362,10 @@ class AbdmActivity : BaseActivity(AbdmActivityBinding::infl dispatchResult(intent) } + fun onContextCareLinkFinished(intent: Intent) { + dispatchResult(intent) + } + override fun getNavHostId(): Int { return R.id.nav_host_fragment } diff --git a/app/src/main/java/org/commcare/dalvik/abha/ui/main/activity/TestActivity.kt b/app/src/main/java/org/commcare/dalvik/abha/ui/main/activity/TestActivity.kt index 431aa68..10d97db 100644 --- a/app/src/main/java/org/commcare/dalvik/abha/ui/main/activity/TestActivity.kt +++ b/app/src/main/java/org/commcare/dalvik/abha/ui/main/activity/TestActivity.kt @@ -131,7 +131,7 @@ class TestActivity : AppCompatActivity() { val careContext= JSONObject().apply { - put("referenceNumber","CC_505") + put("referenceNumber","CC_507") put("display","Visit for fever 505") val hiTypes= JSONArray().apply { put("Prescription") diff --git a/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/CCLinkFragment.kt b/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/CCLinkFragment.kt index 265ae6c..0da73b2 100644 --- a/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/CCLinkFragment.kt +++ b/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/CCLinkFragment.kt @@ -1,18 +1,24 @@ package org.commcare.dalvik.abha.ui.main.fragment +import android.content.Intent import android.os.Bundle import android.view.View +import androidx.core.content.ContextCompat import androidx.fragment.app.activityViewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle +import com.google.gson.Gson import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import org.commcare.dalvik.abha.R import org.commcare.dalvik.abha.databinding.LinkContextCareBinding import org.commcare.dalvik.abha.ui.main.activity.AbdmActivity +import org.commcare.dalvik.abha.ui.main.activity.AbdmResponseCode import org.commcare.dalvik.abha.viewmodel.CareContextViewModel import org.commcare.dalvik.abha.viewmodel.GenerateAbhaUiState +import org.commcare.dalvik.domain.model.CCLinkSuccessResponseModel +import org.commcare.dalvik.domain.model.CheckAbhaResponseModel class CCLinkFragment : BaseFragment(LinkContextCareBinding::inflate) { @@ -22,6 +28,9 @@ class CCLinkFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.linkInfoTxt.text = resources.getString(R.string.linking_cc) + binding.linkHipId.text = viewModel.linkCareContextModel.hipId + binding.clickHandler = this + observeUiState() linkCC() @@ -29,9 +38,7 @@ class CCLinkFragment : private fun linkCC(){ arguments?.getString("accessToken")?.let {accessToken -> - viewModel.linkCareContext(accessToken) - } } @@ -46,25 +53,38 @@ class CCLinkFragment : is GenerateAbhaUiState.Success -> { binding.linkInfoTxt.text = resources.getString(R.string.linking_cc_success) - viewModel.uiState.emit(GenerateAbhaUiState.Loading(false)) - binding.retryLink.visibility = View.GONE - binding.retryLink.isEnabled = false + val ccLinkSuccessResponseModel = + Gson().fromJson(it.data, CCLinkSuccessResponseModel::class.java) + binding.linkStatus.text = ccLinkSuccessResponseModel.status + binding.linkStatus.setTextColor( + ContextCompat.getColor( + requireContext(), + R.color.green + )) + viewModel.uiState.emit(GenerateAbhaUiState.Loading(false)) } is GenerateAbhaUiState.AbdmError -> { + binding.linkStatus.text = resources.getString(R.string.cc_not_linked) binding.linkInfoTxt.text = resources.getString(R.string.linking_cc_error) - binding.retryLink.visibility = View.VISIBLE - binding.retryLink.isEnabled = true + binding.linkStatus.setTextColor( + ContextCompat.getColor( + requireContext(), + R.color.red + )) viewModel.uiState.emit(GenerateAbhaUiState.Loading(false)) (activity as AbdmActivity).showBlockerDialog(it.data.getErrorMsg()) - } is GenerateAbhaUiState.Error -> { + binding.linkStatus.setTextColor( + ContextCompat.getColor( + requireContext(), + R.color.red + )) + binding.linkStatus.text = resources.getString(R.string.cc_not_linked) binding.linkInfoTxt.text = resources.getString(R.string.linking_cc_error) - binding.retryLink.visibility = View.VISIBLE - binding.retryLink.isEnabled = true (activity as AbdmActivity).showBlockerDialog(it.data.get("message").asString) viewModel.uiState.emit(GenerateAbhaUiState.Loading(false)) } @@ -79,4 +99,22 @@ class CCLinkFragment : } } } + + override fun onClick(view: View?) { + super.onClick(view) + when(view?.id){ + R.id.returnFromCCLink ->{ + dispatchResult() + } + } + } + + private fun dispatchResult() { + val intent = Intent().apply { + putExtra("hip_id", viewModel.linkCareContextModel.hipId) + putExtra("ccLinked", binding.linkStatus.text) + } + + (activity as AbdmActivity).onContextCareLinkFinished(intent) + } } \ No newline at end of file diff --git a/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/CCVerifyOtpFragment.kt b/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/CCVerifyOtpFragment.kt index 826ee53..bf328a0 100644 --- a/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/CCVerifyOtpFragment.kt +++ b/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/CCVerifyOtpFragment.kt @@ -142,12 +142,29 @@ class CCVerifyOtpFragment : BaseFragment(GenerateCCOtpBind } is GenerateAbhaUiState.AbdmError -> { + + when (it.requestType) { + RequestType.CC_AUTH_CONFIRM -> { + binding.verifyCCOtp.isEnabled = true + } + else ->{ + + } + } viewModel.uiState.emit(GenerateAbhaUiState.Loading(false)) (activity as AbdmActivity).showBlockerDialog(it.data.getErrorMsg()) } is GenerateAbhaUiState.Error -> { + when (it.requestType) { + RequestType.CC_AUTH_CONFIRM -> { + binding.verifyCCOtp.isEnabled = true + } + else ->{ + + } + } (activity as AbdmActivity).showBlockerDialog(it.data.get("message").asString) viewModel.uiState.emit(GenerateAbhaUiState.Loading(false)) } diff --git a/app/src/main/res/layout/fragment_link_context_care.xml b/app/src/main/res/layout/fragment_link_context_care.xml index 0997b5a..3f1c5d6 100644 --- a/app/src/main/res/layout/fragment_link_context_care.xml +++ b/app/src/main/res/layout/fragment_link_context_care.xml @@ -11,6 +11,10 @@ name="model" type="org.commcare.dalvik.abha.viewmodel.CareContextViewModel" /> + + + + + app:layout_constraintVertical_bias="0.5"> + + + + + + + + + + + + + + + + + + +