From 65c7b69a1eda768b295f69942518625de4778603 Mon Sep 17 00:00:00 2001 From: harish Date: Sat, 30 Sep 2023 23:57:09 +0530 Subject: [PATCH] Heal consent fix --- .../fragment/PatientHealthDataFragment.kt | 29 +++++++++++-------- .../dalvik/abha/viewmodel/PatientViewModel.kt | 26 ++++++++--------- .../res/layout/patient_health_data_layout.xml | 2 +- .../main/res/navigation/link_care_context.xml | 2 +- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/PatientHealthDataFragment.kt b/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/PatientHealthDataFragment.kt index e744a5e..050b920 100644 --- a/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/PatientHealthDataFragment.kt +++ b/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/PatientHealthDataFragment.kt @@ -10,6 +10,7 @@ import androidx.lifecycle.repeatOnLifecycle import com.google.gson.Gson import kotlinx.coroutines.launch import org.commcare.dalvik.abha.databinding.PatientHealthDataBinding +import org.commcare.dalvik.abha.ui.main.activity.AbdmActivity import org.commcare.dalvik.abha.ui.main.adapters.FileData import org.commcare.dalvik.abha.ui.main.adapters.FileType import org.commcare.dalvik.abha.ui.main.adapters.HealthDataAdapter @@ -19,18 +20,19 @@ import org.commcare.dalvik.domain.model.HealthContentModel import org.commcare.dalvik.domain.model.PatientHealthDataModel import timber.log.Timber -class PatientHealthDataFragment : BaseFragment(PatientHealthDataBinding::inflate) { +class PatientHealthDataFragment : + BaseFragment(PatientHealthDataBinding::inflate) { val viewModel: PatientViewModel by activityViewModels() - lateinit var healthDataAdapter:HealthDataAdapter + lateinit var healthDataAdapter: HealthDataAdapter val healthDataList = mutableListOf() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - arguments?.getString("artefactId")?.let {artefactId -> + arguments?.getString("artefactId")?.let { artefactId -> - healthDataAdapter = HealthDataAdapter(healthDataList,this::launchImgAndPdfFragment) + healthDataAdapter = HealthDataAdapter(healthDataList, this::launchImgAndPdfFragment) binding.patientHealthDataList.adapter = healthDataAdapter observeUiState() @@ -39,13 +41,14 @@ class PatientHealthDataFragment : BaseFragment(Patient } - private fun launchImgAndPdfFragment(fileData: FileData){ - if(fileData.fileType == FileType.INVALID){ - Toast.makeText(context, "Invalid file type.",Toast.LENGTH_LONG).show() + private fun launchImgAndPdfFragment(fileData: FileData) { + if (fileData.fileType == FileType.INVALID) { + Toast.makeText(context, "Invalid file type.", Toast.LENGTH_LONG).show() } val dialogFragment = AbdmImgAndPdfViewer(fileData) dialogFragment.show(parentFragmentManager, "healthData") } + private fun observeUiState() { viewLifecycleOwner.lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { @@ -53,7 +56,7 @@ class PatientHealthDataFragment : BaseFragment(Patient when (it) { is GenerateAbhaUiState.PatientHealthDataRequested -> { - Timber.d("Patient health data requested") + viewModel.uiState.emit(GenerateAbhaUiState.InvalidState) viewModel.uiState.emit(GenerateAbhaUiState.Loading(true)) } @@ -73,17 +76,19 @@ class PatientHealthDataFragment : BaseFragment(Patient healthDataModel.page + 1 ) } ?: run { - Timber.d("ALL ARTEFACTS FETCHED") - viewModel.uiState.emit(GenerateAbhaUiState.InvalidState) viewModel.uiState.emit(GenerateAbhaUiState.Loading(false)) } } is GenerateAbhaUiState.Error -> { - Timber.d("ERROR ARTEFACTS FETCHED") - viewModel.uiState.emit(GenerateAbhaUiState.InvalidState) viewModel.uiState.emit(GenerateAbhaUiState.Loading(false)) + (activity as AbdmActivity).showBlockerDialog(it.data.get("message").asString) + } + + is GenerateAbhaUiState.AbdmError -> { + viewModel.uiState.emit(GenerateAbhaUiState.Loading(false)) + (activity as AbdmActivity).showBlockerDialog(it.data.message) } else -> { diff --git a/app/src/main/java/org/commcare/dalvik/abha/viewmodel/PatientViewModel.kt b/app/src/main/java/org/commcare/dalvik/abha/viewmodel/PatientViewModel.kt index 6913c51..0d40b10 100644 --- a/app/src/main/java/org/commcare/dalvik/abha/viewmodel/PatientViewModel.kt +++ b/app/src/main/java/org/commcare/dalvik/abha/viewmodel/PatientViewModel.kt @@ -125,22 +125,20 @@ class PatientViewModel @Inject constructor( ) } is HqResponseModel.Error -> { - Timber.d("EMIT Sending -> GenerateAbhaUiState.Error") -// uiState.emit( -// GenerateAbhaUiState.Error( -// it.value, -// RequestType.AADHAAR_OTP -// ) -// ) + uiState.emit( + GenerateAbhaUiState.Error( + it.value, + RequestType.FETCH_CONSENT_ARTEFACTS + ) + ) } is HqResponseModel.AbdmError -> { - Timber.d("EMIT Sending -> GenerateAbhaUiState.AbdmError") -// uiState.emit( -// GenerateAbhaUiState.AbdmError( -// it.value, -// RequestType.AADHAAR_OTP -// ) -// ) + uiState.emit( + GenerateAbhaUiState.AbdmError( + it.value, + RequestType.FETCH_CONSENT_ARTEFACTS + ) + ) } } } diff --git a/app/src/main/res/layout/patient_health_data_layout.xml b/app/src/main/res/layout/patient_health_data_layout.xml index 50e4d37..68a3f2a 100644 --- a/app/src/main/res/layout/patient_health_data_layout.xml +++ b/app/src/main/res/layout/patient_health_data_layout.xml @@ -25,7 +25,7 @@ android:id="@+id/healthDataErLayout" android:layout_width="0dp" android:layout_height="wrap_content" - android:visibility="visible" + android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" diff --git a/app/src/main/res/navigation/link_care_context.xml b/app/src/main/res/navigation/link_care_context.xml index 3e736b4..1c74488 100644 --- a/app/src/main/res/navigation/link_care_context.xml +++ b/app/src/main/res/navigation/link_care_context.xml @@ -7,7 +7,7 @@ + android:label="@string/linkCareContext" >