Skip to content

Commit

Permalink
Health Data UI
Browse files Browse the repository at this point in the history
  • Loading branch information
RawatH committed Sep 21, 2023
1 parent 0ed51ab commit ecc63e8
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ConsentArtefactFragment :
BaseFragment<ConsentArtefactBinding>(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)
Expand All @@ -46,7 +46,7 @@ class ConsentArtefactFragment :
return when (menuItem.itemId) {

R.id.refresh -> {
arefactAdapter.refresh()
artefactAdapter.refresh()
true
}

Expand All @@ -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)
)
}

Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -114,17 +114,25 @@ 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)


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))
}


Expand All @@ -133,7 +141,7 @@ class ConsentArtefactFragment :
}

is GenerateAbhaUiState.Error -> {

Timber.d("ERROR ARTEFACTS FETCHED")
}

else -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.commcare.dalvik.abha.ui.main.fragment

class PatientHealthDataFragment {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
95 changes: 95 additions & 0 deletions app/src/main/res/layout/health_record_cell.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<data class="PatientHealthDataBinding">
<variable
name="model"
type="org.commcare.dalvik.domain.model.HealthContentModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{model.title}"
style="@style/Headline1"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintBottom_toTopOf="@+id/textView15"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="TITLE" />

<TextView
android:id="@+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:text='@{"Care Context Reference : " + model.careContextRef}'
app:layout_constraintBottom_toTopOf="@+id/careContextsContainer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title"
tools:text="Care Context Reference" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/careContextsContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/button_disabled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView15">

<ImageView
android:id="@+id/expanderView"
android:layout_width="@dimen/_32dp"
android:layout_height="@dimen/_32dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="@+id/textView12"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/textView12"
app:srcCompat="@drawable/baseline_expand_more_24" />

<TextView
android:id="@+id/textView12"
style="@style/Headline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:gravity="center_vertical"
android:paddingStart="@dimen/_5dp"
android:text="@string/content"
app:layout_constraintBottom_toTopOf="@+id/careContextChipGroup"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
android:id="@+id/careContextChipGroup"
android:layout_width="match_parent"
android:layout_height="@dimen/_100dp"
android:padding="@dimen/_5dp"
android:visibility="gone"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/textView12"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView12"
app:layout_constraintVertical_bias="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
64 changes: 64 additions & 0 deletions app/src/main/res/layout/patient_health_data_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<data class="PatientHealthDataBinding">


</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/artefactRetryLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/artefactRetryLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recyclerView">

<TextView
android:id="@+id/textView11"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/retryArtefact"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5" />

<Button
android:id="@+id/retryArtefact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="@string/retry"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/textView11"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
1 change: 1 addition & 0 deletions app/src/main/res/values-hi-rIN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@
<string name="notGrantedMsg">Status is not \"GRANTED\"</string>
<string name="artefats">Artefacts</string>
<string name="get_health_data">HEALTH DATA</string>
<string name="content">Content</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@ Please fill this field if the beneficiary is interested in a custom ABHA address
<string name="notGrantedMsg">Status is not \"GRANTED\"</string>
<string name="artefats">Artefacts</string>
<string name="get_health_data">HEALTH DATA</string>
<string name="content">Content</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ data class PatientHealthDataModel(
@SerializedName("transaction_id") var transactionId: String,
@SerializedName("page_count") var pageCount: Int,
var page: Int,
var next: String
var next: String?
) {
lateinit var results: MutableList<HealthContentModel>
}
Expand Down

0 comments on commit ecc63e8

Please sign in to comment.