Skip to content

Commit

Permalink
API Fixes : Care Context
Browse files Browse the repository at this point in the history
  • Loading branch information
RawatH committed Sep 30, 2023
1 parent db70b44 commit 0538246
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ class AbdmActivity : BaseActivity<AbdmActivityBinding>(AbdmActivityBinding::infl
)
}
}
}

lifecycleScope.launch(Dispatchers.Main) {
careContextViewModel.otpRequestBlocked.asFlow().collect { otpBlockedRequest ->
otpBlockedRequest?.let {
DialogUtility.showDialog(
Expand All @@ -229,9 +231,8 @@ class AbdmActivity : BaseActivity<AbdmActivityBinding>(AbdmActivityBinding::infl
)
}
}


}

}

private fun observerPatientViewModel(){
Expand Down Expand Up @@ -361,6 +362,10 @@ class AbdmActivity : BaseActivity<AbdmActivityBinding>(AbdmActivityBinding::infl
dispatchResult(intent)
}

fun onContextCareLinkFinished(intent: Intent) {
dispatchResult(intent)
}

override fun getNavHostId(): Int {
return R.id.nav_host_fragment
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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>(LinkContextCareBinding::inflate) {
Expand All @@ -22,16 +28,17 @@ 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()

}

private fun linkCC(){
arguments?.getString("accessToken")?.let {accessToken ->

viewModel.linkCareContext(accessToken)

}
}

Expand All @@ -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))
}
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,29 @@ class CCVerifyOtpFragment : BaseFragment<GenerateCCOtpBinding>(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))
}
Expand Down
87 changes: 83 additions & 4 deletions app/src/main/res/layout/fragment_link_context_care.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
name="model"
type="org.commcare.dalvik.abha.viewmodel.CareContextViewModel" />

<variable
name="clickHandler"
type="org.commcare.dalvik.abha.ui.main.fragment.CCLinkFragment" />

</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand All @@ -22,25 +26,100 @@
android:id="@+id/linkInfoTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/aadhaarDataTableLayout"
app:layout_constraintEnd_toEndOf="@+id/aadhaarDataTableLayout"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/aadhaarDataTableLayout"
app:layout_constraintTop_toTopOf="parent" />

<TableLayout
android:id="@+id/aadhaarDataTableLayout"
android:layout_width="347dp"
android:layout_height="wrap_content"
android:background="@color/bright_blue_grad_start"
android:orientation="vertical"
android:padding="1dp"
android:stretchColumns="*"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5" />
app:layout_constraintVertical_bias="0.5">

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:minHeight="32dp">

<TextView
style="@style/Headline1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:paddingStart="2dp"
android:paddingLeft="2dp"
android:text="@string/hipId" />

<TextView
android:id="@+id/linkHipId"
style="@style/Headline2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:paddingEnd="2dp"
android:paddingRight="2dp" />

</TableRow>

<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@color/bgColor"
android:minHeight="32dp">

<TextView
style="@style/Headline1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:paddingStart="2dp"
android:paddingLeft="2dp"
android:text="@string/STATUS" />

<TextView
android:id="@+id/linkStatus"
style="@style/Headline1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:paddingEnd="2dp"
android:paddingRight="2dp"

android:textStyle="bold"
tools:text="SUCCESS" />

</TableRow>


</TableLayout>

<Button
android:id="@+id/retryLink"
android:id="@+id/returnFromCCLink"
style="@style/RoundStyleButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="32dp"
android:text="@string/retryLink"
android:visibility="gone"
android:onClickListener="@{clickHandler}"
android:text="@string/RETURN"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
4 changes: 2 additions & 2 deletions app/src/main/res/navigation/link_care_context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<fragment
android:id="@+id/verifyCCLinkOtpFragment"
android:name="org.commcare.dalvik.abha.ui.main.fragment.CCVerifyOtpFragment"
android:label="verifyCCLinkOtpFragment" >
android:label="@string/VERIFY_OTP" >
<action
android:id="@+id/action_verifyCCLinkOtpFragment_to_linkContextCareFragment"
app:destination="@id/linkContextCareFragment" />
</fragment>
<fragment
android:id="@+id/linkContextCareFragment"
android:name="org.commcare.dalvik.abha.ui.main.fragment.CCLinkFragment"
android:label="LinkContextCareFragment" />
android:label="@string/linkCareContext" />
</navigation>
3 changes: 2 additions & 1 deletion app/src/main/res/values-hi-rIN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@
<string name="linking_cc">Linking context care...</string>
<string name="retryLink">Link Context Care</string>
<string name="linking_cc_success">Context care linked successfully.</string>
<string name="linking_cc_error">Context care not linked. Please retry.</string>
<string name="linking_cc_error">Context care not linked.</string>
<string name="cc_not_linked">NOT LINKED</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,6 @@ Please fill this field if the beneficiary is interested in a custom ABHA address
<string name="linking_cc">Linking context care...</string>
<string name="retryLink">Link Context Care</string>
<string name="linking_cc_success">Context care linked successfully.</string>
<string name="linking_cc_error">Context care not linked. Please retry.</string>
<string name="linking_cc_error">Context care not linked.</string>
<string name="cc_not_linked">NOT LINKED</string>
</resources>
Loading

0 comments on commit 0538246

Please sign in to comment.