Skip to content

Commit

Permalink
Fix Statin nudge alert stroke and animation (#5080)
Browse files Browse the repository at this point in the history
Co-authored-by: Siddharth Agarwal <[email protected]>
  • Loading branch information
siddh1004 and Siddharth Agarwal authored Sep 16, 2024
1 parent 801fd5b commit 70b5432
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 54 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Check statin nudge status in patient summary screen
- Add feature flag for statin nudge
- Fix statin nudge not getting dismissed when a statin is added
- Animate statin nudge visibility in `PatientSummaryScreen`

### Features

Expand Down Expand Up @@ -60,7 +61,7 @@

### Fixes

- Fix app crashing when viewing BP history
- Fix app crashing when viewing BP history

## 2024-06-27-9140

Expand Down
110 changes: 59 additions & 51 deletions app/src/main/java/org/simple/clinic/summary/PatientSummaryScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,59 @@ class PatientSummaryScreen :
}

override fun showClinicalDecisionSupportAlert() {
clinicalDecisionSupportAlertView.translationY = clinicalDecisionSupportAlertView.height.unaryMinus().toFloat()
showWithAnimation(clinicalDecisionSupportAlertView)
}

override fun hideClinicalDecisionSupportAlert() {
hideWithAnimation(clinicalDecisionSupportAlertView, R.id.tag_clinical_decision_pending_end_listener)
}

override fun hideClinicalDecisionSupportAlertWithoutAnimation() {
clinicalDecisionSupportAlertView.visibility = GONE
}

override fun showStatinAlert(statin: StatinModel) {
statinAlertDescription.text = buildString {
append("${getString(R.string.statin_alert_patient)} ")

if (statin.hasDiabetes) {
append(String.format(getString(R.string.statin_alert_has_diabetes), statin.age.toString()))

if (statin.hasHadHeartAttack.xor(statin.hasHadStroke)) {
append(" ${getString(R.string.statin_alert_and_seperator)} ")
}
}

when {
statin.hasHadHeartAttack && statin.hasHadStroke -> append(getCVDString(statin.hasDiabetes))
statin.hasHadHeartAttack -> append(getString(R.string.statin_alert_heart_attack))
statin.hasHadStroke -> append(getString(R.string.statin_alert_stroke))
}

append(".")
}
showWithAnimation(statinAlertView)
}

override fun hideStatinAlert() {
hideWithAnimation(statinAlertView, R.id.tag_statin_alert_end_listener)
}

private fun getCVDString(hasDiabetes: Boolean): String {
return if (hasDiabetes) {
getString(R.string.statin_alert_cvd_with_diabetes)
} else {
getString(R.string.statin_alert_cvd)
}
}

private fun showWithAnimation(view: View) {
view.translationY = view.height.unaryMinus().toFloat()

val spring = clinicalDecisionSupportAlertView.spring(DynamicAnimation.TRANSLATION_Y)
val spring = view.spring(DynamicAnimation.TRANSLATION_Y)

val transition = AutoTransition().apply {
excludeChildren(clinicalDecisionSupportAlertView, true)
excludeChildren(view, true)
excludeTarget(R.id.newBPItemContainer, true)
excludeTarget(R.id.bloodSugarItemContainer, true)
excludeTarget(R.id.drugsSummaryContainer, true)
Expand Down Expand Up @@ -763,77 +810,38 @@ class PatientSummaryScreen :
transition.addListener(transitionListener)
TransitionManager.beginDelayedTransition(summaryViewsContainer, transition)

clinicalDecisionSupportAlertView.visibility = VISIBLE
view.visibility = VISIBLE
}

override fun hideClinicalDecisionSupportAlert() {
if (clinicalDecisionSupportAlertView.visibility != VISIBLE) return
private fun hideWithAnimation(view: View, tag: Int) {
if (view.visibility != VISIBLE) return

val spring = clinicalDecisionSupportAlertView.spring(DynamicAnimation.TRANSLATION_Y)
(clinicalDecisionSupportAlertView.getTag(R.id.tag_clinical_decision_pending_end_listener) as?
val spring = view.spring(DynamicAnimation.TRANSLATION_Y)
(view.getTag(tag) as?
DynamicAnimation.OnAnimationEndListener)?.let {
spring.removeEndListener(it)
}

val listener = object : DynamicAnimation.OnAnimationEndListener {
override fun onAnimationEnd(animation: DynamicAnimation<*>?, canceled: Boolean, value: Float, velocity: Float) {
spring.removeEndListener(this)
clinicalDecisionSupportAlertView.visibility = GONE
view.visibility = GONE
}
}
spring.addEndListener(listener)
clinicalDecisionSupportAlertView.setTag(R.id.tag_clinical_decision_pending_end_listener, listener)
view.setTag(tag, listener)

val transition = AutoTransition().apply {
excludeChildren(clinicalDecisionSupportAlertView, true)
excludeChildren(view, true)
excludeTarget(R.id.newBPItemContainer, true)
excludeTarget(R.id.bloodSugarItemContainer, true)
excludeTarget(R.id.drugsSummaryContainer, true)
}
TransitionManager.beginDelayedTransition(summaryViewsContainer, transition)

spring.animateToFinalPosition(clinicalDecisionSupportAlertView.height.unaryMinus().toFloat())
}

override fun hideClinicalDecisionSupportAlertWithoutAnimation() {
clinicalDecisionSupportAlertView.visibility = GONE
}

override fun showStatinAlert(statin: StatinModel) {
statinAlertDescription.text = buildString {
append("${getString(R.string.statin_alert_patient)} ")

if (statin.hasDiabetes) {
append(String.format(getString(R.string.statin_alert_has_diabetes), statin.age.toString()))

if (statin.hasHadHeartAttack.xor(statin.hasHadStroke)) {
append(" ${getString(R.string.statin_alert_and_seperator)} ")
}
}

when {
statin.hasHadHeartAttack && statin.hasHadStroke -> append(getCVDString(statin.hasDiabetes))
statin.hasHadHeartAttack -> append(getString(R.string.statin_alert_heart_attack))
statin.hasHadStroke -> append(getString(R.string.statin_alert_stroke))
}

append(".")
}

statinAlertView.visibility = VISIBLE
spring.animateToFinalPosition(view.height.unaryMinus().toFloat())
}

private fun getCVDString(hasDiabetes: Boolean): String {
return if (hasDiabetes) {
getString(R.string.statin_alert_cvd_with_diabetes)
} else {
getString(R.string.statin_alert_cvd)
}
}

override fun hideStatinAlert() {
statinAlertView.visibility = GONE
}

override fun showReassignPatientWarningSheet(
patientUuid: UUID,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/background_statin_alert.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<stroke
android:width="@dimen/spacing_1"
android:color="@color/simple_yellow_550_alpha_40" />
android:color="@color/simple_yellow_550" />

<corners android:radius="@dimen/spacing_4" />
</shape>
1 change: 1 addition & 0 deletions app/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
<item name="spring_animation_scrollx" type="id" />
<item name="spring_animation_scrollY" type="id" />
<item name="tag_clinical_decision_pending_end_listener" type="id" />
<item name="tag_statin_alert_end_listener" type="id" />
</resources>
2 changes: 1 addition & 1 deletion common-ui/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<color name="simple_red_100_alpha_50">#80FFD6DD</color>

<color name="simple_yellow_600">#B48E00</color>
<color name="simple_yellow_550_alpha_40">#66E0B000</color>
<color name="simple_yellow_550">#E0B000</color>
<color name="simple_yellow_500">#FFC800</color>
<color name="simple_yellow_100">#FFF8E0</color>

Expand Down

0 comments on commit 70b5432

Please sign in to comment.