diff --git a/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/ConsentArtefactFragment.kt b/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/ConsentArtefactFragment.kt index 640edfc..e9d1769 100644 --- a/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/ConsentArtefactFragment.kt +++ b/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/ConsentArtefactFragment.kt @@ -28,7 +28,7 @@ class ConsentArtefactFragment : BaseFragment(ConsentArtefactBinding::inflate) { val viewModel: PatientViewModel by activityViewModels() - lateinit var arefactAdapter: ConsentArtefactAdapter + lateinit var artefactAdapter: ConsentArtefactAdapter override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -46,7 +46,7 @@ class ConsentArtefactFragment : return when (menuItem.itemId) { R.id.refresh -> { - arefactAdapter.refresh() + artefactAdapter.refresh() true } @@ -56,13 +56,13 @@ class ConsentArtefactFragment : }, viewLifecycleOwner, Lifecycle.State.RESUMED) - arefactAdapter = ConsentArtefactAdapter(this::fetchHealthData) + artefactAdapter = ConsentArtefactAdapter(this::fetchHealthData) binding.artefactList.apply { setHasFixedSize(true) - adapter = arefactAdapter.withLoadStateHeaderAndFooter( - footer = ConsentPageLoaderAdapter(arefactAdapter::retry), - header = ConsentPageLoaderAdapter(arefactAdapter::retry) + adapter = artefactAdapter.withLoadStateHeaderAndFooter( + footer = ConsentPageLoaderAdapter(artefactAdapter::retry), + header = ConsentPageLoaderAdapter(artefactAdapter::retry) ) } @@ -71,11 +71,11 @@ class ConsentArtefactFragment : } viewModel.fetchConsentArtefacts().observe(viewLifecycleOwner) { - arefactAdapter.submitData(lifecycle, it) + artefactAdapter.submitData(lifecycle, it) } //LOAD STATE - arefactAdapter.addLoadStateListener { loadState -> + artefactAdapter.addLoadStateListener { loadState -> val isLoading = loadState.refresh is LoadState.Loading binding.statusLoading.isVisible = isLoading @@ -88,7 +88,7 @@ class ConsentArtefactFragment : binding.statusView.text = resources.getText(R.string.loadErrorMsg) } if (loadState.append.endOfPaginationReached) { - if (arefactAdapter.itemCount < 1) { + if (artefactAdapter.itemCount < 1) { binding.statusView.isVisible = true binding.statusView.text = resources.getText(R.string.noData) } else { @@ -114,6 +114,12 @@ class ConsentArtefactFragment : viewModel.uiState.collect { when (it) { + is GenerateAbhaUiState.PatientHealthDataRequested -> { + Timber.d("Patient health data requested") + viewModel.uiState.emit(GenerateAbhaUiState.Loading(true)) + } + + is GenerateAbhaUiState.Success -> { val healthDataModel = Gson().fromJson(it.data, PatientHealthDataModel::class.java) @@ -121,10 +127,12 @@ class ConsentArtefactFragment : viewModel.patientHealthData.second.addAll(healthDataModel.results) - healthDataModel.next.let { + healthDataModel.next?.let { fetchHealthData(viewModel.patientHealthData.first,healthDataModel.transactionId,healthDataModel.page+1) } ?: run { Timber.d("ALL ARTEFACTS FETCHED") + viewModel.uiState.emit(GenerateAbhaUiState.InvalidState) + viewModel.uiState.emit(GenerateAbhaUiState.Loading(false)) } @@ -133,7 +141,7 @@ class ConsentArtefactFragment : } is GenerateAbhaUiState.Error -> { - + Timber.d("ERROR ARTEFACTS FETCHED") } else -> { 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 new file mode 100644 index 0000000..f99fd3a --- /dev/null +++ b/app/src/main/java/org/commcare/dalvik/abha/ui/main/fragment/PatientHealthDataFragment.kt @@ -0,0 +1,4 @@ +package org.commcare.dalvik.abha.ui.main.fragment + +class PatientHealthDataFragment { +} \ No newline at end of file diff --git a/app/src/main/java/org/commcare/dalvik/abha/viewmodel/BaseViewModel.kt b/app/src/main/java/org/commcare/dalvik/abha/viewmodel/BaseViewModel.kt index ea66282..b7fa3db 100644 --- a/app/src/main/java/org/commcare/dalvik/abha/viewmodel/BaseViewModel.kt +++ b/app/src/main/java/org/commcare/dalvik/abha/viewmodel/BaseViewModel.kt @@ -21,6 +21,8 @@ sealed class GenerateAbhaUiState { object VerifyMobileOtpRequested : GenerateAbhaUiState() object VerifyAadhaarOtpRequested : GenerateAbhaUiState() object AbhaAvailabilityRequested : GenerateAbhaUiState() + + object PatientHealthDataRequested : GenerateAbhaUiState() object Blocked : GenerateAbhaUiState() data class Success(val data: JsonObject, val requestType: RequestType) : 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 1272b1b..6913c51 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 @@ -114,7 +114,7 @@ class PatientViewModel @Inject constructor( fetchPatientHealthDataUseCase.execute(artefactsId,transactionId,page).collect{ when(it){ is HqResponseModel.Loading -> { - uiState.emit(GenerateAbhaUiState.AadhaarOtpRequested) + uiState.emit(GenerateAbhaUiState.PatientHealthDataRequested) } is HqResponseModel.Success -> { uiState.emit( diff --git a/app/src/main/res/layout/health_record_cell.xml b/app/src/main/res/layout/health_record_cell.xml new file mode 100644 index 0000000..ac6bea2 --- /dev/null +++ b/app/src/main/res/layout/health_record_cell.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/patient_health_data_layout.xml b/app/src/main/res/layout/patient_health_data_layout.xml new file mode 100644 index 0000000..cb9a727 --- /dev/null +++ b/app/src/main/res/layout/patient_health_data_layout.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + +