Skip to content

Commit

Permalink
Heal consent fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RawatH committed Sep 30, 2023
1 parent b099a83 commit 65c7b69
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>(PatientHealthDataBinding::inflate) {
class PatientHealthDataFragment :
BaseFragment<PatientHealthDataBinding>(PatientHealthDataBinding::inflate) {

val viewModel: PatientViewModel by activityViewModels()
lateinit var healthDataAdapter:HealthDataAdapter
lateinit var healthDataAdapter: HealthDataAdapter
val healthDataList = mutableListOf<HealthContentModel>()

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()
Expand All @@ -39,21 +41,22 @@ class PatientHealthDataFragment : BaseFragment<PatientHealthDataBinding>(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) {
viewModel.uiState.collect {
when (it) {

is GenerateAbhaUiState.PatientHealthDataRequested -> {
Timber.d("Patient health data requested")
viewModel.uiState.emit(GenerateAbhaUiState.InvalidState)
viewModel.uiState.emit(GenerateAbhaUiState.Loading(true))
}

Expand All @@ -73,17 +76,19 @@ class PatientHealthDataFragment : BaseFragment<PatientHealthDataBinding>(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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/patient_health_data_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/navigation/link_care_context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<fragment
android:id="@+id/CCFetchAuthModeFragment"
android:name="org.commcare.dalvik.abha.ui.main.fragment.CCFetchAuthModeFragment"
android:label="CCFetchAuthModeFragment" >
android:label="@string/linkCareContext" >
<action
android:id="@+id/action_CCFetchAuthModeFragment_to_verifyCCLinkOtpFragment"
app:destination="@id/verifyCCLinkOtpFragment" />
Expand Down

0 comments on commit 65c7b69

Please sign in to comment.